difference in timing

Status
Not open for further replies.
Pommie said:
Unbelievable.

Mike.
i m sending my code
Code:
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;
}

when i burn this programme to PIC16F72, first cycle it toggles at near 2mins,
for next cycles it exactly toggles at 1min...

is it tkes that extra time for boot up or what?
how can i overcome by this problem?
Plz help me .....
 
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.
 
The lack of initialisation was fairly obvious. The really confusing thing is the D0 (zero) instead of DO and the spurious closing braces. I assume this was introduced while copying.

Mike.
 
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 ..........
What do you mean by initialize the second?
PLZ send me some example code of initializing the second.
 
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 ..........
What do you mean by initialize the second?
PLZ send me some example code of initializing the second.
 
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.
 

Thanx it working fine....
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…