RTC_SLEEP.c 2.7 KB

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