I did digital clock using 7 segment and 89c52. But delay is incremented when clock hardware working. Its fall to behind about 4 second after 1 hour. If known anyone please tell me.
the delay code is:
void delay_asec(void)
{
unsigned char d;
for (d = 0; d < 20; d++){
delay_50ms();
}
}
void delay_50ms(void)
{
// SCON = 0x80;
//configure Timer 0 as a 16-bit timer
TMOD &= 0xf0; //Clear all T0 bits (T1 left unchanged)
TMOD |= 0x01; //Set required T0 bits (T1 left unchanged)
ET0 = 0; //No interrupts
//Values for 50ms delay
TH0 = 0x3c; //0x3c
TL0 = 0xb0; //0xb0
TF0 = 0; //Clear overflow flag
TR0 = 1; //Start timer 0
while (TF0 == 0); //Loop until 0 overflows (TF0 == 1)
TR0 = 0;
}
Delays generated by MCUs are rarely used as time-bases for clocks, so all what you can do is to play with the reload values for TL0 ..
In this instance, as the counter counts up and your cumulative time is to long, try to increase the value from #0B0h to #0B1h and see how it goes ..
Dear friend
I’m using ATMEL 89c52 using 11.059MHz
how to calculate delay in this routine?
DELAY:
mov temp1,#19h
lp1:
mov temp2,#19h
lp2:
nop
djnz temp2, lp2
djnz temp1, lp1
ret