// Timer2_PWM // // Output a PWM signal on pins RA2 / RA1 / RA0 // RA2 = 5/256 // RA1 = 20/256 // RA0 = 200/256 // Global Variables const unsigned char MSG0[21] = "Timer2 PWM "; unsigned char RED, GREEN, BLUE, TIME; // Subroutine Declarations #include // Subroutines #include "lcd_portd.c" // High-priority service void interrupt IntServe(void) { if (TMR2IF) { TIME = TIME + 1; if (TIME == 0) PORTA = 7; if (TIME == RED) RA2 = 0; if (TIME == GREEN) RA1 = 0; if (TIME == BLUE) RA0 = 0; TMR2IF = 0; } } // Main Routine void main(void) { unsigned char i; unsigned int j; TRISA = 0; TRISB = 0x0F; 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]); // Wait_ms(2000); // LCD_Inst(1); // clear LCD // set up Timer2 for 1000 clocks T2CON = 0x05; PR2 = 249; TMR2ON = 1; TMR2IE = 1; TMR2IP = 1; PEIE = 1; // turn on all interrupts GIE = 1; while(1) { RED = 5; GREEN = 20; BLUE = 200; LCD_Move(1,0); LCD_Out(RED, 3, 0); LCD_Move(1,5); LCD_Out(GREEN, 3, 0); LCD_Move(1,10); LCD_Out(BLUE, 3, 0); } }