/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
PUTCHAR_PROTOTYPE
{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
/* USER CODE BEGIN PTD */
RTC_DateTypeDef sdatestructureget;
RTC_TimeTypeDef stimestructureget;
uint8_t aShowTime[16] = "hh:ms:ss";
/* USER CODE END PTD */
/* USER CODE BEGIN PD */
static void RTC_TimeShow(uint8_t *showtime);
/* USER CODE END PD */
static void RTC_TimeShow(uint8_t *showtime)
{
/* Get the RTC current Time */
HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN);
/* Get the RTC current Date */
HAL_RTC_GetDate(&hrtc, &sdatestructureget, RTC_FORMAT_BIN);
/* Display time Format : hh:mm:ss */
sprintf((char *)showtime, "%02d:%02d:%02d", stimestructureget.Hours, stimestructureget.Minutes, stimestructureget.Seconds);
}
/* USER CODE BEGIN PD */
void Sys_Enter_Standby(void);
/* USER CODE END PD */
void Sys_Enter_Standby(void)
{
/* The Following Wakeup sequence is highly recommended prior to Standby mode entry
- Enable wakeup
- Clear wake up pin flag depending in edge detection & pin level.
- Enter the Standby mode.
*/
/* Enable WakeUp Pin PWR_WAKEUP_PIN2 connected to PC.13 */
HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN2_LOW);//上升沿触发
HAL_PWREx_EnableInternalWakeUpLine();
/* Clear all related wakeup flags*/
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
/* Enter the Standby mode */
//HAL_PWR_EnterSTANDBYMode();
printf("enter Shutdown Mode!");
HAL_PWREx_EnterSHUTDOWNMode();
/* USER CODE BEGIN 2 */
uint8_t sec=0;
if (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
{
/* Clear Standby flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
printf("wake up from standby!");
/* Check and Clear the Wakeup flag */
if (__HAL_PWR_GET_FLAG(PWR_FLAG_WUF2) != RESET)
{
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF2);
}
/* Wait that user release the User push-button */
while(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13) == GPIO_PIN_SET){}
}
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
RTC_TimeShow(aShowTime);
if(sec == 0)flag=0;
if(sec == 5)Sys_Enter_Standby();
if(sec!=stimestructureget.Seconds)
{
sec=stimestructureget.Seconds;
printf("%s",(char *)aShowTime);
if(flag) HAL_GPIO_TogglePin(LD4_GPIO_Port,LD4_Pin);
}
}
/* USER CODE END 3 */
}
/* USER CODE BEGIN Check_RTC_BKUP */
if (__HAL_RTC_GET_FLAG(&hrtc, RTC_FLAG_INITS) == 0x00u){}
else{return;}
/* USER CODE END Check_RTC_BKUP */
以上代码请添加于MX_RTC_Init(void)中