Datasheet
Hardware Libraries and Drivers
2010 Microchip Technology Inc. DS41401B-page 27
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().
FIGURE 5-14:
5.8.1.4 time
The standard C libraries require the application to supply the time function. This
function returns the current time_t value or loads a supplied time_t value. The
interrupts are saved and restored to make this function safe for use with interrupt driven
code.
5.9 USING THE MCP9800 DRIVER
The MCP9800 is an I
2
C temperature sensor. The MCP9800 driver provides a simple
interface to the features in the sensor.
System_initialization()
{
rtcc_init();
}
System_interrupt_service_routine()
{
If(TMR1IF & TMR1IE)
{
TMR1IF = 0;
rtcc_handler();
}
}
#include <time.h>
Time_set() // set the time & date to 1 second after midnight, July 4, 2009
{
struct tm time_str;
time_t unix_time;
time_str.tm_year = 2009; // the year
time_str.tm_mon = 7; // the month
time_str.tm_mday = 4; // the day of the month
time_str.tm_hour = 0; // the hour (0-23)
time_str.tm_min = 0; // the minutes
time_str.tm_sec = 1; // the seconds
time_str.tm_isdst = -1; // daylight savings time modifier
unix_time = mktime(&time_str);
rtcc_set(unix_time);
}