標(biāo)題: ESK32-360開發(fā)板的RTC計時器 [打印本頁]

作者: jinglixixi    時間: 2020-8-3 09:40
標(biāo)題: ESK32-360開發(fā)板的RTC計時器
本帖最后由 jinglixixi 于 2020-8-3 09:44 編輯

1. RTC基本使用
在例程中,提供了RTC的實(shí)驗(yàn)示例,在串口的配合下可以設(shè)置RTC的初始數(shù)值,并通過串口來輸出RTC計時值,其運(yùn)行效果如圖1所示。

圖1 串口設(shè)置和顯示RTC計時值


2. RTC計時器
為了能直觀地來顯示RTC計時值,可通過TFT顯示屏來實(shí)現(xiàn),所用到的主要為數(shù)值顯示函數(shù)。
改造后的計時顯示函數(shù)為:
  1. void AP_Time_Show(void)
  2. {
  3.          AP_Time_Count(&CurTime);
  4.          LCD_ShowNum(Line6,22,CurTime.year,4);
  5.          LCD_CharDisplay(Line6,84, '-');
  6.          LCD_ShowNum(Line6,100,CurTime.month,2);
  7.          LCD_CharDisplay(Line6,132, '-');
  8.          LCD_ShowNum(Line6,148,CurTime.day,2);
  9.          
  10.          LCD_ShowNum(Line7,52,CurTime.hour,2);
  11.          LCD_CharDisplay(Line7,84, ':');
  12.          LCD_ShowNum(Line7,100,CurTime.minute,2);
  13.          LCD_CharDisplay(Line7, 132,':');     
  14.          LCD_ShowNum(Line7,148,CurTime.second,2);
  15. }
復(fù)制代碼

主程序的內(nèi)容為:
  1. int main(void)
  2. {
  3.   CKCU_PeripClockConfig_TypeDef CKCUClock = {{0}};
  4.   CKCUClock.Bit.BKP        = 1;
  5.   CKCU_PeripClockConfig(CKCUClock, ENABLE);
  6.   if(PWRCU_CheckReadyAccessed() != PWRCU_OK)
  7.   {
  8.    while (1);
  9.   }
  10.   HT32F_DVB_LEDInit(HT_LED1);
  11.   RETARGET_Configuration();
  12.   NVIC_EnableIRQ(RTC_IRQn);
  13.   if(PWRCU_GetFlagStatus() == PWRCU_FLAG_BAKPOR)
  14.   {
  15.     LCD_StringLineDisplay(Line5," Power On Reset occurred!");
  16.   }
  17.   LCD_Init();
  18.   LCD_Config();
  19.   LCD_BackColorSet(Black);
  20.   LCD_TextColorSet(Red);
  21.   LCD_StringLineDisplay(Line3," LCD_RTC TEST");
  22.   LCD_TextColorSet(Yellow);
  23.   
  24.   if(PWRCU_ReadBackupRegister((PWRCU_BAKREG_Enum) PWRCU_BAKREG_0_RTC_KEY) !=0xAA55A5A5)
  25.   {
  26.          LCD_StringLineDisplay(Line5, "RTC not yet configured!");
  27.          LCD_StringLineDisplay(Line6, "   -  -            ");
  28.          LCD_StringLineDisplay(Line7,"    :  : ");
  29.          RTC_Configuration();
  30.    
  31.    #if 1
  32.    AP_Time_Init(&DateTime);
  33.    #else
  34.    DateTime.year   = 2020;
  35.    DateTime.month  = 7;
  36.    DateTime.day    = 25;
  37.    DateTime.hour   = 22;
  38.    DateTime.minute = 5;
  39.    DateTime.second = 0;
  40.    #endif
  41.    
  42.    if (!AP_Time_Adjust(&DateTime))
  43.    {
  44.             LCD_StringLineDisplay(Line5, "Adjusttime error!");
  45.             while(1);
  46.     }
  47.     RTC_Cmd(ENABLE);
  48.     PWRCU_WriteBackupRegister((PWRCU_BAKREG_Enum)PWRCU_BAKREG_0_RTC_KEY, 0xAA55A5A5);
  49.   }
  50.    else
  51.   {
  52.                LCD_StringLineDisplay(Line5,"No need to configure RTC!");
  53.   }
  54.   LCD_TextColorSet(Yellow);
  55.   LCD_StringLineDisplay(Line5,"                    ");
  56.   while(1)
  57.   {
  58.     if (CK_SECOND_Flag)
  59.     {
  60.         CK_SECOND_Flag = 0;
  61.         AP_Time_Show();
  62.     }
  63.   }
  64. }

復(fù)制代碼

圖2  顯示RTC計時值

3. 時間設(shè)置與調(diào)整
  實(shí)現(xiàn)圖3所示的時間設(shè)置與調(diào)整函數(shù)為:
  1.   intf=1,n=0,m=23,c=0,a1=0,a2=0,a3=0;
  2.   while(f)
  3.   {
  4.    TmpStatus = GPIO_ReadInBit(HT_GPIOC, GPIO_PIN_15);
  5.    GPIO_WriteOutBits(HT_GPIOD, GPIO_PIN_0, !TmpStatus);  // !滅
  6.    if(TmpStatus) n++;    //  増值
  7.    if(n>m)n=0;
  8.    
  9.    TmpStatus = GPIO_ReadInBit(HT_GPIOD, GPIO_PIN_1);
  10.    GPIO_WriteOutBits(HT_GPIOD, GPIO_PIN_2, TmpStatus);  // 亮
  11.     if(TmpStatus==0)     //  切換
  12.     {
  13.        c++;
  14.        if(c>2) c=0;
  15.        if(c==0) m=23;
  16.        if(c==1) m=59;
  17.        if(c==2) m=59;
  18.     }
  19.     TmpStatus = GPIO_ReadInBit(HT_GPIOB,GPIO_PIN_9);
  20.     GPIO_WriteOutBits(HT_GPIOB, GPIO_PIN_6,TmpStatus);  // 亮
  21.     if(TmpStatus==0)f=0;   // 退出
  22.          
  23.    if(c==0)a1=n;
  24.    if(c==1) a2=n;
  25.    if(c==2) a3=n;
  26.    LCD_ShowNum(Line7,52,a1,2);
  27.    LCD_CharDisplay(Line7,84, ':');
  28.    LCD_ShowNum(Line7,100,a2,2);
  29.    LCD_CharDisplay(Line7, 132,':');
  30.    LCD_ShowNum(Line7,148,a3,2);
  31.    delay(300);
  32. }
復(fù)制代碼

圖3 數(shù)據(jù)設(shè)置與調(diào)整


在數(shù)據(jù)設(shè)置時,以Wakeup鍵來調(diào)整數(shù)值的大小,以Key1來切換設(shè)置項(xiàng)(確定是時、分、秒),以Key2來確認(rèn)設(shè)置操作。


作者: jinglixixi    時間: 2020-8-4 08:44
感謝鼓勵。!




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1