STM32日历读取,设置和输出
一、CubeMX建立STM32F103C8T6HAL库
1.RCC
2.RTC
3.USART
4.Clock Configuration
5.Project Manager
二、程序编写
1.mian.c
- 重定向fputc和函数
int fputc(int ch,FILE *f){
uint8_t temp[1]={ch};
HAL_UART_Transmit(&huart1,temp,1,2);
return ch;
}
- 在while中加入以下代码
printf("1");
/* USER CODE END WHILE */
/* Get the RTC current Time */
HAL_RTC_GetTime(&hrtc, &GetTime, RTC_FORMAT_BIN);
/* Get the RTC current Date */
HAL_RTC_GetDate(&hrtc, &GetData, RTC_FORMAT_BIN);
/* Display date Format : yy/mm/dd */
printf("%02d/%02d/%02d\r\n",2000 + GetData.Year, GetData.Month, GetData.Date);
/* Display time Format : hh:mm:ss */
printf("%02d:%02d:%02d\r\n",GetTime.Hours, GetTime.Minutes, GetTime.Seconds);
printf("\r\n");
HAL_Delay(1000);
- 勾选Use MicroLIB
三、效果实现
四、输出具体时间
要实现具体时间的输出我们就要在CubeMX中手动设置
五、效果实现
六、参考文章
https://blog.csdn.net/qq_45659777/article/details/121621521?spm=1001.2014.3001.5501