RTC is a relatively common part of the current device, and many devices need to look at the time. RTC Real-time clock has been integrated in a number of microcontroller, before also dedicated clock chip, now the CORTEX-M3 core includes this part. Unlike previous NXP's ARM7 cores, the LPC1768 clock source is provided only by the 32K clock source, which is to be noted, and the other is consistent with ARM7.
RTC is actually a timing, can be understood as the second timer, RTC Register quite a lot, but the register structure is relatively simple, operation is very convenient.
Explains several important registers, interrupt position register ILR, Clock Control register CCR, counter increment interrupt register CIIR, Alarm mask Register AMR
First ILR Interrupt position register
BIT0, when an interrupt is generated for the 1 O'Clock Counter increment module.
BIT1, when 1 is the alarm register generates an interrupt
Second CCR Clock control register
BIT0, the clock can be bit, for 1 is when can BIT1, reset CTC.
BIT4, when calibrated to
Third CIIR counter increment interrupt Register
It can be clearly seen in the figure, respectively, the date of the month and minute, the corresponding position for, the corresponding interruption, the comparison is set to 0x01, both to produce an interrupt per second, set to 0x02, both produce an interrupt every minute.
Fourth, AMR alarm screen Register
This is the register is shielded corresponding alarm bit, and the CIIR bit definition is the same.
As for the other registers like the day of the month and seconds this register can be intuitively aware of its purpose, is not described in one by one.
See Software Design
typedef struct _TIME_TYPE//Time type definition {int8u sec; Seconds int8u min; Sub-int8u hour; When int8u Dom; Day int8u Mon; Month int8u Dow;
Week int16u year;//year}time_type;
void Setnowtime (Time_type * pdata) {lpc_rtc->sec = pdata->sec;
Lpc_rtc->min = pdata->min;
Lpc_rtc->hour = pdata->hour;
Lpc_rtc->dom = pdata->dom;
Lpc_rtc->month = pdata->mon;
Lpc_rtc->dow = pdata->dow;
Lpc_rtc->year = pdata->year;
} Void rtc_init (Time_type * pdata) {LPC_RTC->CCR = 0x0;//disable clock, ready to initialize RTC LPC_RTC->ILR = 0x03;//Purge Interrupt Lpc_rtc->ciir = 0x00;//does not produce an interrupt lpc_rtc->amr = 0xFF; Block all alarm interrupts setnowtime (pdata);//Set Time NVIC_ENABLEIRQ (RTC_IRQN); RTC Interrupt Nvic_setpriority (RTC_IRQN, 9);//Set Interrupt priority LPC_RTC->CCR = 0x01; Start RTC LPC_RTC->CCR = 0x01; Start RTC counter} void Rtctimesend (void) {usart0_printf ("%02d%02d month%02d day%02d:%02d:%02d\r\n", Lpc_rtc->yeAr,lpc_rtc->month,lpc_rtc->dom, Lpc_rtc->hour,lpc_rtc->min, lpc_rtc->sec); } void Rtc_irqhandler (void) {rtctimesend ();//Send time LPC_RTC->ILR = 0x01;//Clear Interrupt}
Generates an interrupt per second, sending time data to the serial port in the interrupt