找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3320|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

GD32F307開發(fā)板的RTC電子時(shí)鐘

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:776997 發(fā)表于 2020-11-26 01:01 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
本帖最后由 jinglixixi 于 2020-11-26 08:28 編輯

GD32307E-START開發(fā)板是具備RTC計(jì)時(shí)功能的,但它的RTC似乎并不是真正的RTC,后面大家從程序中就會(huì)發(fā)現(xiàn)端倪。

將串行通訊功能和RTC計(jì)時(shí)功能相結(jié)合,能快速地驗(yàn)證 RTC電子時(shí)鐘,見下圖所示。

此外,若為它配上一個(gè)OLED屏,那觀察起來就更方便了。


RTC電子時(shí)鐘


那該然后實(shí)現(xiàn)上面的功能的呢?

它會(huì)涉及到幾個(gè)關(guān)鍵函數(shù):


  1. void time_display(uint32_t timevar)
  2. {
  3.     uint32_t thh = 0, tmm = 0, tss = 0;
  4.     if(timevarp!=timevar)
  5.     {
  6.     /* compute  hours */
  7.     thh = timevar / 3600;
  8.     /* compute minutes */
  9.     tmm = (timevar % 3600) / 60;
  10.     /* compute seconds */
  11.     tss = (timevar % 3600) % 60;
  12.    printf(" Time: %0.2d:%0.2d:%0.2d\r\n", thh, tmm, tss);
  13.    timevarp=timevar;        
  14.     }
  15. }

復(fù)制代碼

前面我們已經(jīng)賣過關(guān)子了,你看它的RTC是沒有專門的寄存器來存放時(shí)、分、秒的時(shí)間值,而是通過timevar變量來解算出的。


  1. void time_show(void)
  2. {
  3.     printf("\n\r");
  4.         timedisplay = 1;
  5.         /* infinite loop */
  6.         while (1)
  7.         {
  8.         /* if 1s has paased */
  9.         if (timedisplay == 1)
  10.         {
  11.             /* display current time */
  12.             time_display(rtc_counter_get());
  13.         }
  14.     }
  15. }

復(fù)制代碼
實(shí)現(xiàn)RTC時(shí)鐘顯示功能的主程序?yàn)椋?/font>

  1. int main(void)
  2. {
  3.     /* configure systick */
  4.     systick_config();
  5.     /* configure EVAL_COM1 */
  6.     gd_eval_com_init(EVAL_COM1);
  7.     /* NVIC config */
  8.     nvic_configuration();
  9.     printf( "\r\nThis is a RTC demo...... \r\n" );
  10.     if (bkp_read_data(BKP_DATA_0) != 0xA5A5)
  11.     {
  12.         // backup data register value is not correct or not yet programmed
  13.         //(when the first time the program is executed)
  14.         printf("\r\nThis is a RTC demo!\r\n");
  15.         printf("\r\n\n RTC not yet configured....");
  16.         // RTC configuration
  17.         rtc_configuration();
  18.         printf("\r\n RTC configured....");
  19.         // adjust time by values entred by the user on the hyperterminal
  20.         time_adjust();
  21.         bkp_write_data(BKP_DATA_0, 0xA5A5);
  22.     }
  23.     // display time in infinite loop
  24.     time_show();
  25. }

復(fù)制代碼




評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表