找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2722|回复: 0
打印 上一主题 下一主题
收起左侧

GD32F307开发板的RTC电子时钟

[复制链接]
跳转到指定楼层
楼主
本帖最后由 jinglixixi 于 2020-11-26 08:28 编辑

GD32307E-START开发板是具备RTC计时功能的,但它的RTC似乎并不是真正的RTC,后面大家从程序中就会发现端倪。

将串行通讯功能和RTC计时功能相结合,能快速地验证 RTC电子时钟,见下图所示。

此外,若为它配上一个OLED屏,那观察起来就更方便了。


RTC电子时钟


那该然后实现上面的功能的呢?

它会涉及到几个关键函数:


  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. }

复制代码

前面我们已经卖过关子了,你看它的RTC是没有专门的寄存器来存放时、分、秒的时间值,而是通过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. }

复制代码
实现RTC时钟显示功能的主程序为:

  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. }

复制代码




评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表