在线时间694 小时
UID406727
注册时间2012-12-12
NXP金币21
TA的每日心情 | 奋斗 2023-2-15 00:12 |
---|
签到天数: 969 天 连续签到: 1 天 [LV.10]以坛为家III
金牌会员
 
- 积分
- 7125
- 最后登录
- 2023-4-20
|
本帖最后由 jinglixixi 于 2019-12-6 21:50 编辑
LPC51U68具有RTC计时功能,与前面介绍的OLED屏相结合,就能构成一个RTC电子时钟,其显示效果如图所示。 RTC计时效果
显示该效果的主程序如下: - #include "fsl_debug_console.h"
- #include "board.h"
- #include "fsl_rtc.h"
- #include "pin_mux.h"
- #include <stdbool.h>
- #include "oledfont.h"
- int main(void)
- {
- uint32_t sec;
- 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_BootClockFROHF48M();
- BOARD_InitDebugConsole();
- /* Init RTC */
- RTC_Init(RTC);
- /* Set a start date time and start RT */
- date.year = 2019U;
- date.month = 12U;
- date.day = 4U;
- date.hour = 8U;
- date.minute = 10;
- 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);
-
- OLED_Init();
- OLED_Clear();
- OLED_ShowString(0,0,"LPC51U68 TEST",16);
- OLED_ShowString(0,2,"OLED Display",16);
- OLED_ShowString(0,4,"jinglixixi",16);
- OLED_ShowString(0,6,"2019.12.3",16);
- delay_ms(800);
- OLED_Clear();
- busyWait = true;
- index = 0;
- sec = 0;
- while(1)
- {
- /* Get date time */
- RTC_GetDatetime(RTC, &date);
- OLED_ShowString(0,0,"Current datetime",16);
- OLED_ShowNum(0,2,date.year,4,16);
- OLED_ShowChar(32,2,'-',16);
- OLED_ShowNum(40,2,date.month,2,16);
- OLED_ShowChar(56,2,'-',16);
- OLED_ShowNum(64,2,date.day,2,16);
-
- OLED_ShowNum(16,4,date.hour,2,16);
- OLED_ShowChar(32,4,':',16);
- OLED_ShowNum(40,4,date.minute,2,16);
- OLED_ShowChar(56,4,':',16);
- OLED_ShowNum(64,4,date.second,2,16);
- delay_ms(500);
- }
- }
复制代码
|
|