RTC_SLEEP.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Created by EDZ on 25-9-16.
  3. //
  4. #include "../Inc/RTC_SLEEP.h"
  5. RTC_TimeTypeDef SOS_key_struct = {0};
  6. RTC_TimeTypeDef JUGE_key_struct = {0};
  7. RTC_TimeTypeDef Online_struct = {0};
  8. RTC_TimeTypeDef SOS_struct = {0};
  9. // RTC_key_struct SOS_key_struct = {
  10. // .key_Count = 0,
  11. // .key_Duration = 0,
  12. // .key_CheckActive = FALSE
  13. // };
  14. //
  15. // RTC_key_struct JUGE_key_struct = {
  16. // .key_Count = 0,
  17. // .key_Duration = 0,
  18. // .key_CheckActive = FALSE
  19. // };
  20. // // 单独的RTC时间和日期设置函数
  21. // void RTC_SetDateTime(RTC_HandleTypeDef *hrtc, uint8_t hours, uint8_t minutes, uint8_t seconds,
  22. // uint8_t weekday, uint8_t month, uint8_t date, uint8_t year) {
  23. // RTC_TimeTypeDef sTime = {0};
  24. // RTC_DateTypeDef sDate = {0};
  25. //
  26. // // 设置时间
  27. // sTime.Hours = hours;
  28. // sTime.Minutes = minutes;
  29. // sTime.Seconds = seconds;
  30. // HAL_RTC_SetTime(hrtc, &sTime, RTC_FORMAT_BCD);
  31. //
  32. // // 设置日期
  33. // sDate.WeekDay = weekday;
  34. // sDate.Month = month;
  35. // sDate.Date = date;
  36. // sDate.Year = year;
  37. // HAL_RTC_SetDate(hrtc, &sDate, RTC_FORMAT_BCD);
  38. // }
  39. // // 读取RTC当前时间和日期
  40. // void RTC_GetDateTime(RTC_HandleTypeDef *hrtc, RTC_DateTimeTypeDef *datetime) {
  41. // RTC_TimeTypeDef sTime = {0};
  42. // RTC_DateTypeDef sDate = {0};
  43. //
  44. // // 读取当前时间
  45. // HAL_RTC_GetTime(hrtc, &sTime, RTC_FORMAT_BCD);
  46. // // 读取当前日期
  47. // HAL_RTC_GetDate(hrtc, &sDate, RTC_FORMAT_BCD);
  48. //
  49. // // 存储到自定义结构体中
  50. // datetime->hours = sTime.Hours;
  51. // datetime->minutes = sTime.Minutes;
  52. // datetime->seconds = sTime.Seconds;
  53. // datetime->weekday = sDate.WeekDay;
  54. // datetime->month = sDate.Month;
  55. // datetime->date = sDate.Date;
  56. // datetime->year = sDate.Year;
  57. // }
  58. //
  59. // void RTC_Sleep_Enter_Fun() {
  60. // /* 调用独立的函数设置初始时间 */
  61. // RTC_SetDateTime(&hrtc, 0x12, 0x00, 0x00,
  62. // RTC_WEEKDAY_MONDAY, RTC_MONTH_SEPTEMBER, 0x16, 0x25);
  63. //
  64. // /* 获取当前时间用于设置闹钟 */
  65. // RTC_TimeTypeDef currentTime = {0};
  66. // HAL_RTC_GetTime(&hrtc, &currentTime, RTC_FORMAT_BCD);
  67. //
  68. // /* 设置闹钟:50秒后触发 */
  69. // RTC_AlarmTypeDef sAlarm = {0};
  70. // sAlarm.AlarmTime.Hours = currentTime.Hours;
  71. // sAlarm.AlarmTime.Minutes = currentTime.Minutes;
  72. // sAlarm.AlarmTime.Seconds = (currentTime.Seconds + 50) % 60;
  73. // sAlarm.Alarm = RTC_ALARM_A;
  74. //
  75. // HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD);
  76. //
  77. // /* 进入 STANDBY 模式 */
  78. // __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // 清除唤醒标志
  79. // HAL_PWR_EnterSTANDBYMode(); // MCU 进入 STANDBY
  80. //
  81. // // MCU 唤醒后会从 main() 重新开始运行
  82. // }