// ******* interrupt routine ********
interrupt void intrtn() {
/*
* interrupts all come here.
* First decide what caused the interrupt,
* then respond to it
*/
if (INTCONbits.T0IF) { // timer0 rolled
static uint16_t icount=0; // counts the timer clicks
icount+=512;
if (icount>1000) { // past a millisecond
++millis;
icount-=1000; // this preserves any error, which eventually smoothes out
}
INTCONbits.T0IF=0; // turn off int flag
}
if (INTCONbits.INTF) { // RB0 input fired
LEDoff=millis+2000; // turn of secends from now
INTCONbits.INTF=0;
}
}
The great thing about now having a millisecond timer built-in is we can use it anywhere we want. Here I set a timer to the current millisecond+2000 and we can use that in the master loop to switch an LED on for two seconds.
if (millis>LEDoff) {
manual_LED=0;
} else {
manual_LED=1;
}
No comments:
Post a Comment