// Global Variables const unsigned char MSG0[21] = "Quad Copter "; const unsigned char MSG1[21] = "PW (ms): "; unsigned int N, T0, T1, M; // Subroutine Declarations #include // Subroutines #include "lcd_portd.c" // High-priority service void interrupt IntServe(void) { if (TMR0IF) { // PS = 4 TMR0 = -50000; TMR1 = -N; T0 += 1; RC0 = 1; TMR0IF = 0; } if (TMR1IF) { RC0 = 0; T1 += 1; TMR1IF = 0; } } // Main Routine void main(void) { unsigned int 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(1000); N = 9000; // set up Timer0 for PS = 4 T0CS = 0; T0CON = 0x81; TMR0ON = 1; TMR0IE = 1; TMR0IP = 1; PEIE = 1; // set up Timer1 for PS = 1 TMR1CS = 0; T1CON = 0x81; TMR1ON = 1; TMR1IE = 1; TMR1IP = 1; PEIE = 1; // turn on all interrupts GIE = 1; while(1) { if (RB0) N = 9000; if (RB1) N = 12000; if (RB2) N = 13000; if (RB3) N = 14000; if (RB4) N = 15000; if (RB5) N = 16000; if (RB6) N = 17000; if (RB7) N = 18000; LCD_Move(1,9); LCD_Out(N, 5, 4); } }