[N32WB031_STB开发板测评]+RTC计时与显示
<div class='showpostmsg'> 本帖最后由 jinglixixi 于 2023-5-9 23:58 编辑<p>N32WB031内置了RTC计时器,并具有日历处理功能,因此在OLED屏的配合下极易实现电子时钟的功能。</p>
<p>在使用例程的基础上,所用的关键函数为获取RTC计时值的函数RTC_GetTime()及OLED屏的数值显示函数OLED_ShowNum()。</p>
<p>其中OLED屏的数值显示函数为:</p>
<pre>
<code class="language-cpp">void OLED_ShowNum(uint8_t x,uint8_t y,uint32_t num,uint8_t len,uint8_t size2)
{
uint8_t t,temp;
uint8_t enshow=0;
for(t=0;t<len;t++)
{
temp=(num/oled_pow(10,len-t-1))%10;
if(enshow==0&&t<(len-1))
{
if(temp==0)
{
OLED_ShowChar(x+(size2/2)*t,y,' ',size2);
continue;
}
else enshow=1;
}
OLED_ShowChar(x+(size2/2)*t,y,temp+'0',size2);
}
}
</code></pre>
<p>相应的RTC计时值显示函数为:</p>
<pre>
<code class="language-cpp">void RTC_TimeShow(void)
{
RTC_GetTime(RTC_FORMAT_BIN, &RTC_TimeStructure);
(void)RTC->DATE;
OLED_ShowNum(20,4,RTC_TimeStructure.Hours,2,16);
OLED_ShowNum(44,4,RTC_TimeStructure.Minutes,2,16);
OLED_ShowNum(68,4,RTC_TimeStructure.Seconds,2,16);
}
</code></pre>
<p> 显示效果</p>
<p> </p>
<p>要实现上图的主函数为:</p>
<pre>
<code class="language-cpp">int main(void)
{
log_init();
log_info("\r\nRTC calendar demo\r\n");
RTC_DateAndTimeDefaultVale();
RTC_CLKSourceConfig(2);
RTC_PrescalerConfig();
log_info("RTC configured....");
RTC_ConfigInt(RTC_INT_WUT, DISABLE);
RTC_EnableWakeUp(DISABLE);
RTC_DateRegulate();
RTC_TimeRegulate();
TIM3_Configuration();
OLED_gpio();
OLED_Init();
OLED_Clear();
OLED_ShowString(20,0,"N32WB031",16);
OLED_ShowString(20,4,"::",16);
while(1);
}
</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>问题的核心是把这两个为获取RTC计时值的函数RTC_GetTime()及OLED屏的数值显示函数OLED_ShowNum()函数搞熟练,,,</p>
页:
[1]