// Generate a frequency with Timer0 // Global Variables const unsigned char MSG0[21] = "T0_Freq.C "; const unsigned char MSG1[21] = "N = "; unsigned int N = 8513 - 50; // Subroutine Declarations #include // Subroutines #include "lcd_portd.c" void interrupt IntServe(void) { if (TMR0IF) { TMR0 = -N; RC0 = !RC0; TMR0IF = 0; } } // Main Routine void main(void) { unsigned char i; TRISA = 0; 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]); Wait_ms(100); // set up Timer0 for PS = 1 T0CS = 0; T0CON = 0x88; TMR0ON = 1; TMR0IE = 1; TMR0IP = 1; PEIE = 1; // turn on all interrupts GIE = 1; while(1) { LCD_Move(1,8); LCD_Out(N, 5, 0); } }