static void isr(void) __interrupt 0 {
if(TMR0IE==1 && TMR0IF==1)//timer 1 interrupt overflow detect
{
[B] TMR0 = 5[/B]; // reinit timer0 immediatly, because must continue to count elapsed time
done = 1; //latch enable as soon as interrupt detected
TMR0IF = 0;//clear overflow flag
}
}
void main(void) {
setup();
while(1) {
delay_ms(1000);
LATA |= (1<<2);
delay_ms(1000);
LATA &= ~(1<<2);
}
}
void setup(void) {
OSCCON = 0b01011000; // 1MHZ internal clock
LATA = 0;
TRISA = 0x00;
PORTA = 0x00;
// Clock source selection (Fosc/4)
TMR0CS = 0;
PSA = 1; // No prescaler
TMR0 = 5; /
// Enable Timer1 interrupt
TMR0IE = 1;
GIE = 1;
}
void delay_ms(int milis) {
while (milis--) {
done = 0; //disable delay latch
// TMR0 = 250; // allready done inside interrupt
while (!done); //latch till 1ms interrupt happens
}
}