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

XiaomaGee發表於2017-08-21

實驗現象:

核心程式碼:

int main(void)
{
  /* USER CODE BEGIN 1 */
    RTC_TimeTypeDef sTime;
  RTC_DateTypeDef sDate;
    int second_bak = 0;
    
  /* 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_USART6_UART_Init();

  /* USER CODE BEGIN 2 */
    usart6.initialize(115200);                                                                                        //´®¿Ú²¨ÌØÉèÖÃ
    usart6.printf("\x0c");                                                                                              //ÇåÆÁ
    usart6.printf("\033[1;32;40m");                                       //ÉèÖÃÖÕ¶Ë×ÖÌåΪÂÌÉ«
    usart6.printf(" Hello, I am iCore4!\r\n");                                                        //´®¿ÚÐÅÏ¢Êä³ö 
    LED_GREEN_ON;
    
    //ÉèÖÃRTCÈÕÆÚºÍʱ¼ä
    my_rtc.set_date(17,8,11,5);
    my_rtc.set_time(17,43,20);
  /* 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_bak != sTime.Seconds){
            usart6.printf(" %02d:%02d:%02d  ",sTime.Hours,sTime.Minutes,sTime.Seconds);
            usart6.printf("20%02d-%02d-%02d  \r",sDate.Year,sDate.Month,sDate.Date);
            second_bak = sTime.Seconds;                
        }
  }
  /* USER CODE END 3 */

}

原始碼下載連結:

連結:http://pan.baidu.com/s/1pLJn3HT 密碼:gjwl

iCore4連結:

相關文章