本帖最后由 hxb20122012 于 2018-6-12 10:56 编辑
u8 RTC_Set(u16 syear,u8 smon,u8 sday,u8 hour,u8 min,u8 sec)
{
//RTC_InitTypeDef RTC_InitStructure;
RTC_DateTimeTypeDef RTC_DateTimeStructure;
if(syear<1970||syear>2099)return 1;
RTC_DateTimeStructure.Year = (uint8_t)(syear-2000);
RTC_DateTimeStructure.Month = smon;
RTC_DateTimeStructure.Date = sday;
RTC_DateTimeStructure.Week = 3;
RTC_DateTimeStructure.Hour = hour;
RTC_DateTimeStructure.Minute = min;
RTC_DateTimeStructure.Second = sec;
RTC_SetDateTime(RTC_DateTimeStructure); //Ê״γõʼ»¯RTC(2016Äê6ÔÂ5ÈÕ ÖÜÆß 12:00:00)
RTC_WriteBackupRegister(RTC_BKP_DR0, RTC_FLAG_BKP);
return 0;
}
u8 RTC_Get(void)
{
RTC_DateTimeTypeDef RTC_DateTimeStructure;
RTC_GetDateTime(&RTC_DateTimeStructure);
calendar.w_year = (u16)RTC_DateTimeStructure.Year+2000;
calendar.w_month = RTC_DateTimeStructure.Month;
calendar.w_date = RTC_DateTimeStructure.Date;
calendar.week = RTC_DateTimeStructure.Week;
calendar.hour = RTC_DateTimeStructure.Hour;
calendar.min = RTC_DateTimeStructure.Minute;
calendar.sec = RTC_DateTimeStructure.Second;
return 0;
}
问题: 比如 2018-06-12 23:59:50 ,10秒之后, 变成 2018-06-12 0:0:0 ,日期没有变化
程序开启了: ALARM
void RTC_SetAlarm_main(void)
{
RTC_AlarmTypeDef RTC_AlarmStructure_main;
EXTI_InitTypeDef EXTI_InitStructure;
RTC_Get();
RTC_AlarmCmd(RTC_Alarm_A,DISABLE);
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_H12 = 0x00;
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Hours = calendar.hour;
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Minutes = calendar.min;
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Seconds = calendar.sec;
if(calendar.sec+ALARM_TIME_SEC>=60)
{
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Seconds = (calendar.sec+ALARM_TIME_SEC)-60;
if((calendar.min+1)>=60)
{
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Minutes = (calendar.min+1)-60;
if((calendar.hour+1)>=24)
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Hours = (calendar.hour+1)-24;
else
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Hours = calendar.hour+1;
}
else
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Minutes = calendar.min+1;
}
else
RTC_AlarmStructure_main.RTC_AlarmTime.RTC_Seconds = calendar.sec+ALARM_TIME_SEC;
// RTC_AlarmStructure_main.RTC_AlarmDateWeekDay = 0x31;
// RTC_AlarmStructure_main.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
// RTC_AlarmStructure_main.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay;
// RTC_SetAlarm(RTC_Format_BCD, RTC_Alarm_A, &RTC_AlarmStructure_main);
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure_main);
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarm */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
RTC_WaitForSynchro();
}
void RTC_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
RTC_TimeTypeDef RTC_TimeStructure;
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_ClearITPendingBit(RTC_IT_ALRA);
EXTI_ClearITPendingBit(EXTI_Line17);
}
}
好像是ALARM影响了
|