1276 views|0 replies

1452

Posts

1

Resources
The OP
 

[Xiaohua HC32F448 Review] +RTC electronic clock [Copy link]

 

The HC32F448 is equipped with an RTC timer. This is a standard RTC, not some chips launched by manufacturers that claim to have RTC but are fake. It can only be called a quasi-RTC and the calendar function must be implemented through software.

Therefore, the function of an electronic clock can be easily realized by using the RTC on the chip. The effect of testing with the serial port is shown in Figure 1.

Figure 1 RTC test results

The function to set the RTC is:

static void RTC_CalendarConfig(void)
{
    stc_rtc_date_tstcRtcDate;
    stc_rtc_time_tstcRtcTime;
    stcRtcDate.u8Year    = 23U;
    stcRtcDate.u8Month   = RTC_MONTH_JULY;
    stcRtcDate.u8Day     = 28U;
    stcRtcDate.u8Weekday = RTC_WEEKDAY_WEDNESDAY;
    stcRtcTime.u8Hour   = 23U;
    stcRtcTime.u8Minute = 59U;
    stcRtcTime.u8Second = 55U;
    stcRtcTime.u8AmPm   = RTC_HOUR_12H_AM;
    if (LL_OK != RTC_SetDate(RTC_DATA_FMT_DEC, &stcRtcDate)) {
         DDL_Printf("Set Date failed!\r\n");
    }
    if (LL_OK != RTC_SetTime(RTC_DATA_FMT_DEC, &stcRtcTime)) {
         DDL_Printf("Set Time failed!\r\n");
    }
}

By cooperating with the OLED screen introduced above, the function of electronic clock can be realized. The main program is:

int32_t main(void)
{
    stc_rtc_date_tstcCurrentDate;
    stc_rtc_time_tstcCurrentTime;
    LL_PERIPH_WE(EXAMPLE_PERIPH_WE);
    BSP_CLK_Init();
    BSP_IO_Init();
    BSP_LED_Init();
	LED_Init();
    OLED_Init();
	OLED_Clear();
	OLED_ShowString(20,0,"HC32F448",16);
	OLED_ShowString(20,2,"RTC & OLED",16);
	OLED_ShowString(20,4,"  :  :",16);
	OLED_ShowString(20,6,"  -  -",16);
    DDL_PrintfInit(BSP_PRINTF_DEVICE, BSP_PRINTF_BAUDRATE, BSP_PRINTF_Preinit);
    RTC_Config();
    LL_PERIPH_WP(EXAMPLE_PERIPH_WP);
    for (;;)
    {
        if (1U == u8SecIntFlag) 
        {
             u8SecIntFlag = 0U;
             BSP_LED_Toggle(LED_RED);
             if (LL_OK == RTC_GetDate(RTC_DATA_FMT_DEC, &stcCurrentDate)) 
             {
                 if (LL_OK == RTC_GetTime(RTC_DATA_FMT_DEC, &stcCurrentTime)) 
                 {
					OLED_ShowNum(20,4,stcCurrentTime.u8Hour,2,16);
					OLED_ShowNum(44,4,stcCurrentTime.u8Minute,2,16);
					OLED_ShowNum(68,4,stcCurrentTime.u8Second,2,16);
					OLED_ShowNum(20,6,stcCurrentDate.u8Year,2,16);
					OLED_ShowNum(44,6,stcCurrentDate.u8Month,2,16);
					OLED_ShowNum(68,6,stcCurrentDate.u8Day,2,16);
                 } else {
                     DDL_Printf("Get time failed!\r\n");
                 }
              } else {
                     DDL_Printf("Get date failed!\r\n");
              }
        }
    }
}

After the program is compiled and downloaded, the test results are shown in Figure 2, indicating that the function is correct.

Figure 2 Electronic clock effect

This post is from Domestic Chip Exchange
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
MSP432 connects wifi module ESP8266 as server

The wifi module esp8266 is very easy to use. It can be connected to the microcontroller via uart, and it is very easy to ...

【DIY Creative LED V2】Complete production steps

This post was last edited by dcexpert on 2020-10-21 15:09 The production of V2 is much simpler than V1. If everything g ...

Teach you step by step: Use STM32F103 to drive ST7567 LCD screen

ST7567 is one of the driver chips for LCD screens. It is a single-chip dot matrix LCD driver that integrates an LCD c ...

Understand the fast charging protocols of major mobile phone manufacturers

This post was last edited by qwqwqw2088 on 2021-6-21 08:24 Fast charging has become a major battlefield for major mobil ...

15th Anniversary] EE DIY (Progress) -- Upper Computer UI Changes

This post was last edited by RCSN on 2021-7-12 18:00 For details of DIY projects, see this post The previous host com ...

[Flower carving hands-on] Interesting and fun music visualization series of small projects (06) --- dot matrix spectrum lamp

I suddenly had the urge to do a series of topics on sound visualization. This topic is a bit difficult and covers a wide ...

[Flower carving DIY] Interesting and fun music visualization series of small projects (15) - horizontal LED square tube lights

I had the urge to do a series of topics on sound visualization. This topic is a bit difficult and covers a wide range of ...

41 "Wanli" Raspberry Pi car - ROS learning (ROSBridge controls the little turtle)

This post was last edited by lb8820265 on 2022-11-3 22:29 Previously, we introduced how to control the turtle using t ...

Modelsim simulation problem

First picture: 710815 I searched online and found that I need to modify the environment variables. 710816 But there is n ...

[ACM32G103RCT6 development board evaluation] +ADC and NTC to achieve temperature detection

Temperature detection is inseparable from temperature sensors. In terms of temperature sensor types, they are mainly div ...

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