【AT32WB415测评】RTC电子时钟
<div class='showpostmsg'><p>在AT32WB415片内配有所谓的ERTC,并提供了相应的例程以供测试,其测试效果如图1所示。</p><p > 图1 运行效果</p>
<p >在例程中,除了RTC的初始化处理,在使用中最为关注的则是函数ertc_config()。因为在未配置后备电源的情况下,打开电源就会时RTC停止工作。使用在初次使用或开机后就需对RTC的初始值加以设置或调整。</p>
<p >所做的处理则恰恰是在ertc_config()中,其内容如下:</p>
<pre>
<code class="language-cpp">void ertc_config(void)
{
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
pwc_battery_powered_domain_access(TRUE);
crm_battery_powered_domain_reset(TRUE);
crm_battery_powered_domain_reset(FALSE);
crm_clock_source_enable(CRM_CLOCK_SOURCE_LEXT, TRUE);
while(crm_flag_get(CRM_LEXT_STABLE_FLAG) == RESET);
crm_ertc_clock_select(CRM_ERTC_CLOCK_LEXT);
ertc_clk_div_b = 255;
ertc_clk_div_a = 127;
crm_ertc_clock_enable(TRUE);
ertc_reset();
ertc_wait_update();
ertc_divider_set(ertc_clk_div_a, ertc_clk_div_b);
ertc_hour_mode_set(ERTC_HOUR_MODE_24);
/* set date: 2022-08-08 */
ertc_date_set(22, 8, 8, 1);
/* set time: 8:30:00 */
ertc_time_set(8, 30, 0, ERTC_AM);
ertc_interrupt_enable(ERTC_ALA_INT, TRUE);
ertc_flag_clear(ERTC_ALAF_FLAG);
ertc_bpr_data_write(ERTC_DT1, 0x1234);
}</code></pre>
<p >当然,若是配合按键的使用则可以动态来调整时间值。</p>
<p >在了解这些之后,就可利用前面介绍的TFT屏来实现电子时钟的显示功能,其显示效果如图2所示。</p>
<p > 图2 显示效果</p>
<p >实现显示效果的主程序如下:</p>
<pre>
<code class="language-cpp">int main(void)
{
exint_init_type exint_init_struct;
ertc_time_type time;
uint32_t temp = 0;
system_clock_config();
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
at32_board_init();
crm_periph_clock_enable(CRM_PWC_PERIPH_CLOCK, TRUE);
pwc_battery_powered_domain_access(TRUE);
if (ertc_bpr_data_read(ERTC_DT1) != 0x1234)
{
ertc_config();
}
else
{
ertc_wait_update();
ertc_flag_clear(ERTC_ALAF_FLAG);
exint_flag_clear(EXINT_LINE_17);
}
exint_default_para_init(&exint_init_struct);
exint_init_struct.line_enable = TRUE;
exint_init_struct.line_mode = EXINT_LINE_INTERRUPUT;
exint_init_struct.line_select = EXINT_LINE_17;
exint_init_struct.line_polarity = EXINT_TRIGGER_RISING_EDGE;
exint_init(&exint_init_struct);
nvic_irq_enable(ERTCAlarm_IRQn, 0, 1);
app_tft_init();
tft_Init();
LCD_Clear(RED);
LCD_Fill(0,0,239,50,WHITE);
show_tb(60,0,0);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
BACK_COLOR=RED;
POINT_COLOR=YELLOW;
LCD_Fill(0,287,239,319,WHITE);
BACK_COLOR=WHITE;
POINT_COLOR=RED;
LCD_ShowString(60,294,"BY: jinglixixi");
LCD_ShowString(80,16," : : ");
LCD_ShowString(152,16," - - ");
while(1)
{
ertc_calendar_get(&time);
if(temp != time.sec)
{
temp = time.sec;
delay_us(40);
LCD_Show2Num(152,16,time.year,2);
LCD_Show2Num(176,16,time.month,2);
LCD_Show2Num(200,16,time.day,2);
LCD_Show2Num(80,16,time.hour,2);
LCD_Show2Num(104,16,time.min,2);
LCD_Show2Num(128,16,time.sec,2);
}
}
}</code></pre>
<p> </p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>搞个备电放上去,或者接个大电容,要不每次开机都得重新设置,可以弄个电子秒表,不弄设置时间了</p> 秦天qintian0303 发表于 2022-8-15 14:02
搞个备电放上去,或者接个大电容,要不每次开机都得重新设置,可以弄个电子秒表,不弄设置时间了
<p>有道理!!!</p>
大佬的帖子,都是让人耳目一新的感觉,向大佬学习! lugl4313820 发表于 2022-8-17 21:31
大佬的帖子,都是让人耳目一新的感觉,向大佬学习!
<p><img height="48" src="https://bbs.eeworld.com.cn/static/editor/plugins/hkemoji/sticker/facebook/handshake.gif" width="48" /></p>
页:
[1]