/* PWM01.C 2006-05-09 David Ellis http://home.comcast.net/~ellis76016/robots/ */ #include "int16CXX.H" #pragma chip PIC16F877 #pragma resetVector 0x0003 bit LED @ PORTD.0; //Pin40 = D0 bit pin2 @ PORTD.1; //Pin38 = D1 uns8 Ticks; interrupt int_server(void) { int_save_registers // W, STATUS, and PCLATH if (TMR2IF) { Ticks++; if (Ticks == 100) { Ticks = 0; LED = ! LED; // toggle pin d0 } TMR2IF = 0; /* reset flag */ } int_restore_registers // W, STATUS, and PCLATH } void main(void) { Ticks = 0; // set up PWM // bank 1 PR2 = 0xFF; // bank 0 CCPR1L = 0xA0; CCPR2L = 0xA0; T2CON = 0b.0011.1100; TMR2IF = 0; // bank 1 TMR2IE = 1; // bank 0 PEIE = 1; GIE = 1; CCP1CON = 0b.0000.1100; CCP2CON = 0b.0000.1100; PORTD = 0b.0000.0000; TRISD = 0b.1111.1100; while ( 1 ) { // loop forever nop(); // do nothing nop(); // do nothing pin2 = ! pin2; // toggle pin d1 } }