在LPC55S69的内核中配置了RTC计时器,并在函数库中也提供了相应的函数支持。为此,我们只需要调用相关的函数并为它配置一个显示屏就可实现RTC电子时钟的功能。 实现图示效果的主程序为: - int main(void)
- {
- uint32_t sec,i;
- uint32_t currSeconds;
- uint8_t index;
- rtc_datetime_t date;
- /* Board pin, clock, debug console init */
- /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
- CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
- /* Enable the RTC 32K Oscillator */
- // SYSCON->RTCOSCCTRL |= SYSCON_RTCOSCCTRL_EN_MASK;
- BOARD_InitPins();
- BOARD_BootClockFROHF96M();
- BOARD_InitDebugConsole();
- /* Init RTC */
- RTC_Init(RTC);
- app_oled_init();
- OLED_Init();
- OLED_Clear();
- OLED_ShowString(0,0,"OKDOE1 TEST",16);
- OLED_ShowString(0,2,"RTC & OLED",16);
- OLED_ShowString(0,5," : :",16);
- /* Set a start date time and start RT */
- date.year = 2020U;
- date.month = 11U;
- date.day = 11U;
- date.hour = 19U;
- date.minute = 0;
- date.second = 0;
- /* RTC time counter has to be stopped before setting the date & time in the TSR register */
- RTC_StopTimer(RTC);
- /* Set RTC time to default */
- RTC_SetDatetime(RTC, &date);
- /* Enable RTC alarm interrupt */
- RTC_EnableInterrupts(RTC, kRTC_AlarmInterruptEnable);
- /* Enable at the NVIC */
- EnableIRQ(RTC_IRQn);
- /* Start the RTC time counter */
- RTC_StartTimer(RTC);
- /* This loop will set the RTC alarm */
- while (1)
- {
- busyWait = true;
- index = 0;
- sec = 0;
- /* Get date time */
- RTC_GetDatetime(RTC, &date);
- OLED_ShowNum(0,5,date.hour,2,16);
- OLED_ShowNum(24,5,date.minute,2,16);
- OLED_ShowNum(48,5,date.second,2,16);
- for(i=0;i<10000;i++);
- }
- }
复制代码
在主程序中,包括了RTC时钟的设置环节,在初次使用时,只需按时时间加以调整即可。 此外,如果感兴趣的话,还可利用开发板上的小按键来随机调整RTC的系统时间。 小家伙,一样会有大力量! RTC电子时钟
|