// T0_Ext.c // Count every 7th rising edge on RA4 // Global Variables const unsigned char MSG0[21] = "TMR0 "; const unsigned char MSG1[21] = "N "; unsigned long int N; // Subroutine Declarations #include // Subroutines #include "lcd_portd.c" void interrupt IntServe(void) { if (TMR0IF) { TMR0 = -7; N += 1; TMR0IF = 0; } } // Main Routine void main(void) { unsigned char i; TRISA = 0xFF; TRISB = 0xFF; TRISC = 0; TRISD = 0; TRISE = 0; ADCON1 = 0x0F; LCD_Init(); // initialize the LCD LCD_Move(0,0); for (i=0; i<20; i++) LCD_Write(MSG0[i]); LCD_Move(1,0); for (i=0; i<20; i++) LCD_Write(MSG1[i]); // set up Timer0 for PS = 1 T0CON = 0x88; TMR0ON = 1; TMR0IE = 1; TMR0IP = 1; T0CS = 1; PEIE = 1; // turn on all interrupts GIE = 1; N = 0; TMR0 = -7; while(1) { LCD_Move(0,8); LCD_Out(-TMR0, 5, 0); LCD_Move(1,8); LCD_Out(N, 5, 0); } }