RTC_SLEEP.c 2.7 KB

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