User`s manual

RX62N Group, RX621 Group 5. Usage Examples
/* Peripheral driver function prototypes */
#include "r_pdl_cmt.h"
#include "r_pdl_cgc.h"
#include "r_pdl_io_port.h"
#include "r_pdl_intc.h"
/* RPDL device-specific definitions */
#include "r_pdl_definitions.h"
/* Callback function prototype */
void CMT0_handler(void);
void main(void)
{
/* Initialise the system clocks */
R_CGC_Set(
12.0E6,
96E6,
48E6,
24E6,
PDL_CGC_BCLK_DISABLE
);
/* Set the CPU’s Interrupt Priority Level to 0 */
R_INTC_Write(
PDL_INTC_REG_IPL,
0
);
/* Configure a port pin for output */
R_IO_PORT_Set(
PDL_IO_PORT_3_4,
PDL_IO_PORT_OUTPUT
);
/* Configure CMT channel 0 for 1 kHz operation */
R_CMT_Create(
0,
PDL_CMT_FREQUENCY,
1E3,
CMT0_handler,
7
);
/* Change the frequency to 10kHz */
R_CMT_Control(
0,
PDL_CMT_STOP | PDL_CMT_FREQUENCY | PDL_CMT_START,
10E3
);
}
void CMT0_handler(void)
{
/* Invert the port pin */
R_IO_PORT_Modify(
PDL_IO_PORT_3_4,
PDL_IO_PORT_XOR,
1
);
}
Figure 5-16: Example of Compare Match Timer use
R20UT0084EE0112 Rev.1.12 Page 5-31
July. 16, 2014