rtc. Object
The rtc. object facilitates access to the real-time counter (RTC) of your device. The RTC is an independent hardware counter that has its own power input. When the backup battery is installed, the RTC will continue running even when the rest of the device is powered off. The RTC keeps track of elapsed days, minutes, and seconds, not actual date and time. This is why it is called the "counter," not "clock." Most platforms include a set of convenient date and time conversion syscalls that can be used to transform RTC data into the current date/time and back (see year, month, date, weekday, daycount, hours, minutes, and mincount).
Two methods of the RTC object — rtc.getdata and rtc.setdata — are used to read and set the counter value.
Supposing that your project has curr_year, curr_month, curr_date, curr_hours, curr_minutes, and curr_seconds variables, here is how you set and get the time:
dim curr_year, curr_month, curr_date, curr_hours, curr_minutes, curr_seconds as byte
dim x,y as word
...
...
'set RTC now (data is supposed to be prepared in curr_ variables)
rtc.set(daycount(curr_year,curr_month,curr_date),mincount(curr_hours,curr_minutes),curr_seconds)
...
...
'get RTC now- first get the daycount and mincout into x and y
rtc.getdata(x,y,curr_seconds)
'now convert daycount and mincount into date and time
curr_year=year(x)
curr_month=month(x)
curr_date=date(x)
curr_hours=hours(y)
curr_minutes=minutes(y)
There is also the rtc.running read-only property that tells you whether the RTC is working.
Note that after the device powers up, and provided that the backup power was not present at all times, the RTC may be in the undetermined state and not work properly until the rtc.setdata method is executed at least once. Incorrect behavior may include failure to increment or incrementing at an abnormal rate. The rtc.running read-only property cannot be used to reliably check the RTC state in this situation.
It is not necessary to use rtc.setdata if the backup power was present at all times while the device was off.