system
August 28, 2010, 10:29am
1
Hi, I red that till 2100 DS1307 has an accurate calendar, but when I'm trying to write an year >49 with this code
int new_year = (first_year*10) + second_year;
RTC.set(DS1307_YR,new_year);
It doesn't write it to DS1307, why? But if the year is 2049 and the whole year elapsed it continues to 2050.
system
August 28, 2010, 1:08pm
2
What values are in first_year and second_year? What are their types?
Since new_year is defined as an int, the multiplication and addition operations could cause an overflow, resulting in new_year being negative. Perhaps that is why the RTC won't accept it.
system
August 28, 2010, 2:42pm
3
The values of first_year and second_year are between 0-9, both of them are from type int.
system
August 28, 2010, 3:49pm
4
Is the value sent to the RTC to set the year supposed to be a two digit number (10) or a 4 digit number (2010)?
system
August 28, 2010, 5:04pm
5
@Morpheous
I'm trying to write an year >49
Are you using the DS1307 library from here: Google Code Archive - Long-term storage for Google Code Project Hosting. ? (See Footnote.)
If so, then maybe you can contact the author and ask why the following is in the DS1307::set() function in DS1307.cpp
case DS1307_YR:
if(v<50 && v>-1)
{
rtc_bcd[DS1307_YR]=((v / 10)<<4) + (v % 10);
}
break;
I mean, why the heck would he have that v < 50 in there ?
Alternatively, maybe you can find another library that actually makes sense.
Regards,
Dave
Footnote:
If you are not using that library, how about telling us what you are using?
system
August 29, 2010, 12:18pm
6
Yea, as I se[ch1077], the problem is in the library not in the code or the IC. I suppose that if I change the value v<50 it could work?
P.S. I tried to modify the .cpp file and it works now. Thanks for the HELP !!!