Hi all...
I'm trying to set up timer0 to time about 10ms and inc a global variable that gets displayed on an LCD. Everything is pretty much working except that I can't change the time out value for timer0. I init the timer before a while loop that display the variable "time". The isr inc the value on every time out of timer0. It also toggles RB4 so I can check the freq (for testing). The freq is always about 4 Hz. TIME_TIMEOUT is defined as 5000. I've tried to change this value but nothing happens. What am I missing ?
Thanks
BTW it runs at 2MHz. There is only one isr.
//------------- code begins -------------------------- OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_1); WriteTimer0(TIME_TIMEOUT);
// INTCON=0; //make sure interrupts are disable // INTCONbits.GIE=1; //enable global interrupts // INTCONbits.PEIE=1; //enable peripheral interrupts // INTCONbits.TMR0IE=1; //enable TMR0 overflow interrupt enable bit INTCON=0xe0; //all 4 lines above combined
while(1) { itoa(time,timeStr); SetDDRamAddr(LCD_LINE2); // Display value of time while(BusyXLCD()); // Wait if LCD busy putsXLCD(timeStr);
}; //--------------- code ends ----------------------
The isr is here:
//------------- code begins ---------------------- #pragma code #pragma interrupt InterruptHandlerLow void InterruptHandlerLow() { if (INTCONbits.TMR0IF==1) { time++; PORTBbits.RB4=~PORTBbits.RB4; WriteTimer0(TIME_TIMEOUT); INTCONbits.TMR0IF=0; //clear interrupt flag }
} //--------------- code ends ----------------------