2785 views|3 replies

1452

Posts

1

Resources
The OP
 

【AT32F421 Review】+RTC Electronic Clock [Copy link]

 

The AT32F421 is equipped with an RTC timer and is equipped with corresponding routines to assist in learning, use and functional verification.

The verification result of the routine ERTC_Calendar is shown in Figure 1.

Figure 1 RTC verification effect

In order to facilitate intuitive observation, the OLED screen display function introduced earlier can be combined with the RTC, and the display effect is shown in Figure 2.

Figure 2 Clock timing effect

The main program to achieve the timing effect shown in the figure is:

int main(void)
{
  NVIC_InitType NVIC_InitStructure;
   EXTI_InitType EXTI_InitStructure;
  int temp=0;
  AT32_Board_Init();
AT32_OLED_Init();
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"AT32F421",16);
OLED_ShowString(0,2,"RTC & OLED",16);
  if (ERTC_ReadBackupRegister(ERTC_BKP_DT0) != 0x32F1)
  {
   ERTC_Config();
   ERTC_TimeShow();
   ERTC_AlarmShow();
  }
   else
  {
   if (RCC_GetFlagStatus(RCC_FLAG_PORST) != RESET)
    {
      AT32_LEDn_ON(LED3);
    }
   else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
   {
      AT32_LEDn_ON(LED4);
    }
   RCC_APB1PeriphClockCmd(RCC_APB1PERIPH_PWR, ENABLE);
   PWR_BackupAccessCtrl(ENABLE);
   ERTC_WaitForSynchro();
   ERTC_ClearFlag(ERTC_FLAG_ALAF);
   EXTI_ClearIntPendingBit(EXTI_Line17);
   ERTC_TimeShow();
   ERTC_AlarmShow();
  }
  EXTI_ClearIntPendingBit(EXTI_Line17);
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_InitStructure.EXTI_LineEnable = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
 NVIC_InitStructure.NVIC_IRQChannel = ERTC_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
  OLED_Clear();
 OLED_ShowString(0,0,"20 - -",16);
 OLED_ShowString(0,2," : :",16);
  while (1)
  {
      ERTC_GetTimeValue(ERTC_Format_BIN, &ERTC_TimeStructure);
 ERTC_GetDateValue(ERTC_Format_BIN, &ERTC_DateStructure);
       if(temp != ERTC_TimeStructure.ERTC_Seconds)
      {
      temp = ERTC_TimeStructure.ERTC_Seconds;
       OLED_ShowNum(16,0,ERTC_DateStructure.ERTC_Year,2,16);
  OLED_ShowNum(40,0,ERTC_DateStructure.ERTC_Month,2,16);
  OLED_ShowNum(64,0,ERTC_DateStructure.ERTC_Date,2,16);
  OLED_ShowNum(0,2,ERTC_TimeStructure.ERTC_Hours,2,16);
  OLED_ShowNum(24,2,ERTC_TimeStructure.ERTC_Minutes,2,16);
  OLED_ShowNum(48,2,ERTC_TimeStructure.ERTC_Seconds,2,16);
 }
    }

}

This post is from Domestic Chip Exchange

Latest reply

Can you provide a demo zip file?  Details Published on 2023-9-10 22:46
 
 

6555

Posts

0

Resources
2
 

After power off and restart, is the RTC data lost?

This post is from Domestic Chip Exchange

Comments

Without a backup battery to support the RTC, it will definitely be lost  Details Published on 2021-4-27 09:16
 
 
 

1452

Posts

1

Resources
3
 
Jacktang posted on 2021-4-27 08:58 Is the RTC data lost after power failure and restart

Without a backup battery to support the RTC, it will definitely be lost

This post is from Domestic Chip Exchange
 
 
 

1

Posts

0

Resources
4
 

Can you provide a demo zip file?


This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

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