2153 views|2 replies

1452

Posts

1

Resources
The OP
 

【GD32307E-START】+RTC electronic clock [Copy link]

 This post was last edited by jinglixixi on 2020-11-26 21:02

The GD32307E-START development board has the RTC timing function, but its RTC does not seem to be a real RTC. You will find the clue from the program later.

Combining the serial communication function with the RTC timing function can quickly verify the RTC electronic clock, as shown in the figure below.

In addition, if it is equipped with an OLED screen, it will be more convenient to observe.

RTC electronic clock

So how do we achieve the above functions?

It involves several key functions:

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

We have already given you a sneak peek before. You see, its RTC does not have dedicated registers to store the time values of hours, minutes, and seconds. Instead, they are calculated through the timevar variable.

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());
        }
    }
}
uint32_t time_regulate(void)
{
    uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF;
    printf("\r\n==============Time Settings=====================================");
    /*printf("\r\n  Please Set Hours");
    while (tmp_hh == 0xFF)
    {
        tmp_hh = usart_scanf(23);
    }
    printf(":  %d", tmp_hh);
    printf("\r\n  Please Set Minutes");
    while (tmp_mm == 0xFF)
    {
        tmp_mm = usart_scanf(59);
    }
    printf(":  %d", tmp_mm);
    printf("\r\n  Please Set Seconds");
    while (tmp_ss == 0xFF)
    {
        tmp_ss = usart_scanf(59);
    }
    printf(":  %d", tmp_ss);*/
	tmp_hh = 23;
    tmp_mm = 59;
	tmp_ss = 59;
	printf(":  %d", tmp_hh);
	printf(":  %d", tmp_mm);
	printf(":  %d", tmp_ss);
    /* return the value  store in RTC counter register */
    return((tmp_hh*3600 + tmp_mm*60 + tmp_ss));
}

The main program to realize the RTC clock display function is:

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();
}

This post is from Domestic Chip Exchange

Latest reply

I guess so. The integer value corresponds to the hours, minutes and seconds.   Details Published on 2020-11-26 18:42
 
 

7422

Posts

2

Resources
2
 

I guess so. The integer value corresponds to the hours, minutes and seconds.

This post is from Domestic Chip Exchange

Comments

Different people have different opinions!  Details Published on 2020-11-26 21:05
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

1452

Posts

1

Resources
3
 
freebsder posted on 2020-11-26 18:42 I guess so. The integer value corresponds to the hour, minute, and second.

Different people have different opinions!

This post is from Domestic Chip Exchange
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list