【平头哥RVB2601创意应用开发】+智能闹钟
本帖最后由 奇迹12 于 2022-5-17 19:02 编辑<p style="text-align:justify"><strong><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">一、作品简介</span></span></span></strong></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">显示当前时间</span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">设备能够通过ntp获取时间,并配置到RTC</span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">具有设置单个闹钟的功能</span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">闹钟可通过按下任意按键关闭</span></span></span></p>
<p style="margin-left:28px; text-align:justify"><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">主界面显示当前环境温度与湿度</span></span></span></p>
<p style="margin-left:28px; text-align:justify"></p>
<p> </p>
<p style="text-align:justify"><strong><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">二、系统框图</span></span></span></strong></p>
<p></p>
<p style="text-align:justify"><strong><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">三、各部分功能说明和解析</span></span></span></strong></p>
<p>1.RTC配置与时间读取</p>
<pre>
<code class="language-cpp">csi_rtc_t rtc;
void app_rtc_init(app_time_t *time)
{
ASSERT_INSPECT(csi_rtc_init(&rtc, 0));
ASSERT_INSPECT(csi_rtc_set_time(&rtc, time));
}
void app_get_time(app_time_t *time)
{
ASSERT_INSPECT(csi_rtc_get_time(&rtc, time));
time->tm_year += 1900;
time->tm_mon += 1;
}</code></pre>
<p> </p>
<p>2.主界面代码</p>
<p>裸机操作,通过操作显存显示,最后刷新到屏幕</p>
<pre>
<code class="language-cpp">void app_display_main(app_time_t app_time, int16_t temp, int16_t humi)
{
uint8_t date_x=24,date_y=10;
uint8_t time_x=32,time_y=26;
uint8_t interval = 8;
uint8_t temp_x=0,temp_y=45;
uint8_t humi_x=88,humi_y=45;
gui_Clear();
gui_ShowChar(date_x,date_y,app_time.tm_year/1000%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_year/100%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_year/10%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_year/1%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,'-',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_mon/10%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_mon/1%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,'-',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_mday/10%10+'0',16,1); date_x+=interval;
gui_ShowChar(date_x,date_y,app_time.tm_mday/1%10+'0',16,1); date_x+=interval;
gui_ShowChar(time_x,time_y,app_time.tm_hour/10%10+'0',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,app_time.tm_hour/1%10+'0',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,':',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,app_time.tm_min/10%10+'0',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,app_time.tm_min/1%10+'0',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,':',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,app_time.tm_sec/10%10+'0',16,1); time_x+=interval;
gui_ShowChar(time_x,time_y,app_time.tm_sec/1%10+'0',16,1); time_x+=interval;
gui_ShowChar(temp_x,temp_y,temp/100%10+'0',16,1); temp_x+=interval;
gui_ShowChar(temp_x,temp_y,temp/10%10+'0',16,1); temp_x+=interval;
gui_ShowChar(temp_x,temp_y,'.',16,1); temp_x+=4;
gui_ShowChar(temp_x,temp_y,temp/1%10+'0',16,1); temp_x+=interval;
gui_ShowChar(temp_x,temp_y-2,'o',12,1); temp_x+=6;
gui_ShowChar(temp_x,temp_y,'C',16,1); temp_x+=interval;
gui_ShowChar(humi_x,humi_y,humi/100%10+'0',16,1); humi_x+=interval;
gui_ShowChar(humi_x,humi_y,humi/10%10+'0',16,1); humi_x+=interval;
gui_ShowChar(humi_x,humi_y,'.',16,1); humi_x+=4;
gui_ShowChar(humi_x,humi_y,humi/1%10+'0',16,1); humi_x+=interval+3;
gui_ShowChar(humi_x,humi_y,'%',16,1); humi_x+=interval;
oled_refresh(OLED_GRAM);
}</code></pre>
<p> </p>
<p>3.读取DHT11</p>
<pre>
<code class="language-cpp">uint8_t dht11_readData(int16_t *Temp, int16_t *Humi)
{
uint8_t sta = 0;
uint8_t i;
uint8_t buf;
if (DHT11RstAndCheck()) //检测响应信号
{
for(i=0;i<5;i++)
{
buf<i>=DHT11ReadByte();
}
if(buf+buf+buf+buf == buf) //校验成功
{
uint8_t H_inte = buf; //湿度整数部分数据
uint8_t H_frac = buf; //湿度小数部分数据
uint8_t T_inte = buf; //温度整数部分数据
uint8_t T_frac = buf; //温度小数部分数据
printf("%d.%d %d.%d %d\n",buf,buf,buf,buf,buf);
*Humi = H_inte*10+H_frac;
*Temp = T_inte*10+T_frac;
}
sta = 0;
}
else //响应失败返回-1
{
*Humi = 0; //响应失败返回-1
*Temp = 0; //响应失败返回-1
sta = 1;
}
return sta;
}</i></code></pre>
<p> </p>
<p><i>4.播放声音</i></p>
<pre>
<code class="language-cpp">void player_voice()
{
char url;
snprintf(url, sizeof(url), "mem://addr=%u&size=%u", (uint32_t)&_welcome_mp3, _welcome_mp3_len);
player_play(get_player_demo(), url, 0);
}</code></pre>
<p> </p>
<p><i>5.按键检测与处理任务</i></p>
<pre>
<code class="language-cpp">static void key_task()
{
uint8_t key1_state = 0;
uint8_t key2_state = 0;
uint8_t key_time;
while(1)
{
if(key1_get() == 1)
{
aos_msleep(10);
if(key1_state == 0) key_time = 1000 / 10;
else key_time = 100 /10;
while(key1_get() == 1)
{
aos_msleep(10);
key_time--;
if(key_time == 0) break;
}
key1_state = 1;
}
else
{
key1_state = 0;
}
if(key2_get() == 1)
{
aos_msleep(10);
if(key2_state == 0) key_time = 1000 / 10;
else key_time = 100 /10;
while(key2_get() == 1)
{
aos_msleep(10);
key_time--;
if(key_time == 0) break;
}
key2_state = 1;
}
else
{
key2_state = 0;
}
if(key1_state == 1)
{
screen_state ++;
}
if(screen_state > 4) screen_state = 0;
if(key2_state == 1)
{
if(screen_state == 1)
alarm_clock.tm_hour++;
if(alarm_clock.tm_hour >= 24) alarm_clock.tm_hour = 0;
if(screen_state == 2)
alarm_clock.tm_min++;
if(alarm_clock.tm_min >= 60) alarm_clock.tm_min = 0;
if(screen_state == 3)
alarm_clock.tm_sec++;
if(alarm_clock.tm_sec >= 60) alarm_clock.tm_sec = 0;
if(screen_state == 4)
alarm_clock_state ++;
if(alarm_clock_state >= 2) alarm_clock_state = 0;
}
if((key1_state == 1 || key2_state == 1)&&player_flag == 1)
{
player_flag = 0;
}
aos_msleep(50);
}
}</code></pre>
<p><i> </i></p>
<p style="text-align:justify"><i><strong><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><span style="font-family:"微软雅黑","sans-serif"">四、作品源码</span></span></span></strong></i></p>
<p><i> </i></p>
<p><i> <a href="https://download.eeworld.com.cn/detail/%E5%A5%87%E8%BF%B912/623561" target="_blank">源代码</a></i></p>
<p><i> </i></p>
<p style="text-align:justify"><i><span style="font-size:16px;"><span style="font-family:"Times New Roman","serif""><b><span style="font-family:"微软雅黑","sans-serif"">五、视频<span style="font-family:"微软雅黑","sans-serif"">演示</span></span></b></span></span></i></p>
<p style="text-align:justify"><i> </i></p>
<p><i> </i>f4a31f943e2f31b4d84327eaa2dd1758</p>
<p><i> </i></p>
<p><i><b style="font-family: "Times New Roman", "serif"; font-size: 16px; text-align: justify;"><span style="font-family:"微软雅黑","sans-serif"">六、项目总结</span></b></i></p>
<p><i> 整体项目比较简单,论坛也有很多大神的资料参考,很顺利就完成了,总体还是很好的,就是CDK环境用起来怪怪的。</i></p>
<p><i>最后感谢论坛跟平头哥提供的这次机会。</i></p>
<p><i> </i></p>
各方面掌握不错了,恭喜完成作业! <p>奇迹,作品文档也附上</p>
<p>还有是否去平头哥同步和发邮件,按照下面的帖子说明,查缺补漏啊:<br />
</p>
<p>关于平头哥RVB2601作品提交说明 <a href="https://bbs.eeworld.com.cn/thread-1201527-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1201527-1-1.html</a></p>
页:
[1]