// Timer2 Binary Clock // Global Variables const unsigned char MSG0[20] = "T2 Clock "; const unsigned char MSG1[20] = " "; unsigned int DELAY; // Subroutine Declarations #include #include "lcd_portd.c" void interrupt IS(void) { if (TMR2IF) { RA1 = !RA1; if(DELAY) DELAY -= 1; TMR2IF = 0; } } // Main Routine void main(void) { unsigned char i, j; unsigned int TIME; TRISA = 0; TRISB = 0; TRISC = 0; TRISD = 0; TRISE = 0; ADCON1 = 15; // Timer2 Initialize TMR2ON = 1; TMR2IE = 1; PEIE = 1; T2CON = 0x4D; PR2 = 249; GIE = 1; LCD_Init(); 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]); DELAY = 0; while(1) { RA2 = !RA2; while(DELAY); DELAY = 1000; TIME += 1; LCD_Move(1,0); LCD_Out(TIME, 3, 0); } }