The Real Time Clock Calendar (RTCC) is a PIC24F module that permits to keep track of the time with the secondary oscillator. This feature permits handling timed alarm interrupts without any polling by the user task. The RTCC can be seen as an advanced alarm clock since it's alarm can executed not only every day (like any other standard alarm clock) but with different alarm time configurations.
The openPicus framework embedds RTCC helper APIs to permit users to use the RTCC without dealing with PIC internal registers. To use this library it is necessary to enable the flag of "RTCC library" using Wizard Tool of IDE.
struct tm contains calendar date and time broken down into its components.
The structure contains nine members of type int (in any order), which are:
||int||seconds after the minute||0 - 61*|
||int||minutes after the hour||0 - 59|
||int||hours since the midnight||0 - 23|
||int||day of the month||1 - 31|
||int||months since January||0 - 11|
||int||years since 1900|
||int||days since Sunday||0 - 6|
||int||days since January 1||0 - 365|
||int||daylight saving time flag||values**|
* tm_sec is generally 0-59. The extra range is to accommodate for leap seconds in certain systems.
** The Daylight Saving Time flag (tm_isdst) is greater than zero if Daylight Saving Time is in effect, zero if Daylight Saving Time is not in effect, and less than zero if the information is not available.
For example, to assign the values corresponding to the date “April 6, 2013 (Saturday), hour 20:01.02” to a defined structure, the following sequence of commands may be used:
struct tm mytime; //initialization of mytime mytime.tm_hour = 20; mytime.tm_min = 1; mytime.tm_sec = 2; mytime.tm_mday = 6; mytime.tm_mon = 3; mytime.tm_year = 113; mytime.tm_wday = SATURDAY;
Once the user's structure is set up, the information exchange between this structure and the RTCC module register can take place using the following functions:
|void RTCCGet(struct tm * rtcc)||Reads the actual date/time from the RTCC and puts it inside a struct pointer.
|void RTCCSet(struct tm * rtcc)||Sets the date/time for the RTCC and enables the RTCC module.
|void RTCCAlarmConf(struct tm * rtcc, int repeats, BYTE whenToRaise, void(*)()fptr)||Function to configure the alarm. It is possible to set the interval for the alarm and if it must be repeated continously.
whenToRaise How often the alarm must be raised:
fptr Custom user function to execute when alarm event is raised. please use NO_ALRM_EVENT to ignore.
|void RTCCAlarmSet(BYTE run)||Activates or deactivates the alarm.
|BOOL RTCCAlarmStat()||Activates or deactivates the alarm.
RTCC Alarm Notes
The meaning of the flag "EVERY_X" on the function RTCCAlarmConf(...) is that the alarm is raised every time the RTCC clock is the same of your alarm, but ignoring the higher part you don't want.
For example EVERY_HOUR means that every time your minutes are the same of the alarm clock previously set, you will have an alarm:
- You set alarm at 8:30 and a flag "EVERY_HOUR" then the alarm will raise every hour:
- 00:30, 01:30, 02:30, and so on....
- But if you set the flag "EVERY_DAY" instead, your alarm will be raised only at 8:30 of each day
Examples are available on tutorial section