added tag. -Bob On Sat, Jun 22, 2013, at 11:42 AM, mircea2012 wrote: > Hy.=20 > In this program i try to test compare mode using pic16f88. > I am not quite sure if it is OK but the code is working. > I set an output RB0 for 1 sec (led is ON), after that i reset that output > RB0 (led is OFF) for 1 sec. > >From my calculations : f =3D 4MHz / (4 * 8 * 65536) =3D 2Hz > T =3D 1 / 2Hz =3D 0,5 which means that the led is on twice per sec. > But in program i use variable counter to increase the delay, so led is on > for 1 sec and off - 1 sec. >=20 >=20 > #include >=20 > #pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF >=20 > unsigned int counter =3D 0; >=20 > void interrupt()=20 > { =20 > if((pir1 & 0x01) && (pir1 & 0x04)) > { =20 > clear_bit(pir1, 0); > clear_bit(pir1, 2); > counter++; > if(counter =3D=3D 2) > { > ccp1con =3D 0b00001001; > } > else if(counter =3D=3D 4) > { > ccp1con =3D 0b00001000; > counter =3D 0; > } > } =20 > } >=20 > void main() > { > trisb =3D 0xf0; > portb =3D 0x00; > tmr1h =3D 0; > tmr1l =3D 0; > ccpr1l =3D 0x60; > ccpr1h =3D 0xea; > cmcon =3D 0x07; > t1con =3D 0b00110001; // prescaler =3D 8 > intcon =3D 0b11000000; > pie1 =3D 0b00000101; > ccp1con =3D 0b00001000; > while(1) > { > =09 > }=20 > } >=20 --=20 http://www.fastmail.fm - Access your email from home and the web --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .