| 
				打卡等级:初来乍到打卡总天数:1最近打卡:2025-10-18 22:00:38  已绑定手机新手上路 
 
 
	积分26 
 | 
 
 发表于 2025-10-18 22:00:38
|
显示全部楼层 
| 我遇到了问题,我的串口返回时间是这样的 
 [21:54:13.664]接收←Year=206410,Month=4628,Day=2835,Hour=4924,Minute=20519,Second=61716
 
 [21:54:14.164]接收←Year=206410,Month=4628,Day=2835,Hour=4924,Minute=20519,Second=61716
 
 [21:54:14.664]接收←Year=206410,Month=4628,Day=2836,Hour=4924,Minute=20519,Second=61716
 
 
 
 
 我的返回代码是这样的
 
 unsigned char year, month, day, hour, minute, second;
 // 读取时间
 year = RTC_ReadYear();
 month = RTC_ReadMonth();
 day = RTC_ReadDay();
 hour = RTC_ReadHour();
 minute = RTC_ReadMinute();
 second = RTC_ReadSecond();
 
 printf("Year=20%u,Month=%u,Day=%u,Hour=%u,Minute=%u,Second=%u\r\n", year, month, day, hour, minute, second);
 
 delay_ms(500);
 
 
 
 
 
 
 我使用的Aicube配置的
 void RTC_Init(void)
 {
 RTC_CLK_X32K();                     //RTC使用外部32768当作时钟源
 
 RTC_SetAlarmHour(-1);               //设置RTC闹钟的小时
 RTC_SetAlarmMinute(-1);             //设置RTC闹钟的分钟
 RTC_SetAlarmSecond(-1);             //设置RTC闹钟的秒
 RTC_SetAlarmSSecond(0);             //初始化RTC闹钟的次秒
 
 RTC_SetYear(25);                    //设置RTC的年
 RTC_SetMonth(10);                   //设置RTC的月
 RTC_SetDay(18);                     //设置RTC的日
 RTC_SetHour(20);                    //设置RTC的小时
 RTC_SetMinute(11);                  //设置RTC的分钟
 RTC_SetSecond(5);                   //设置RTC的秒
 RTC_SetSSecond(0);                  //初始化RTC的次秒
 
 RTC_Run();                          //启动RTC
 RTC_SyncInitial();                  //同步RTC的初始值
 while (RTC_IsSyncing());            //等待同步完成
 
 RTC_SetIntPriority(3);              //设置中断为最高优先级
 RTC_EnableAlarmInt();               //使能RTC闹钟中断
 RTC_EnableDayInt();                 //使能RTC天中断
 RTC_EnableHourInt();                //使能RTC小时中断
 RTC_EnableSecondInt();              //使能RTC秒中断
 
 //<<AICUBE_USER_RTC_INITIAL_BEGIN>>
 // 在此添加用户初始化代码
 //<<AICUBE_USER_RTC_INITIAL_END>>
 }
 | 
 |