I'm stuck in Timer Interrupt Routine using a PIC16F1827;
Very simple LED ON, LED OFF, absolutely nothing else in the program
Code: Select all
#define LED LatB.F3
char LED_cnt = 0 ;
/* Timer0
Prescaler 1:256; TMR0 Preload = 61; Actual Interrupt Time : 49.92 ms */
OPTION_REG = 0x87;
TMR0 = 61;
INTCON.TMR0IE = 1;
INTCON.TMR0IF = 0;
INTCON.PEIE = 1 ;
INTCON.GIE = 1 ;
while(1) {
asm CLRWDT;
if(LED_cnt >= 20) { // about 1_sec_ON, then 1_sec_OFF
LED =~ LED ;
LED_cnt = 0 ;
}
}
Code: Select all
void Interrupt() iv 0x0004 ics ICS_AUTO {
if (TMR0IF_bit){
TMR0IF_bit = 0;
TMR0 = 61;
LED_cnt ++ ;
// LED = 1 ; // if I uncomment this line, I can see the LED comming ON
// so that means the program reaches this line, but then the
// PIC resets itself and starts all over again
}
}
No matter which timer I'm using is doing it the same.
Has anybody got any idea?
Thanks.