RTC_SLEEP.c 2.8 KB

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