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