本帖最后由 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屏,那觀察起來就更方便了。
1.jpg (40.03 KB, 下載次數(shù): 66)
下載附件
2020-11-26 00:58 上傳
RTC電子時(shí)鐘
那該然后實(shí)現(xiàn)上面的功能的呢? 它會(huì)涉及到幾個(gè)關(guān)鍵函數(shù):
- void time_display(uint32_t timevar)
- {
- uint32_t thh = 0, tmm = 0, tss = 0;
- if(timevarp!=timevar)
- {
- /* compute hours */
- thh = timevar / 3600;
- /* compute minutes */
- tmm = (timevar % 3600) / 60;
- /* compute seconds */
- tss = (timevar % 3600) % 60;
- printf(" Time: %0.2d:%0.2d:%0.2d\r\n", thh, tmm, tss);
- timevarp=timevar;
- }
- }
復(fù)制代碼
前面我們已經(jīng)賣過關(guān)子了,你看它的RTC是沒有專門的寄存器來存放時(shí)、分、秒的時(shí)間值,而是通過timevar變量來解算出的。
- void time_show(void)
- {
- printf("\n\r");
- timedisplay = 1;
- /* infinite loop */
- while (1)
- {
- /* if 1s has paased */
- if (timedisplay == 1)
- {
- /* display current time */
- time_display(rtc_counter_get());
- }
- }
- }
復(fù)制代碼 實(shí)現(xiàn)RTC時(shí)鐘顯示功能的主程序?yàn)椋?/font>
- int main(void)
- {
- /* configure systick */
- systick_config();
- /* configure EVAL_COM1 */
- gd_eval_com_init(EVAL_COM1);
- /* NVIC config */
- nvic_configuration();
- printf( "\r\nThis is a RTC demo...... \r\n" );
- if (bkp_read_data(BKP_DATA_0) != 0xA5A5)
- {
- // backup data register value is not correct or not yet programmed
- //(when the first time the program is executed)
- printf("\r\nThis is a RTC demo!\r\n");
- printf("\r\n\n RTC not yet configured....");
- // RTC configuration
- rtc_configuration();
- printf("\r\n RTC configured....");
- // adjust time by values entred by the user on the hyperterminal
- time_adjust();
- bkp_write_data(BKP_DATA_0, 0xA5A5);
- }
- // display time in infinite loop
- time_show();
- }
復(fù)制代碼
|