Datasheet
14.6 Initialization/application information
This section provides example code to give some basic direction to a user on how to
initialize and configure the RTC module. The example software is implemented in C
language.
The example below shows how to implement time of day with the RTC using the XOSC
clock source to achieve the lowest possible power consumption.
Example: 14.6.1 Software calendar implementation in RTC ISR
/* Initialize the elapsed time counters */
Seconds = 0;
Minutes = 0;
Hours = 0;
Days=0;
/* Configure RTC to interrupt every 1 second from XOSC (32.768KHz) clock source */
RTC_MOD = 511; // overflow every 32 times
RTC_SC2 = RTC_SC2_RTCPS_MASK; // external 32768 clock selected with 1/64 predivider.
RTC_SC1 = RTC_SC1_RTIF_MASK | RTC_SC1_RTIE_MASK; // interrupt cleared and enabled
/**********************************************************************
Function Name : RTC_ISR
Notes : Interrupt service routine for RTC module.
**********************************************************************/
#pragma TRAP_PROC
void RTC_ISR(void)
{
/* Clears the interrupt flag, RTIF, and interrupt request */
RTC_SC1_RTIF = 1;
/* RTC interrupts every 1 Second */
Seconds++;
/* 60 seconds in a minute */
if (Seconds > 59)
{
Minutes++;
Seconds = 0;
}
/* 60 minutes in an hour */
if (Minutes > 59)
{
Hours++;
Minutes = 0;
}
/* 24 hours in a day */
if (Hours > 23)
{
Days ++;
Hours = 0;
}
Initialization/application information
MC9S08PA60 Reference Manual, Rev. 1, 9/2012
402 Freescale Semiconductor, Inc.
