【AT32F421测评】+RTC电子时钟
<p>在AT32F421的内部配置有RTC计时器,且为其配备了相应的例程来辅助学习、使用及功能验证。</p><p>对例程ERTC_Calendar的验证效果,如图1所示。</p>
<p></p>
<p>图1 RTC验证效果</p>
<p> </p>
<p>为了便于直观的观察,可以将前面介绍过的OLED屏显示功能与RTC结合起来使用,其显示效果如图2所示。</p>
<p></p>
<p>图2时钟计时效果</p>
<p> </p>
<p>实现图示计时效果的主程序为:</p>
<pre>
<code class="language-cpp">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);
}
}
}</code></pre>
<p> </p>
<p>断电重启之后,RTC的数据有没有丢失</p>
Jacktang 发表于 2021-4-27 08:58
断电重启之后,RTC的数据有没有丢失
<p>没有后备电池支持RTC的话肯定会丢失</p>
<p>能否给个demo压缩包?</p><br/>
页:
[1]