tumee
Member level 1
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;
}
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;
}