User`s manual

RX62N Group, RX621 Group 5. Usage Examples
5.10. Real-time Clock
Figure 5-17 shows an example of Real-time Clock usage.
The sub-clock oscillator is enabled and allowed to settle.
The two-second settling time is generated using one CMT call with the peripheral clock (PCLK) set to 12MHz.
Other methods can be used, such as multiple calls of the one-shot function.
The current time and date are set, with the day of week being calculated by the function.
The alarm is set for 10 seconds in the future.
After 10 seconds have elapsed, the callback function is called and moves the alarm time to 10 seconds in the
future.
/* Peripheral driver function prototypes */
#include "r_pdl_cgc.h"
#include "r_pdl_cmt.h"
#include "r_pdl_rtc.h"
/* PDL device-specific definitions */
#include "r_pdl_definitions.h"
void Alarm_handler(void);
void main(void)
{
uint8_t Flags;
uint32_t CurrentTime;
/* Set PCLK to 12MHz and enable the sub clock oscillator */
R_CGC_Set(
12E6,
96E6,
12E6,
24E6,
PDL_CGC_SUB_CLOCK_ENABLE
);
/* Allow 2s for the sub-clock oscillator to settle */
R_CMT_CreateOneShot(
0,
PDL_NO_DATA,
2.0,
PDL_NO_FUNC,
0
);
/* Set the current time and enable the alarm */
R_RTC_Create(
PDL_RTC_ALARM_TIME_ENABLE,
0xFF114250, // Automatic day of week, 11:42:50
0x20100921, // 21-Sep-2010
0x00114300, // Alarm in 10 seconds time
PDL_NO_DATA,
Alarm_handler,
15,
PDL_NO_FUNC,
PDL_NO_DATA
);
/* Read the timer values */
R_RTC_Read(
R20UT0084EE0112 Rev.1.12 Page 5-32
July. 16, 2014