Last active
August 29, 2015 13:56
-
-
Save kingcoyote/8939749 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// include the XC and PIC18 libraries | |
#include <xc.h> | |
#include <pic18.h> | |
#pragma config FOSC=HS1 | |
// number of milliseconds that the device has been on | |
unsigned long int milliseconds; | |
// main loop of the program | |
void main() { | |
// enable Timer 0, part of the T0CON register (datasheet page 211) | |
TMR0ON = 1; | |
// enable Timer 0's interrupt | |
TMR0IE = 1; | |
// enable general interrupts | |
GIE = 1; | |
// main loop | |
while (1) { } | |
} | |
// interrupt service routine to handle all interrupts | |
void interrupt main_isr(void) { | |
// if Timer 0's interrupt flag has been raised | |
if (TMR0IF) { | |
// increment the millisecond counter | |
milliseconds++; | |
// lower the interrupt flag | |
TMR0IF = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment