Help!!!

Status
Not open for further replies.

apricot_star

New Member
Hi all,

Does anyone know why the displaying of msg to LCD will affect the functioning of the real time clock( once displaying too many message to LCD the Real time clock will appear to be hang)? Is it because RTC being loaded?

Thanks.

Regards,
 
It is probably because you are calling a delay or your LCD code in your interrupt and missing a timer interrupt because of it. Only update your variables in the interrupt and display them in the main code.

Mike.
 
In your code (received by PM) you don't appear to initialise year_date.

It would be nice if you could post your code here so that others can look and maybe find the problem.

Mike.
 
i've tried to initialize the year_date as following but it seems that the prob is still exist:
year= ReadEeprom(YEAR_ADDR);
Out_Hex_LCD(year);
GetTime_I2C();
year_date = 0b00110001;
year = year_date & 0b11000000;
if((year_date>>6)<old_year){
year=ReadEeprom(YEAR_ADDR)+4;
// year+=4;
WriteEeprom(YEAR_ADDR, year);
}

i tried the above code but the code is not able to detect the roll over from 11 to 00 in the year date register and plus 4 to the base year which is (08) i saved in EEprom earlier. Instead of from 2011 roll over to 2012(2008+4), it goes back to 2008.
 
Last edited:
I don't see where you setup old_year. I know it is defined as a static but it won't retain it's value during power down.

Why not simply do,
Code:
    year = ReadEeprom(YEAR_ADDR);	//get the year
    GetTime_I2C();			//get current time and year(0-3)
    while((year_date>>6)!=(year&3)) 	//do they agree
        year++;				//no so play catch up
    WriteEeprom(YEAR_ADDR, year);	//write it back

Mike.
 
Yup, yup i've tried but it seems that the above code can't get it work.
Btw, if you are saying the static variable can't retain it value when power down , is there any other way that can retain the last year value?

Thanks!
 
I can't see why that code wouldn't work. Are you sure it isn't your other code that needs to be changed as well in order for it to work.

Maybe I should explain it, If the EEPROM contains the value 22 (2022) and the I²C chip contains 10xxxxxx then the comparison ((year_date>>6)!=(year&3)) will evaluate false as 10xxxxxx>>6=2 and 22&3=2 (the comparison is not equal). If however the year has rolled over during power down then the I²C chip will return 11xxxxxx and the year will be incremented until year gets to 23 as 23&3=3. your other test in the program should do the same comparison and only increment and write back when the values are not equal.

The only way to retain values during power down is in EEPROM or on the non volatile memory on your time chip.

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