This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTC (Ds1302)...

I am currently using 89C52 to write a program...

if i want to display RTC on the LCD, should i use a loop? for example below:

while(1)
{
displayRTC(); //routine to display RTC on LCD
}

Or should i use an interrupt??? if i would to use an interrupt... can i use timer 2 of 89C52??? i haf written a routine as follow:

void setTimer2(void)
{
TR2=0;
hour=0;
minute=0;
second=0;
count20ms=0;
T2CON=0;
RCAP2H=(-40000) >> 8;
RCAP2L=(-40000) & 0x0ff;
TH2=RCAP2H;
TL2=RCAP2L;
TF2=0;
TR2 = 1;
ET2=1;
EA=1;
}

void timer2ISR( void ) interrupt 5 using 1
{
TF2 = 0;
// --- use count20ms to check if 1 second has passed ---

count20ms = count20ms + 1;
if (count20ms == 50)
{
count20ms = 0;
displayRTC();

}
}

is the above routine correct????

0