1.rtc.h
#ifndef _RTC_H
#define _RTC_H
#include "stm32f1xx_hal.h"
#include "stm32f1xx_hal_rtc.h"
void MX_RTC_Init(void);
#endif
2.rtc.c
#include "rtc.h"
/* USER CODE BEGIN 0 */
RTC_HandleTypeDef hrtc;
/* USER CODE END 0 */
extern uint16_t NetYear1;
extern uint8_t NetMonth1,NetDay1,NetHour1,NetMinute1,NetSecond1;
/* RTC init function */
RTC_DateTypeDef DateToUpdate = {0};
void MX_RTC_Init(void)
{
RTC_TimeTypeDef time; //时间结构体参数
RTC_TimeTypeDef sTime = {0};
/** Initialize RTC Only
*/
hrtc.Instance = RTC;
hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
if (HAL_RTC_Init(&hrtc) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date
*/
//修改初始时间
sTime.Hours = NetHo