STM32F103 RTC 出现问题,当设定时间出现12月的时候,会自动加一月,变为第二年0月!!!希望大家帮忙解答一下。谢谢。
现象如下: (通过串口输出)
Time set: 2015-12-12 12:12:00 // 设置时设定的时间
RTC configured.... // 提示已经设置成功
Time: 2016-0-12 12:12:3 // 通过串口打印的时钟:2016年0月!!!!!!
/*********************************设置代码***************************************/
unsigned char time_set_data[6]; //如2015.10.29.16:57,0x07,0xdf,0x0a,0x1d,0x10,0x39
time_set_data[0] = 0x07; //2015
time_set_data[1] = 0xdf;
time_set_data[2] = 0x0c; //12 月
time_set_data[3] = 0x0c; //12 日
time_set_data[4] = 0x0c; //12 时
time_set_data[5] = 0x0c; //12 分
/*RTC设定函数*/
void Time_Regulate(unsigned char *src)
{
struct tm time;
//memset(&time, 0 , sizeof(time) );
printf("=======================Time Settings==========================\r\n");
time.tm_year=(unsigned int)((src[0]<<8)|src[1]);
time.tm_mon =(unsigned int)src[2];
time.tm_mday=(unsigned int)src[3];
time.tm_hour=(unsigned int)src[4];
time.tm_min =(unsigned int)src[5];
time.tm_sec = 0; // 秒默认为0 ,不设置
printf("Time set: %d-%d-%d %02d:%02d:%02d \r\n", time.tm_year, \
time.tm_mon, time.tm_mday,\
time.tm_hour, time.tm_min, time.tm_sec);
/* Return the value to store in RTC counter register */
Time_SetCalendarTime(time);
}
/*时钟输出函数*/
void Time_Display(void)
{
current_time = Time_GetCalendarTime();
printf("Time: %u-%u-%u %u:%u:%u \r\n", current_time.tm_year, \
current_time.tm_mon, current_time.tm_mday,\
current_time.tm_hour, current_time.tm_min, current_time.tm_sec);
}
|