【iCore1S 雙核心板_ARM】例程十一:RTC實時時鐘實驗——顯示時間和日期

XiaomaGee發表於2017-08-30

實驗現象:

 

核心程式碼:

int main(void)
{

  /* USER CODE BEGIN 1 */
        RTC_DateTypeDef sDate;
        RTC_TimeTypeDef sTime;
        uint8_t second_tmp = 0;
  /* USER CODE END 1 */

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

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

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

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_RTC_Init();
  MX_USART1_UART_Init();
  SystemClock_Config();

  /* USER CODE BEGIN 2 */
    LED_RED_ON;                                                                                             //ºìµÆ³£ÁÁ
    usart1.printf("\x0c");                                   //ÇåÆÁ    
    usart1.printf("\033[1;32;40m");                          //ÉèÖÃ×ÖÌåÖÕ¶ËΪÂÌÉ«
    usart1.printf("\r\n\r\nhello! I am iCore1S!\r\n\r\n\r\n");

  /* USER CODE END 2 */

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

  /* USER CODE BEGIN 3 */
      HAL_Delay(100);                                                                                 //¶ÁÈ¡RTCÈÕÆÚºÍʱ¼ä
        HAL_RTC_GetTime(&hrtc, &sTime, RTC_FORMAT_BIN);
        HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN);
        
        if(second_tmp != sTime.Seconds){                                           //µ±ÃëÊý¾ÝÓ뱸·Ý²»Ò»ÖÂʱ£¬ÏòÖն˴òӡʱ¼ä/ÈÕÆÚ

            usart1.printf("  %02d:%02d:%02d  ",sTime.Hours,sTime.Minutes,sTime.Seconds);
            usart1.printf("20%02d-%02d-%02d  \r",sDate.Year,sDate.Month,sDate.Date);\
            second_tmp = sTime.Seconds;                                   //ÃëÊý¾Ý±¸·Ý
        }

  }
  /* USER CODE END 3 */

}

原始碼下載連結:

連結:http://pan.baidu.com/s/1b1hxF4 密碼:pg08

 

相關文章