大家好,下面是我的RTC代码, 软件在运行一段时间之后,rtc_stime.year=0x30了,其他的都清零了。
变成:2048-0-0 0:0:0
void Read_Time(void)
{
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_GetTime(RTC_Format_BIN,&RTC_TimeStruct);
RTC_GetDate(RTC_Format_BIN,&RTC_DateStruct);
rtc_stime.year = 0;
rtc_stime.month = 0;
rtc_stime.day = 0;
rtc_stime.hour =0;
rtc_stime.min = 0;
rtc_stime.sec = 0;
rtc_stime.year = RTC_DateStruct.RTC_Year;
rtc_stime.month = RTC_DateStruct.RTC_Month;
rtc_stime.day = RTC_DateStruct.RTC_Date;
rtc_stime.hour =RTC_TimeStruct.RTC_Hours;
rtc_stime.min = RTC_TimeStruct.RTC_Minutes;
rtc_stime.sec = RTC_TimeStruct.RTC_Seconds;
#if DUG_RTC > 0
printf(" rtc time %02d-%02d-%02d %02d:%02d:%02d \r\n ",rtc_stime.year,rtc_stime.month,rtc_stime.day,rtc_stime.hour,rtc_stime.min,rtc_stime.sec);
#endif
} |