STM32L476VET6 RTC时钟日历(HAL库+CubeMX开发)(二)串口通讯

main函数

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_RTC_Init();
  MX_USART2_UART_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  /* USER CODE BEGIN 2 */
	DelayInit();
	GpioInit();
	LCD_ST7920_Init();
	LED_35V_CTL_L;//LCD受3.5v电源芯片控(使能)
	LCDClrDisplay();
	USART2_BUF_INIT(&rxbuf_struct);
	LOW_PWR_Init(LOW_PWR_COUNTDOWN);//1min

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
	  
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
        //不断获取新的Time和Date
	  	HAL_RTC_GetTime(&hrtc, &Time, RTC_FORMAT_BIN);
		HAL_RTC_GetDate(&hrtc, &Date, RTC_FORMAT_BIN);
		if(!low_pwr_struct.low_pwr_flag)//当不在休眠模式的时候才输出和显示
		{
			/* Display date Format : yy/mm/dd */
			printf("DATE: %02d/%02d/%02d\r\nWEEKDAY: %02d\r\n",2000 + Date.Year, Date.Month, Date.Date,Date.WeekDay);
			/* Display time Format : hh:mm:ss */
			printf("TIME: %02d:%02d:%02d\r\n",Time.Hours, Time.Minutes, Time.Seconds);
			printf("\r\n");
			LCD_Display();
		}
	  LED_TOGGLE();

//	  USART2_BUF_DEINIT(rxbuf_struct);
  }
  /* USER CODE END 3 */
}

USART2串口配置

//usart.h

/* USER CODE BEGIN Includes */
#include "sys.h"
#include "stdio.h"
/* USER CODE END Includes */

extern UART_HandleTypeDef huart2;

/* USER CODE BEGIN Private defines */
#define USART2_BUF_SIZE			20

typede
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值