- M33LC046N RTC时钟特性
- BCD时间,日期可达2099年
- 周期唤醒中断
- 闹钟功能
- 周期信号定时输出
- 数字调校
- 反馈电阻集成
- RTC计时部分不复位
2.RTC组成
3.工作原理
4.软件实现步骤
(1)RTC初始化:不复位,只需写入当前时间;
(2)读取当前RTC时间参数,确保是否正确写入到RTC中;
(3)通过串口将RTC时钟信息打印到电脑串口助手上;
- void MF_RTC_Init(void)
- {
-
- FL_RTC_InitTypeDef defaultInitStruct;
-
- defaultInitStruct.year = 0x20;
- defaultInitStruct.month = 0x10;
- defaultInitStruct.day = 0x01;
- defaultInitStruct.week = 0x03;
- defaultInitStruct.hour = 0x00;
- defaultInitStruct.minute = 0x00;
- defaultInitStruct.second = 0x00;
-
-
- FL_RTC_Init(RTC,&defaultInitStruct );
-
- }
- uint8_t RTC_SetRTC(FL_RTC_InitTypeDef* InitStructer)
- {
- uint8_t n, i;
- uint8_t Result;
- FL_RTC_InitTypeDef TempTime1;
-
- for(n=0 ;n<3; n++)
- {
- FL_RTC_ConfigTime(RTC,InitStructer);
- Result = RTC_GetRTC(&TempTime1);
- if(Result == 0)
- {
- Result = 1;
- for(i=0; i<7; i++)
- {
- if(((uint32_t*)(&TempTime1))[i] != ((uint32_t*)(InitStructer))[i])
- break;
- }
- if(i == 7)
- {
- Result = 0;
- break;
- }
- }
- }
- return Result;
- }
- uint8_t RTC_GetRTC(FL_RTC_InitTypeDef* InitStructer)
- {
- uint8_t n, i;
- uint8_t Result = 1;
-
- FL_RTC_InitTypeDef TempTime1,TempTime2;
-
- for(n=0 ;n<3; n++)
- {
- FL_RTC_GetTime(RTC,&TempTime1);
- FL_RTC_GetTime(RTC,&TempTime2);
-
- for(i=0; i<7; i++)
- {
- if(((uint32_t*)(&TempTime1))[i] != ((uint32_t*)(&TempTime2))[i]) break;
- }
- if(i == 7)
- {
- Result = 0;
- memcpy((uint32_t*)(InitStructer), (uint32_t*)(&TempTime1), 7*sizeof(uint32_t));
- break;
- }
- }
- return Result;
- }
- RTC_GetRTC(&GetTime);
-
- printf("RTC: 日期:20%x-%2x-%2x 星期:%x 时间:%2x:%2x:%2x \r\n",GetTime.year,GetTime.month,GetTime.day,GetTime.week,GetTime.hour,GetTime.minute, GetTime.second);
串口助手显示RTC参数
开发板接线图
|