// Timer0.C // // Use Timer0 interrupts with PS=1 to // display time to 100ns // #include // Global Variables unsigned long int TIME; const unsigned char MSG0[21] = "Timer0 "; // Interrupt Service Routine void interrupt IntServe(void) { if (TMR0IF) { TIME = TIME + 0x10000; RC0 = !RC0; TMR0IF = 0; } } // Subroutines #include "lcd_portd.c" // Main Routine void main(void) { unsigned int i; unsigned long int TIME0; TRISA = 0; TRISB = 0; TRISC = 0; TRISD = 0; ADCON1 = 0x0F; // set up Timer0 for PS = 1 T0CS = 0; T0CON = 0x88; TMR0ON = 1; TMR0IE = 1; TMR0IP = 1; PEIE = 1; LCD_Init(); Wait_ms(100); TIME = 0; LCD_Init(); LCD_Move(0,0); for (i=0; i<20; i++) LCD_Write(MSG0[i]); // turn on all interrupts GIE = 1; // Do nothing. Interrupts do all the work. while(1) { TIME0 = TIME + TMR0; LCD_Move(1,0); LCD_Out(TIME0, 10, 7); } }