User manual
Hardware Libraries and Drivers
2011 Microchip Technology Inc. DS41614A-page 33
5.8 USING THE RTCC DRIVER
The RTC driver simply keeps track of seconds. The power-up initial value is ‘0’,
however, a function (rtcc_set) is provided to change that value. To keep the seconds
up-to-date, the function, rtcc_handler, must be called more frequently than the
defined value of CLOCKS_PER_SECOND. There are two options for the RTCC driver.
The first option is to use the Timer1 counter to provide a 1 Hz interrupt
(CLOCKS_PER_SECOND = 1). The second option is to use the LCD write-allowed
interrupt flag to provide a 128 Hz event (CLOCKS_PER_SECOND = 128). The two
choices are selected by defining use_lcdif or undefining use_lcdif.
5.8.1 RTCC Function Interface
5.8.1.1 rtcc_init
Initialize the RTCC function including Timer1, if required.
FIGURE 5-12:
5.8.1.2 rtcc_handler
The rtcc_handler function must be called frequently to keep the internal seconds
counter accurate.
FIGURE 5-13:
5.8.1.3 rtcc_set
After system initialization, the seconds counter is cleared to ‘0’. The standard C
libraries equate 0 seconds to Midnight, Jan 1, 1970. That time has expired a long time
ago, so a new time in seconds can be configured with rtcc_set().
System_initialization()
{
rtcc_init();
}
System_interrupt_service_routine()
{
If(TMR1IF & TMR1IE)
{
TMR1IF = 0;
rtcc_handler();
}
}