恩智浦LPC1549@eeworld ( 六 )RTC
Real-Time Clock (RTC)
该RTC使用一个独立的振荡器,它具有以下的时钟输出:
- 32 kHz的时钟,可选择系统时钟和CLKOUT引脚。
- 1 Hz时钟为RTC计时。
- 1 kHz的时钟进行高分辨率RTC计时。
寄存器也比较少,才4个
参考例程,先运行起来
程序中只要RTC,没有闹钟,和唤醒功能,中断等等
void Init_RTC(void)
{
/* Enable the RTC oscillator, oscillator rate can be determined by
calling Chip_Clock_GetRTCOscRate() */
Chip_Clock_EnableRTCOsc();
/* Initialize RTC driver (enables RTC clocking) */
Chip_RTC_Init(LPC_RTC);
/* Enable RTC as a peripheral wakeup event */
Chip_SYSCTL_EnableERP1PeriphWakeup( SYSCTL_ERP1_WAKEUP_RTCALARMINT );//|SYSCTL_ERP1_WAKEUP_RTCWAKEINT);
/* RTC reset */
Chip_RTC_Reset(LPC_RTC);
/* Start RTC at a count of 0 when RTC is disabled. If the RTC is enabled, you
need to disable it before setting the initial RTC count. */
Chip_RTC_Disable(LPC_RTC);
Chip_RTC_SetCount(LPC_RTC, 0);
/* Set a long alarm time so the interrupt won't trigger */
Chip_RTC_SetAlarm(LPC_RTC, 1);
/* Enable RTC and high resolution timer - this can be done in a single
call with Chip_RTC_EnableOptions(LPC_RTC, (RTC_CTRL_RTC1KHZ_EN | RTC_CTRL_RTC_EN)); */
Chip_RTC_Enable1KHZ(LPC_RTC);
Chip_RTC_Enable(LPC_RTC);
/* Clear latched RTC interrupt statuses */
Chip_RTC_ClearStatus(LPC_RTC, (RTC_CTRL_OFD | RTC_CTRL_ALARM1HZ | RTC_CTRL_WAKE1KHZ));
/* Enable RTC wake and alarm interrupts */
NVIC_EnableIRQ(RTC_ALARM_IRQn);
//NVIC_EnableIRQ(RTC_WAKE_IRQn);
/* Enable RTC alarm interrupt */
Chip_RTC_EnableWakeup(LPC_RTC, (RTC_CTRL_ALARMDPD_EN));// | RTC_CTRL_WAKEDPD_EN
}
通过2个库函数来设置,读取时钟,不过要把COUNT寄存器 转换计算出,年,月,日,时,分秒
Chip_RTC_SetCount(LPC_RTC,couter );
//获取RTC
couter=Chip_RTC_GetCount(LPC_RTC);
效果图