You are quite correct Tamas,=20 That will teach me to make a last minute "fix" to the email! =20 -Jim -----Original Message----- From: piclist-bounces@mit.edu [mailto:piclist-bounces@mit.edu] On Behalf Of Tamas Rudnai Sent: 21 June 2013 15:43 To: Microcontroller discussion list - Public. Subject: Re: [PIC] TIMER0 - delay Hi, Just a quick note to the quick fix: I believe clearing the counter should happen inside the conditional blocks otherwise it will be zeroed every time= : void interrupt() { if(intcon & 0x04) { clear_bit(intcon, 2); counter++; if(portb =3D=3D 1) { if(counter =3D=3D 3906) { portb =3D 0; counter =3D 0; } } else { if(counter =3D=3D 2929) { portb =3D 1; counter =3D 0; } } } } On 21 June 2013 04:56, Jim wrote: > Hi, > > without changing the way you have started to write your code, here is=20 > a quick fix for you. > > > > void interrupt() > > { > > if(intcon & 0x04) > > { > > clear_bit(intcon, 2); > > counter++; > > > > if(portb =3D=3D 1) > > { > > if(counter =3D=3D 3906) > > { > > portb =3D 0; > > } > > } > > else > > { > > if(counter =3D=3D 2929) > > { > > portb =3D 1; > > } > > } > > counter =3D 0; > > } > > } > > > > > > -Jim > > > > > > On Fri 21/06/13 10:22 AM , mircea2012 mircead.personal@yahoo.com sent: > > > Hy. > > > I want to generate two diferent delays, using timer0 pic16f88. > > > step 1 : led 1 stay ON 4 sec > > > step 2 : led 1 stay OFF 3 sec > > > > > > By the way I use a Matrix multimedia development board. > > > > > > Look at my cod : in this moment the led 1 stay ON - 4 sec and then=20 > > stay > > > OFF- 4 sec. > > > I know that my mistake is in interrupt function, but i am not able=20 > > to > > > correct this mistake. > > > > > > #include > > > #pragma DATA _CONFIG1, _EXTRC_CLKOUT & _WDT_OFF & _LVP_OFF > > > > > > unsigned int counter=3D0; > > > > > > void interrupt() > > > { > > > if(intcon & 0x04) > > > { > > > clear_bit(intcon, 2); > > > counter++; > > > if(counter =3D=3D 3906) > > > { > > > portb =3D ~portb; > > > counter=3D0; > > > } > > > } > > > } > > > > > > void main() > > > { > > > trisb =3D 0xf0; > > > portb =3D 0; > > > tmr0 =3D 0; > > > cmcon =3D 0x07; > > > option_reg =3D 0b00000001; // prescaler =3D 4 > > > intcon =3D 0b10100000; > > > while(1) > > > { > > > > > > } > > > } > > > > > > > > > > > > -- > > > View this message in context: > http://microcontrollers.2385.n7.nabble.com/PIC-TIMER0-delay-tp1 > > > 83408.htmlSent from the MicroControllers - PIC mailing list archive=20 > > at > > > Nabble.com.-- > > > > > > http://www.piclist.com/techref/piclist PIC/SX > > > FAQ & list archiveView/change your membership options at > > > http://mailman.mit.edu/mailman/listinfo/piclist > > > > > > > > > > > -- > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive=20 > View/change your membership options at=20 > http://mailman.mit.edu/mailman/listinfo/piclist > -- int main() { char *a,*s,*q; printf(s=3D"int main() { char *a,*s,*q; printf(s=3D%s%s%s, q=3D%s%s%s%s,s,q,q,a=3D%s%s%s%s,q,q,q,a,a,q); }", q=3D"\"",s,q,q,a=3D"\\",q,q,q,a,a,q); } -- http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/chang= e your membership options at http://mailman.mit.edu/mailman/listinfo/piclist --=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 .