sachin.kolkar
New Member
hi guys,
i m facing problem with timer
i m facing problem with timer
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
sachin.kolkar said:hi guys,
i m facing problem with timer
i m sending my codePommie said:Unbelievable.
Mike.
unsigned short counter,second,m;
void main()
{
TRISB=0x00;
PORTB=0x0F;
T1CON=0b00001001;
TMR1H=0x80;
TMR1L=0x0F;
T1CON.TMR1ON=1;
PIR1.TMR1IF=0;
PIE1.TMR1IE=1;
INTCON=0xC0;
d0
{
if(counter==30)
{
counter=0;
second++;
if(second==60)
{
m++;
second=0;
if(m==1)
{
m=0;
PORTB=~PORTB;
}
}
}
}while(1);
}
void interrupt()
{
counter++;
TMR1H=0x80;
TMR1L=0x04;
PIR1.TMR1IF=0;
}
do you mean that making TMR1L=0x00; TMR1H=0x00; is initializing the counter right ..........Pommie said:That is because you don't initialise counter or seconds in your code. Try setting them to zero at the start of your main routine.
Mike.
do you mean that making TMR1L=0x00; TMR1H=0x00; is initializing the counter right ..........Pommie said:That is because you don't initialise counter or seconds in your code. Try setting them to zero at the start of your main routine.
Mike.
Pommie said:Just set them to zero,
Code:unsigned short counter,second,m; void main() { [COLOR="Blue"] counter=0; second=0;[/COLOR] TRISB=0x00; PORTB=0x0F; T1CON=0b00001001; TMR1H=0x80;
You might also consider setting m=0 as well.
Mike.