在线时间1258 小时
UID3174487
注册时间2015-10-31
NXP金币2015
TA的每日心情 | 开心 2025-5-29 08:54 |
---|
签到天数: 2992 天 连续签到: 8 天 [LV.Master]伴坛终老
金牌会员
 
- 积分
- 12035
- 最后登录
- 2025-5-29
|
晚上抽个空继续LPC54114开发板搞起,【LPC54114】+ A2.GPIO操作点亮数码管这篇帖子点亮了数码管,今天来学习一下RTC(Real-time clock)。
从原理图上可以看到晶振是焊接了的,所以就可以直接使用了。
操作起来也不是很复杂,主要是对以下四个寄存器的操作。手册上写的很清楚跟着操作就可以了。
- #include "fsl_device_registers.h"
- #include "fsl_debug_console.h"
- #include "board.h"
- #include "pin_mux.h"
- #include "fsl_common.h"
- #include "fsl_iocon.h"
- #include <stdbool.h>
- #include <stdio.h>
- #include "app_interrupt.h"
- #include "app_led.h"
- #include "app_key.h"
- #include "hc595.h"
- #include "fsl_rtc.h"
- /*******************************************************************************
- * Definitions
- ******************************************************************************/
- // 0 1 2 3 4 5 6 7 8 9 a b c d e f
- // f g dp e d c b a
- //uint8_t table[] = { 0x60,0xf9,0xa4,0xb0,0x39,0x32,0x22,0xf8,0x20,0x30,0x28,0x23,0x66,0xa1,0x26,0x2e,0xbf};
- uint8_t table[] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xbf};
- uint8_t Conversion(uint8_t data)
- {
- return ((data<<2)&0x80)|((data>>2)&0x20)|(data&0x5f);
- }
- /*******************************************************************************
- * Prototypes
- ******************************************************************************/
- int main(void)
- {
- /* Init board hardware. */
- /* attach 12 MHz clock to FLEXCOMM0 (debug console) */
- CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);
- BOARD_InitPins();
- BOARD_BootClockRUN();
- BOARD_InitDebugConsole();
-
- SystemCoreClockUpdate();
-
- SysTick_Config(SystemCoreClock/1000);
-
- PRINTF("\r\n-------------------------------\r\n\r\n");
- PRINTF("hello world.\r\n");
- PRINTF("LPC54110 Sys Clock is %dMhz.\r\n", SystemCoreClock/1000000);
- PRINTF("\r\n-------------------------------\r\n");
- CLOCK_EnableClock(kCLOCK_InputMux);
- CLOCK_EnableClock(kCLOCK_Iocon);
- CLOCK_EnableClock(kCLOCK_Gpio0);
- CLOCK_EnableClock(kCLOCK_Gpio1);
-
- HC595Init();
- key_init();
-
- rtc_datetime_t date;
- RTC_Init(RTC);
-
- date.year = 2017;
- date.month = 04;
- date.day = 18;
- date.hour = 20;
- date.minute = 00;
- date.second = 00;
-
- /* 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);
- /* Start the RTC time counter */
- RTC_StartTimer(RTC);
- HC595SendData_eight(Conversion(table[0]), Conversion(table[1]), Conversion(table[2]), Conversion(table[3]), \
- Conversion(table[4]), Conversion(table[5]), Conversion(table[6]), Conversion(table[7]));
- HAL_Delay(2000);
- while (1)
- {
- RTC_GetDatetime(RTC, &date);
-
- // printf("Current datetime: %04d-%02d-%02d %02d:%02d:%02d",
- // date.year,
- // date.month,
- // date.day,
- // date.hour,
- // date.minute,
- // date.second);
- if(key_value(0) == 0)
- HC595SendData_eight(Conversion(table[date.year%100/10]),Conversion(table[date.year%10]),Conversion(table[16]),Conversion(table[date.month/10]),\
- Conversion(table[date.month%10]),Conversion(table[16]),Conversion(table[date.day/10]),Conversion(table[date.day%10]));
- else
- HC595SendData_eight(Conversion(table[date.hour/10]),Conversion(table[date.hour%10]),Conversion(table[16]),Conversion(table[date.minute/10]),\
- Conversion(table[date.minute%10]),Conversion(table[16]),Conversion(table[date.second/10]),Conversion(table[date.second%10]));
- }
- }
复制代码 开机显示01234567然后是时间的显示,按下板卡上的KEY0会显示日期松开显示时间。这个数码管比较大,显示效果还是很好的。
工程:
lpc54114.zip
(9.36 MB, 下载次数: 74)
|
|