// // Created by EDZ on 25-9-16. // #include "../Inc/RTC_SLEEP.h" RTC_TimeTypeDef SOS_key_struct = {0}; RTC_TimeTypeDef JUGE_key_struct = {0}; RTC_TimeTypeDef Online_struct = {0}; // RTC_key_struct SOS_key_struct = { // .key_Count = 0, // .key_Duration = 0, // .key_CheckActive = FALSE // }; // // RTC_key_struct JUGE_key_struct = { // .key_Count = 0, // .key_Duration = 0, // .key_CheckActive = FALSE // }; // // 单独的RTC时间和日期设置函数 // void RTC_SetDateTime(RTC_HandleTypeDef *hrtc, uint8_t hours, uint8_t minutes, uint8_t seconds, // uint8_t weekday, uint8_t month, uint8_t date, uint8_t year) { // RTC_TimeTypeDef sTime = {0}; // RTC_DateTypeDef sDate = {0}; // // // 设置时间 // sTime.Hours = hours; // sTime.Minutes = minutes; // sTime.Seconds = seconds; // HAL_RTC_SetTime(hrtc, &sTime, RTC_FORMAT_BCD); // // // 设置日期 // sDate.WeekDay = weekday; // sDate.Month = month; // sDate.Date = date; // sDate.Year = year; // HAL_RTC_SetDate(hrtc, &sDate, RTC_FORMAT_BCD); // } // // 读取RTC当前时间和日期 // void RTC_GetDateTime(RTC_HandleTypeDef *hrtc, RTC_DateTimeTypeDef *datetime) { // RTC_TimeTypeDef sTime = {0}; // RTC_DateTypeDef sDate = {0}; // // // 读取当前时间 // HAL_RTC_GetTime(hrtc, &sTime, RTC_FORMAT_BCD); // // 读取当前日期 // HAL_RTC_GetDate(hrtc, &sDate, RTC_FORMAT_BCD); // // // 存储到自定义结构体中 // datetime->hours = sTime.Hours; // datetime->minutes = sTime.Minutes; // datetime->seconds = sTime.Seconds; // datetime->weekday = sDate.WeekDay; // datetime->month = sDate.Month; // datetime->date = sDate.Date; // datetime->year = sDate.Year; // } // // void RTC_Sleep_Enter_Fun() { // /* 调用独立的函数设置初始时间 */ // RTC_SetDateTime(&hrtc, 0x12, 0x00, 0x00, // RTC_WEEKDAY_MONDAY, RTC_MONTH_SEPTEMBER, 0x16, 0x25); // // /* 获取当前时间用于设置闹钟 */ // RTC_TimeTypeDef currentTime = {0}; // HAL_RTC_GetTime(&hrtc, ¤tTime, RTC_FORMAT_BCD); // // /* 设置闹钟:50秒后触发 */ // RTC_AlarmTypeDef sAlarm = {0}; // sAlarm.AlarmTime.Hours = currentTime.Hours; // sAlarm.AlarmTime.Minutes = currentTime.Minutes; // sAlarm.AlarmTime.Seconds = (currentTime.Seconds + 50) % 60; // sAlarm.Alarm = RTC_ALARM_A; // // HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD); // // /* 进入 STANDBY 模式 */ // __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // 清除唤醒标志 // HAL_PWR_EnterSTANDBYMode(); // MCU 进入 STANDBY // // // MCU 唤醒后会从 main() 重新开始运行 // }