描述
<div class="document">
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">注:* 为必填项</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong><span style="color: #0093e6;">请在报名阶段填写 ↓</span></strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">* 1、项目功能介绍</h3>
<hr class="horizontal-splitline normal-bold-2">
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="color: #95a5a6; font-size: 14px;">请输入内容…</span></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 本作品是一款放置在家中的智能空调伴侣,旨在使用户家中传统的空调实现智能控制。智能伴侣以瑞萨R7FA2E1A72DFL作为主控,利用温湿度传感器单元、WiFi数据传输单元、红外收发单元、语音单元、LCD显示单元等进行智能控制,实现了室内温湿度采集、实时天气预报、空调工作状态设置、语音识别、语音播报、LCD显示等功能。产品具体特性如下:</p>
<ul>
<ul>
<li>USB接口,5V,1A供电</li>
<li>2.4寸LCD屏显示功能,显示室内温湿度以及室外天气情况</li>
<li>实时天气预报功能,每半小时更新一次室外天气</li>
</ul>
</ul>
<ul>
<ul>
<li>室内温湿度采集功能,湿度精度±2%,温度精度±0.5℃</li>
<li>云端功能设置,可通过微信小程序对空调工作状态进行远程设置</li>
<li>语音识别功能,可识别唤醒词、天气预报、室内湿度、室内温度、空调温度增减等关键词,并进行相应设置</li>
<li>语音播报功能,可播报当前室内温湿度以及天气情况</li>
</ul>
</ul>
<ul>
<ul>
<li>更多特性演示可以参考视频</li>
</ul>
</ul>
<p>本项目硬件部分100%使用立创EDA进行设计。</p>
<p>本项目软件、硬件完全开源,可以浏览、下载本项目资源,或在此基础上进行二次开发,但是禁止未授权的商用。</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">*2、项目属性</h3>
<hr class="horizontal-splitline normal-bold-2">本项目为首次公开,为本人原创项目。项目未曾在别的比赛中获奖。<br>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">* 3、开源协议</h3>
<hr class="horizontal-splitline normal-bold-2">
<ol style="line-height: 1.8;">
<li class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt pap-hanging-indent-1.6em" style="line-height: 1.8;">该项目开源协议使用GPL3.0</li>
</ol>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">*4、硬件部分</h3>
<p><strong>系统整体方案</strong></p>
<p> 本作品是基于瑞萨R7FA2E1A72DFL微控制器作为主控制器。整个系统分为7个单元,分别为供电单元、主控单元、传感器采集单元、WiFi数据传输单元、语音处理单元、显示单元以及控制输出单元。具体方案框图如下所示:</p>
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/pullimage/Uy40JlWmZ5LRhbSl6gUIsF1YNZNXTfVJMLmWds2f.png" alt="" width="555" height="243"></p>
<p>各单元详细介绍如下:</p>
<p><strong>(1)供电单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/C7G8p5piVDIkJbrkn2aqVn7MLkPu5NcZONUToYfE.png" alt=""></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 如上原理图所示,供电单元采用micro usb作为供电接口输入5V电压,采用AMS1117-3.3 LOD作为5V转3.3V电源使用。由于该USB接口为常用电源插拔口,为了安全增加USB专用ESD芯片USBLC6-2P6,防止插拔过程中产生静电造成接口损伤;USB转串口通讯部分放到控制输出单元详细说明。</p>
<p><strong>(2)主控单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/Dtxq67pGwWd3DsCPDHlzPpL4bUk1WmfhoaT8eYgq.png" alt="" width="678" height="391"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 主控单元由上图所示,程序下载调试接口使用SWD口;芯片子时钟配置为32.768K用于RTC定时使用;芯片工作模式选择接口默认设置为高电平,为单芯片模式;芯片复位电路上增加续流二极管,可以将复位线上电容的电压快速泄放到电源上;</p>
<p><strong>(3)传感器采集单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/ttugqBGl4x1v3OMBSi7onGaidN7HLxvWX3AM6tCt.png" alt="" width="724" height="295"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 传感器采集单元如上图所示,DHT11主要用于室内温湿度采集,如果传感器和主控芯片之间通讯距离过远导致误码,可以适当减小R20,延长通讯距离;NTC10K主要用于不采集湿度只采集温度场景下,降低成本使用;</p>
<p><strong>(4)WiFi数据传输单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/ZrjgYFM4SvzBVqoBFb2ZBRR75Kh2TfQHoxFqUCAW.png" alt="" width="662" height="412"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> WiFi数据传输单元如上图所示,此WiFi模组采用乐鑫ESP8266模块,按键SW3用于下载WiFi程序使用,WiFi下载时,IO0=0,再按下SW2复位后才可进入下载模式。WiFi供电需要保证3.3V,0.5A,在WiFi进入smart config模式时峰值电流可能达到500mA左右。WiFi串口0连接主控芯片串口1,由于有时WiFi需要单独测试使用,所以在WiFi与主芯片连接串口之间增加了跳线帽,方便测试使用。</p>
<p><strong>(5)语音处理单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/njGgXDqfBcH3TG2mRlf8HvEJlz221T8AHklJRfh4.png" alt="" width="672" height="383"> 语音处理单元如上图所示,5V供电,保证0.5A供电电流,由于喇叭工作时电流波动较大,所以电源处要增加电容。注意喇叭和mic差分走线,PCB上最好对这两对线做包地处理,减少音频信号传输干扰。在mic和喇叭接口处增加双向TVS,防止ESD干扰,注意TVS一定选取寄生电容小的,防止对音频产生干扰。H4音频模组烧录接口,烧录时SW5需要按下。</p>
<p><strong>(6)显示单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/jORan11EQ709eAe4mQkTvEZJBnrykUPyu4oJGHT7.png" alt="" width="682" height="405"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 显示单元如上图所示,10Pin SPI通讯2.4寸LCD屏,LCD主控芯片为ST7789V2。R15、R14、R16为LCD背光限流使用。</p>
<p><strong>(7)控制输出单元:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 原理图如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/7Ow6qxIE5f9Nt4VjE8kO1bt3hyFLWBUqN7r5DCNP.png" alt="" width="1120" height="517"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> 控制输出单元如上图所示,分为三部分,红外收发、通讯接口、单按键开关。红外接收单元用于接收市面上红外遥控器发送的编码,发送单元用于发送空调控制编码,二者底层驱动皆采用NEC协议。USB接口连接CH340实现USB转串分别用于与主芯片打印串口连接和与WiFi串口0连接,具体连接哪一个可以使用SW4进行选择,SW4抬起连接WiFi串口,SW4按下连接主控芯片串口2。单按键开关工作原理在原理图上已经标明,通过两个GPIO可以实现整个设备的开启关闭,注意此电路只能实现延迟关闭不能实现延迟开启。</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong>总原理图如下所示:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong><img src="//image.lceda.cn/pullimage/W9za3QuTGxfSUubaGDYf1Ezwf8cAN1cXKYBOJoDC.png" alt="" width="1655" height="1170">PCB如下所示:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong><img src="//image.lceda.cn/pullimage/HLukybcWJ85hErlU33ngSuoD8R7VnrqBdtxPUPNs.png" alt="" width="818" height="708"><img src="//image.lceda.cn/pullimage/H9cCEgDjJcsrH265lMDUbKWJRYIFwFSklv768HFJ.png" alt="" width="721" height="728"></strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong>实物图如下所示:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong><img src="//image.lceda.cn/pullimage/GwPp0gtEoCzNGcYrBelWLct1wHB6RswKgFKR8u6R.jpeg" alt="" width="721" height="541"><img src="//image.lceda.cn/pullimage/MBOXEwjlGdK7p7opEZIEyk3Qg7NUNhwA820ED7XW.jpeg" alt="" width="723" height="542"></strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong><img src="//image.lceda.cn/pullimage/jQYkRfeDB1fDVPwh56A1m1AXE8GcsTBTbsKfoOBN.jpeg" alt="" width="724" height="965"></strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong>如上图所示:PCB设计时注意项如下:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">1、WiFi模组天线位置将PCB切除,且WiFi天线周围做净空处理,防止对WiFi信号产生影响;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">2、语音模块的喇叭还有mic注意差分走线,且走线包地良好;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">3、晶振附近的地保证良好,防止EMI;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">4、SPI线注意等长;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">5、电源线注意粗细合理,按照10mil最大500mA设计;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">6、退耦电容放在芯片电源引脚附近,越近越好。ESD器件放在干扰源传输的入口处;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">7、PCB板的接口和安装孔布局合理,可能产生互相干扰的器件分开放置;</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">8、后续可能需要进行调试的信号PCB添加测试点;</p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">*5、软件部分</h3>
<hr class="horizontal-splitline normal-bold-2">
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong>一、程序简介</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong> WiFi程序:<a href="https://github.com/caiyongsheng-designer/EST_TEST.git" target="_blank">https://github.com/caiyongsheng-designer/EST_TEST.git</a></strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong> 主控MCU程序:<a href="https://github.com/caiyongsheng-designer/Intelligent-air-conditioner-box.git" target="_blank">https://github.com/caiyongsheng-designer/Intelligent-air-conditioner-box.git</a></strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong>(1)主控MCU程序设计:</strong></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong> </strong> 主控芯片程序设计使用时间片轮转法,时间片周期为100ms,该周期使用滴答定时器中断来触发。</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">代码结构如下:</p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/zi526s0fYoOEMrdOTOS61GsjKyYD34s1hylkjEG5.png" alt="" width="802" height="742"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">源码运行流程如下:</p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p><img src="//image.lceda.cn/pullimage/vXUjjpKhDB9Co56LQveMppHGEpZu0FMqUJrs8Tqd.png" alt="" width="1144" height="751"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 16px;"><strong>(2)WiFi程序设计:</strong></span></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><strong> <span style="font-size: 16px;"> </span></strong><span style="font-size: 16px;"> WiFi程序设计基于乐鑫ESP8266_RTOS_SDK开源代码进行设计。</span></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 16px;">代码结构如下:</span><span style="font-size: 16px;"> <img src="//image.lceda.cn/pullimage/WnuWnd0Z7tu03iS8zU5RlbY62JZEehF6ZInG5jTw.png" alt="" width="654" height="682"></span></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 16px;">源码运行流程如下:</span></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p><img src="//image.lceda.cn/pullimage/jdbgg7nY1YFSspbQVPFMC1cAQdiuDAqg00447IsW.png" alt="" width="1002" height="757"></p>
</div>
</div>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size: 16px;"><strong>二、具体实现方法介绍</strong></span></p>
<p><span style="font-size: 16px;"><strong>2.1 MCU部分介绍</strong></span></p>
<p><span style="font-size: 16px;"><strong>2.1.1</strong></span><span style="font-size: 16px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;">时间片轮询法具体程序架构如下:</span></p>
</div>
</div>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">Step1、参数初始化:</p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p><span style="color: #3f7f5f;">// 初始化任务结构</span></p>
<p><span style="color: #7f0055; font-weight: bold;">typedef</span><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">struct</span><span style="color: #000000;"> </span><span style="color: #005032;">_TASK_COMPONENTS</span></p>
<p><span style="color: #000000;">{</span></p>
<p><span style="color: #005032;"> uint8_t</span><span style="color: #000000;"> </span><span style="color: #0000c0;">Run</span><span style="color: #000000;">; </span><span style="color: #3f7f5f;">// 程序运行标记:0-不运行,1运行</span></p>
<p><span style="color: #005032;"> uint8_t</span><span style="color: #000000;"> </span><span style="color: #0000c0;">Timer</span><span style="color: #000000;">; </span><span style="color: #3f7f5f;">// 起始计时器</span></p>
<p><span style="color: #005032;"> uint8_t</span><span style="color: #000000;"> </span><span style="color: #0000c0;">ItvTime</span><span style="color: #000000;">; </span><span style="color: #3f7f5f;">// 任务运行间隔时间【AKA计时器初始值值】</span></p>
<p><span style="color: #7f0055; font-weight: bold;"> void</span><span style="color: #000000;"> (*</span><span style="color: #0000c0;">TaskHook</span><span style="color: #000000;">)(</span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;">); </span><span style="color: #3f7f5f;">// 要运行的任务函数,注意该函数不得传参</span></p>
<p><span style="color: #000000;">} </span><span style="color: #005032;">TASK_COMPONENTS</span><span style="color: #000000;">; </span><span style="color: #3f7f5f;">// 任务定义</span></p>
<p><span style="color: #7f0055; font-weight: bold;">static</span><span style="color: #000000;"> </span><span style="color: #005032;">TASK_COMPONENTS</span><span style="color: #000000;"> TaskComps[] =</span></p>
<p><span style="color: #000000;">{</span></p>
<p><span style="color: #000000;"> {0, 2, 2, WiFi_Uart_Receive_All}, </span><span style="color: #3f7f5f;">// 间隔200MS运行一次,读WiFi串口数据</span></p>
<p><span style="color: #000000;"> {0, 3, 3, ir_receive_data_output}, </span><span style="color: #3f7f5f;">// 间隔300MS读一下红外接收是否有数据</span></p>
<p><span style="color: #000000;"> {0, 5, 5, WiFi_data_Upload}, </span><span style="color: #3f7f5f;">// 间隔500ms比较WiFi上传数据变化,变化则上报</span></p>
<p><span style="color: #000000;"> {0, 10, 10, Read_Temperature_Display}, </span><span style="color: #3f7f5f;">// 间隔1S运行一次,温度测量</span></p>
<p><span style="color: #000000;"> {0, 20, 20, rtc_minute_30_read}, </span><span style="color: #3f7f5f;">// 间隔2S,读RTC,间隔30Min获取实时天气并读取室内湿度</span></p>
<p><span style="color: #000000;"> {0, 50, 50,Wifi_state_inquire}, </span><span style="color: #3f7f5f;">// 间隔5S,检查WiFi状态</span></p>
<p><span style="color: #000000;"> {0, 100,100,WiFi_data_Upload_Timing_Report}</span><span style="color: #3f7f5f;">//间隔10S进行当前设备状态上报</span></p>
<p><span style="color: #000000;"> };</span></p>
<p><span style="color: #7f0055; font-weight: bold;">typedef</span><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">enum</span><span style="color: #000000;"> _TASK_LIST</span></p>
<p><span style="color: #000000;">{</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_WiFi_Uart_Receive_All</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_ir_receive_data_output</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_WiFi_data_Upload</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_Read_Temperature_Display</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_rtc_minute_30_read</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_GET_Wifi_State</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASK_WiFi_data_Upload_Timing_Report</span><span style="color: #000000;">,</span></p>
<p><span style="color: #0000c0; font-style: italic;"> TASKS_MAX</span><span style="color: #000000;"> </span><span style="color: #3f7f5f;">// 总的可供分配的定时任务数目</span></p>
<p><span style="color: #000000;">} </span><span style="color: #005032;">TASK_LIST</span><span style="color: #000000;">;</span></p>
</div>
</div>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">Step2、对滴答定时器开启初始化</p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p><span style="color: #3f5fbf;">/**</span></p>
<p><span style="color: #3f5fbf;"> * </span><span style="color: #7f9fbf;">@brief</span><span style="color: #3f5fbf;"> 启动系统滴答计时器 SysTick</span></p>
<p><span style="color: #3f5fbf;"> * </span><span style="color: #7f9fbf;">@param</span><span style="color: #3f5fbf;"> IT_frequency: 滴答计时器每秒的中断次数</span></p>
<p><span style="color: #3f5fbf;"> * </span><span style="color: #7f9fbf;">@retval</span><span style="color: #3f5fbf;"> 无</span></p>
<p><span style="color: #3f5fbf;"> */</span></p>
<p><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;"> </span><span style="color: #000000; font-weight: bold;">SysTick_Init</span><span style="color: #000000;">(</span><span style="color: #005032;">uint32_t</span><span style="color: #000000;"> IT_frequency)</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #000000;"> </span><span style="color: #3f7f5f;">/* SystemCoreClock在这里默认为48M</span></p>
<p><span style="color: #3f7f5f;"> * SystemCoreClock / 1000 1ms中断一次</span></p>
<p><span style="color: #3f7f5f;"> * SystemCoreClock / 100000 10us中断一次</span></p>
<p><span style="color: #3f7f5f;"> * SystemCoreClock / 1000000 1us中断一次</span></p>
<p><span style="color: #3f7f5f;"> */</span></p>
<p><span style="color: #000000;"> IT_Period = </span><span style="color: #000000; background-color: #d4d4d4;">SystemCoreClock</span><span style="color: #000000;"> / IT_frequency;</span></p>
<p><span style="color: #000000;"> </span><span style="color: #005032;">uint32_t</span><span style="color: #000000;"> err = SysTick_Config (IT_Period);</span></p>
<p><span style="color: #000000;"> assert(err==0); </span><span style="color: #3f7f5f;">//capture error</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="font-size: 16px;"><strong>Step3、</strong>启动滴答定时器中断,并在中断中对来到的任务标志使能</span></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p><span style="color: #3f5fbf;">/**</span></p>
<p><span style="color: #3f5fbf;"> * </span><span style="color: #7f9fbf;">@brief</span><span style="color: #3f5fbf;"> SysTick的中断服务函数</span></p>
<p><span style="color: #3f5fbf;"> * </span><span style="color: #7f9fbf;">@param</span><span style="color: #3f5fbf;"> 无</span></p>
<p><span style="color: #3f5fbf;"> * </span><span style="color: #7f9fbf;">@retval</span><span style="color: #3f5fbf;"> 无</span></p>
<p><span style="color: #3f5fbf;"> */</span></p>
<p><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">extern</span><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;"> </span><span style="color: #000000; font-weight: bold;">SysTick_Handler</span><span style="color: #000000;">(</span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;">); </span><span style="color: #3f7f5f;">//需要先</span><span style="color: #3f7f5f; text-decoration: underline; text-decoration-color: #ff8040; text-decoration-style: wavy;">extern</span><span style="color: #3f7f5f;">声明一下避免编译器警告</span></p>
<p><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;"> </span><span style="color: #000000; font-weight: bold;">SysTick_Handler</span><span style="color: #000000;">(</span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;">)</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #000000;"> TaskRemarks();</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="color: #000000;"> </span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;"> </span><span style="color: #000000; font-weight: bold;">TaskRemarks</span><span style="color: #000000;">(</span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;">)</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #005032;"> uint8_t</span><span style="color: #000000;"> i;</span></p>
<p><span style="color: #7f0055; font-weight: bold;"> for</span><span style="color: #000000;"> (i=0; i<</span><span style="color: #0000c0; font-style: italic;">TASKS_MAX</span><span style="color: #000000;">; i++) </span><span style="color: #3f7f5f;">// 逐个任务时间处理</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #7f0055; font-weight: bold;"> if</span><span style="color: #000000;"> (TaskComps[i].</span><span style="color: #0000c0;">Timer</span><span style="color: #000000;">) </span><span style="color: #3f7f5f;">// 时间不为0</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #000000;"> TaskComps[i].</span><span style="color: #0000c0;">Timer</span><span style="color: #000000;">--; </span><span style="color: #3f7f5f;">// 减去一个节拍</span></p>
<p><span style="color: #7f0055; font-weight: bold;"> if</span><span style="color: #000000;"> (TaskComps[i].</span><span style="color: #0000c0;">Timer</span><span style="color: #000000;"> == 0) </span><span style="color: #3f7f5f;">// 时间减完了</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #000000;"> TaskComps[i].</span><span style="color: #0000c0;">Timer</span><span style="color: #000000;"> = TaskComps[i].</span><span style="color: #0000c0;">ItvTime</span><span style="color: #000000;">; </span><span style="color: #3f7f5f;">// 恢复计时器值,从新下一次</span></p>
<p><span style="color: #000000;"> TaskComps[i].</span><span style="color: #0000c0;">Run</span><span style="color: #000000;"> = 1; </span><span style="color: #3f7f5f;">// 任务可以运行</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="color: #000000;"> }</span></p>
</div>
</div>
<p> </p>
</div>
</div>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt pap-left-indent-1.6em" style="line-height: 1.8;">Step4、main函数中调用任务函数TaskProcess,判断任务是否启动</p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;"> </span><span style="color: #000000; font-weight: bold;">TaskProcess</span><span style="color: #000000;">(</span><span style="color: #7f0055; font-weight: bold;">void</span><span style="color: #000000;">)</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #000000;"> </span><span style="color: #005032;">uint8_t</span><span style="color: #000000;"> i;</span></p>
<p><span style="color: #7f0055; font-weight: bold;"> for</span><span style="color: #000000;"> (i=0; i<</span><span style="color: #0000c0; font-style: italic;">TASKS_MAX</span><span style="color: #000000;">; i++) </span><span style="color: #3f7f5f;">// 逐个任务时间处理</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #7f0055; font-weight: bold;"> if</span><span style="color: #000000;"> (TaskComps[i].</span><span style="color: #0000c0;">Run</span><span style="color: #000000;">) </span><span style="color: #3f7f5f;">// 时间不为0</span></p>
<p><span style="color: #000000;"> {</span></p>
<p><span style="color: #000000;"> TaskComps[i].</span><span style="color: #0000c0;">TaskHook</span><span style="color: #000000;">(); </span><span style="color: #3f7f5f;">// 运行任务</span></p>
<p><span style="color: #000000;"> TaskComps[i].</span><span style="color: #0000c0;">Run</span><span style="color: #000000;"> = 0; </span><span style="color: #3f7f5f;">// 标志清0</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="color: #000000;"> }</span></p>
<p><span style="font-size: 10pt;">}</span></p>
<p> </p>
<p><strong><span style="font-size: 16px;">2.1.2 DHT11驱动介绍</span></strong></p>
<p><strong><span style="font-size: 16px;"> (1)DHT11基本知识介绍</span></strong></p>
<p><span style="font-size: 16px;"> DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器,内部由一个8位单片机控制一个电阻式</span></p>
<p><span style="font-size: 16px;">感湿元件和一个</span><span style="font-size: 16px;">NTC 测温元件。DHT11采用单总线协议</span><span style="font-size: 16px;">,其温度测量范围为 0~50℃,误差在±2℃;湿度的测</span><span style="font-size: 16px;">量范围为</span></p>
<p><span style="font-size: 16px;">20%~90%RH(Relative Humidity 相对湿度—指空气中水汽压与饱和水汽压的百分比),误差在±5%RH。DHT11 电路</span></p>
<p><span style="font-size: 16px;">很简单,只需</span><span style="font-size: 16px;">要将Dout引脚连接单片机的一个I/O即可,不过该引脚需要上拉一个电阻,DHT11 的供电电压为 3~5.5V。</span></p>
<p><span style="font-size: 16px;"><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/pullimage/sqDPGiGjcZB44kPMR7Y9CJqeL2saeOIBiFjTzleF.png" alt="" width="268" height="264"></span></p>
<p><span style="font-size: 16px;"><strong> (2)DHT11协议及数据格式</strong></span></p>
<p><span style="font-size: 16px;"> DHT11采用单总线协议与单片机通信,单片机发送一次复位信号后,DHT11从低功耗模式转换到高速模式,等待主机</span></p>
<p><span style="font-size: 16px;">复位结束后,DHT11发送响应信号,并拉高总线准备传输数据。一次完整的数据为40bit,按照高位在前,低位在后的顺序</span></p>
<p><span style="font-size: 16px;">传输</span><span style="font-size: 16px;">数据格式为:8bit 湿度整数数据+8bit 湿度小数数据+8bit 温度整数数据+8bit 温度小数数据+8bit校验和,一</span></p>
<p><span style="font-size: 16px;">共5字节(40bit)数据。由于DHT11分辨率只能精确到个位,所以小数部分是数据全为0。校验和为前4个字节数</span><span style="font-size: 16px;">据相加,</span></p>
<p><span style="font-size: 16px;">校验的目的是为了保证数据传输的准确性。</span><span style="font-size: 16px;">DHT11只有在接收到开始信号后才触发一次温湿度采集,如果没有接收到主机发</span></p>
<p><span style="font-size: 16px;">送复位信号,DHT11不主动进行温湿度采集。当数据采集完毕且无开始信号后,DHT11自动切换到低速模式。</span></p>
<h3><span style="font-size: 16px;"><strong>(3)DHT11操作时序</strong></span></h3>
<p><span style="font-size: 16px;"><strong> DHT11操作时序如下所示:</strong></span><span style="font-size: 16px;"><strong><img src="//image.lceda.cn/pullimage/zUZ6P1y99XQSJioCpaj5IEA13FJB5POuGw1gHZuy.png" alt="" width="1008" height="322"></strong></span></p>
<p><span style="font-size: 16px;"><strong>具体操作步骤如下:</strong></span></p>
<p><span style="font-size: 16px;"><strong>步骤一:<br> </strong> DHT11上电后(DHT11上电后要等待 1S 以越过不稳定状态在此期间不能发送任何指令),测试环境温湿度数据,并记</span></p>
<p><span style="font-size: 16px;">录数据,同时DHT11的DATA数据线由上拉电阻拉高一直保持高电平;此时DHT11的DATA引脚处于输入状态,时刻检测外部</span></p>
<p><span style="font-size: 16px;">信号。<strong><br>步骤二:<br></strong> 微处理器的I/O设置为输出同时输出低电平,且低电平保持时间不能小于18ms(最大不得超过 30ms),然后微处理器</span></p>
<p><span style="font-size: 16px;">的I/O设置为输入状态,由于上拉电阻,微处理器的I/O即DHT11的DATA 数据线也随之变高,等待DHT11作出回答信号,</span></p>
<p><span style="font-size: 16px;">发送信号如图所示:</span></p>
<p><span style="font-size: 16px;"><strong><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/pullimage/WePSoxfo3QkN3opIoxqFp73YHQBA78IsJXQI6Zly.png" alt=""></strong></span></p>
<p><span style="font-size: 16px;"><strong>步骤三:<br></strong> DHT11的DATA引脚检测到外部信号有低电平时,等待外部信号低电平结束,延迟后DHT11的DATA引脚处于输出状态,</span></p>
<p><span style="font-size: 16px;">输出83微秒的低电平作为应答信号,紧接着输出 87 微秒的高电平通知外设准备接收数据,微处理器的 I/O 此时处于输</span></p>
<p><span style="font-size: 16px;">入状态,检测到I/O有低电平(DHT11 回应信号)后,等待87微秒的高电平后的数据接收,发送信号如图所示:</span></p>
<p><span style="font-size: 16px;"><strong><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/pullimage/QigirysCtB6lwoea9PpnL4iywDBppYmexbCBeauH.png" alt=""></strong></span></p>
<p><span style="font-size: 16px;"><strong>步骤四:<br></strong> 由DHT11的DATA引脚输出40位数据,微处理器根据I/O电平的变化接收40位数据,位数据“0”的格式为: 54微秒的</span></p>
<p><span style="font-size: 16px;">低电平和23-27微秒的高电平,位数据“1”的格式为: 54微秒的低电平加68-74微秒的高电平。位数据“0”、“1”格式信</span></p>
<p><span style="font-size: 16px;">号如图所示:</span></p>
<p><span style="font-size: 16px;"><strong><img style="display: block; margin-left: auto; margin-right: auto;" src="//image.lceda.cn/pullimage/cHe67iTCe7xeiinwdXBwRJhOCXrMktptmOW8IcjG.png" alt="" width="986" height="221">结束信号:<br></strong> DHT11的DATA引脚输出40位数据后,继续输出低电平54微秒后转为输入状态,由于上拉电阻随之变为高电平。但</span></p>
<p><span style="font-size: 16px;">DHT11内部重测环境温湿度数据,并记录数据,等待外部信号的到来。 </span></p>
<p><strong><span style="font-size: 16px;">具体程序如下所示:</span></strong></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p> <span style="font-size: 16px;">具体代码参考MCU程序user_DHT11文件夹中文件;</span></p>
</div>
</div>
<p><strong><span style="font-size: 16px;">2.1.3 红外收发驱动介绍</span></strong></p>
<p> <span style="font-size: 16px;"> <span class="fontstyle0">红外遥控是一种无线、非接触控制技术,具有抗干扰能力强,信息传输可靠,功耗低,成本低,易实现等</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">显著优点,被诸多电子设备特别是家用电器广泛采用,并越来越多的应用到计算机系统中。由于红外线遥控不</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">具有像无线电遥控那样穿过障碍物去控制被控对象的能力,所以,在设计红外线遥控器时,不必要像无线电遥</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">控器那样,每套</span><span class="fontstyle1">(</span><span class="fontstyle0">发射器和接收器</span><span class="fontstyle1">)</span><span class="fontstyle0">要有不同的遥控频率或编码</span><span class="fontstyle1">(</span><span class="fontstyle0">否则,就会隔墙控制或干扰邻居的家用电器</span><span class="fontstyle1">)</span><span class="fontstyle0">,</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">所以同类产品的红外线遥控器,可以有相同的遥控频率或编码,而不会出现遥控信号“串门”的情况。这对于大</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">批量生产以及在家用电器上普及红外线遥控提供了极大的方面。由于红外线为不可见光,因此对环境影响很小,</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">再由红外光波动波长远小于无线电波的波长,所以红外线遥控不会影响其他家用电器,也不会影响临近的无线</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle0">电设备。红外遥控的编码目前广泛使用的是: </span><span class="fontstyle3">NEC Protocol </span><span class="fontstyle0">的 </span><span class="fontstyle3">PWM(</span><span class="fontstyle0">脉冲宽度调制</span><span class="fontstyle3">)</span><span class="fontstyle0">和 </span><span class="fontstyle3">Philips RC-5 </span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3">Protocol </span><span class="fontstyle0">的 </span><span class="fontstyle3">PPM(</span><span class="fontstyle0">脉冲位置调制</span><span class="fontstyle3">)。本项目使用的是NEC编码方式。NEC编码方式特点如下:</span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"> <span class="fontstyle0">1</span><span class="fontstyle1">、</span><span class="fontstyle0">8 </span><span class="fontstyle1">位地址和 </span><span class="fontstyle0">8 </span><span class="fontstyle1">位指令长度;<br></span><span class="fontstyle0">2</span><span class="fontstyle1">、地址和命令 </span><span class="fontstyle0">2 </span><span class="fontstyle1">次传输(确保可靠性)<br></span><span class="fontstyle0">3</span><span class="fontstyle1">、</span><span class="fontstyle0">PWM </span><span class="fontstyle1">脉冲位置调制,以发射红外载波的占空比代表“</span><span class="fontstyle0">0</span><span class="fontstyle1">”和“ </span><span class="fontstyle0">1</span><span class="fontstyle1">”;<br></span><span class="fontstyle0">4</span><span class="fontstyle1">、载波频率为 </span><span class="fontstyle0">38Khz</span><span class="fontstyle1">;<br></span><span class="fontstyle0">5</span><span class="fontstyle1">、位时间为 </span><span class="fontstyle0">1.125ms </span><span class="fontstyle1">或 </span><span class="fontstyle0">2.25ms</span><span class="fontstyle1">;</span> <br></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle0"> NEC </span><span class="fontstyle2">码的位定义:一个脉冲对应</span><span class="fontstyle0">560us</span><span class="fontstyle2">的连续载波,一个逻辑</span><span class="fontstyle0">1</span><span class="fontstyle2">传输需要</span><span class="fontstyle0">2.25ms</span><span class="fontstyle2">(</span><span class="fontstyle0">560us</span><span class="fontstyle2">脉冲</span><span class="fontstyle0">+1680us</span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">低</span></span></span><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">电平),一个逻辑</span><span class="fontstyle0">0</span><span class="fontstyle2">的传输需要</span><span class="fontstyle0">1.125ms</span><span class="fontstyle2">(</span><span class="fontstyle0">560us</span><span class="fontstyle2">脉冲</span><span class="fontstyle0">+560us </span><span class="fontstyle2">低电平)。而遥控接收头在收到脉冲的时候</span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">为</span></span></span><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">低电平,在没有脉冲的时候为高电平,这样,我们在接收头端收到的信号为:逻辑</span><span class="fontstyle0">1</span><span class="fontstyle2">应该是</span><span class="fontstyle0">560us</span><span class="fontstyle2">低</span><span class="fontstyle0">+1680</span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle0">us</span><span class="fontstyle2">高</span></span></span><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">,逻辑</span><span class="fontstyle0">0</span><span class="fontstyle2">应该是</span><span class="fontstyle0">560us</span><span class="fontstyle2">低</span><span class="fontstyle0">+560us</span><span class="fontstyle2">高。</span><span class="fontstyle0">NEC</span><span class="fontstyle2">遥控指令的数据格式为:同步码头、地址码、地址反码、</span></span></span><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">控制码</span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">、控制反码。同步码由一个</span><span class="fontstyle0">9ms</span><span class="fontstyle2">的低电平和一个</span><span class="fontstyle0">4.5ms</span><span class="fontstyle2">的高电平组成,地址码、地址反码、控制码、控制反码</span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">均是</span><span class="fontstyle0">8</span><span class="fontstyle2">位数据格式。按照低位在前,高位在后的顺序发送。采用反码是为了增加传输的可靠性(可用于校验)。</span> <br></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2"><img src="//image.lceda.cn/pullimage/G4ZJJ7vao9BSqbggm3NFChjPtmBJHxwDXtVm7eXo.png" alt="" width="871" height="259"></span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2"><img src="//image.lceda.cn/pullimage/rLU2HMZwsGEYCxiKLUVSHkShIGjbbaYJNm0xckRD.png" alt="" width="1147" height="207"> <span class="fontstyle0"> 本程序利用输入捕获来测量高电平的脉宽,来解码红外遥控信号,利用两个定时器产生发送信号,</span>一个定时器</span></span></span></p>
<p><span style="font-size: 16px;"><span class="fontstyle3"><span class="fontstyle2">用于PWM脉冲信号发送时间计时一个定时器用于38K PWM脉冲信号产生。</span></span></span></p>
<p><strong><span style="font-size: 16px;">具体程序如下所示:</span></strong></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p> <span style="font-size: 16px;">发送驱动具体代码参考MCU程序user_ir_send文件夹中文件;</span></p>
<p><span style="font-size: 16px;"> 接收驱动具体代码参考MCU程序user_bsp_gpt_pwm文件夹中文件; </span></p>
</div>
</div>
<p><strong><span style="font-size: 16px;">2.1.4 NTC读取介绍</span></strong></p>
<p> <span style="font-size: 16px;">采用NTC10K热敏电阻,使用AN008通道进行ADC读取,计算出热敏电阻上的电压,再通过公式法算出当前</span></p>
<p><span style="font-size: 16px;">温度,公式法如下所示:</span></p>
<p><span style="font-size: 16px;">NTC 热敏电阻温度计算公式:Rt = R *EXP(B*(1/T1-1/T2))</span></p>
<p><span style="font-size: 16px;"> (1) T1和T2指的是K度,即开尔文温度。</span></p>
<p><span style="font-size: 16px;"> (2) Rt 是热敏电阻在T1温度下的阻值。</span></p>
<p><span style="font-size: 16px;"> (3) R是热敏电阻在T2常温下的标称阻值。10K的热敏电阻25℃的值为10K(即R=10K)。</span></p>
<p><span style="font-size: 16px;"> (4) T2 = (273.15+25)。</span></p>
<p><span style="font-size: 16px;"> (5) EXP(?) 是 e 的 ? 次方。</span></p>
<p><span style="font-size: 16px;"> (6) B值是热敏电阻的重要参数。</span></p>
<p><span style="font-size: 16px;">通过转换,得到温度 T1 与电阻 Rt 的关系:</span></p>
<p><span style="font-size: 16px;">T1 = 1 / ( ln( Rt/R ) / B + 1/T2 )</span></p>
<p><span style="font-size: 16px;">最终对应的摄氏温度:</span></p>
<p><span style="font-size: 16px;">Temp = T1 - 273.15</span></p>
<p><strong><span style="font-size: 16px;">具体程序如下所示:</span></strong></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p> <span style="font-size: 16px;">驱动具体代码参考MCU程序user_ntc_3950_10k_read文件夹中文件;</span></p>
</div>
</div>
<p><strong><span style="font-size: 16px;">2.2 WiFi部分介绍</span></strong></p>
<p> <span style="font-size: 16px;"> 本项目Wifi模块使用的是ESP8266,物联网平台使用的是腾讯物联网平台以及心知天气平台,二者分别使用MQTT和</span></p>
<p><span style="font-size: 16px;">HTTP的方式进行连接,下面对WiFi代码比较关键的地方进行具体说明。</span></p>
<p><strong><span style="font-size: 16px;">2.2.1 WiFi配网流程介绍</span></strong></p>
<p> <span style="font-size: 16px;"> 腾讯物联网平台WiFi配网过程如下图所示:</span></p>
<p><span style="font-size: 16px;"><img src="//image.lceda.cn/pullimage/59ix8bbyMkw0ZB68c65R9bxvBzqNErF3Ng5rvFnv.png" alt=""></span></p>
<p><span style="font-size: 16px;"> WiFi配网流程如上图所示,下面主要讲解下WiFi UDP连接建立,以及如何通过json字符串获得小程序的token。</span></p>
<p><span style="font-size: 16px;">WiFi UDP建立步骤如下:</span></p>
<p><span style="font-size: 16px;">1、WiFi进入soft AP模式,找到路由进行连接;</span></p>
<p><span style="font-size: 16px;">2、连接成功后WiFi建立socket();</span></p>
<p><span style="font-size: 16px;"><img src="//image.lceda.cn/pullimage/vgxC6pbLE91fBd9bQMllSBQWJLAIjuuegzH83g4Z.png" alt="" width="876" height="353"></span></p>
<p><span style="font-size: 16px;">3、绑定UDP bind();</span></p>
<p><span style="font-size: 16px;"><img src="//image.lceda.cn/pullimage/VbyzCWzA1nfLoSdsUl2285ukHW9B1Ed2noaNVbAj.png" alt=""></span></p>
<p><span style="font-size: 16px;">4、监听UDP是否有数据传输;</span></p>
<p><span style="font-size: 16px;"><img src="//image.lceda.cn/pullimage/LbgSO8UCGUtGswcfC88YXlQIXBg5sxhoABY1GgNi.png" alt="" width="949" height="292"></span></p>
<p> </p>
<p><span style="font-size: 16px;">小程序通过UDP传输发送的json字符串如下所示:</span></p>
<p><span style="font-size: 16px;">{"cmdType":1,"ssid":"Home-WiFi","password":"abcd1234",</span></p>
<p><span style="font-size: 16px;">"token":"6aa11111****23****546****11****d"} </span></p>
<p><span style="font-size: 16px;"> 可以通过cjson对字符串进行解析,解析出当前WiFi所需连接路由的ssid,password,以及要发给腾讯物联网平台的</span></p>
<p><span style="font-size: 16px;">token</span><span style="font-size: 16px;">当设备端连接路由器,与腾讯物联网平台建立MQTT连接并订阅后,将token发送到腾讯物联网平台。发送成功后,手</span></p>
<p><span style="font-size: 16px;">机APP、</span><span style="font-size: 16px;">腾讯物联网平台、设备端三者通过token实现绑定,配网完成。</span></p>
<p><strong><span style="font-size: 16px;">具体程序如下所示:</span></strong></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p> <span style="font-size: 16px;">驱动具体代码参考WiFi程序user_udp_sever文件夹中文件;</span></p>
</div>
</div>
<p><strong><span style="font-size: 16px;">2.2.2 WiFi http连接心知天气流程介绍</span></strong></p>
<p> <span style="font-size: 16px;">WiFi连接路由后,建立socket,进行lwip_connect连接知心天气端口,发送get指令获取返回信息。</span></p>
<p><strong><span style="font-size: 16px;">具体程序如下所示:</span></strong></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p> <span style="font-size: 16px;">驱动具体代码参考WiFi程序user_http_request文件夹中文件;</span></p>
</div>
</div>
<p><strong><span style="font-size: 16px;">2.2.3 WiFi mqtt连接腾讯云流程介绍</span></strong></p>
<p><strong><span style="font-size: 16px;"> </span></strong><span style="font-size: 16px;"> 1、腾讯物联网三元码动态生成,进行mqtt初始化;</span></p>
<p><span style="font-size: 16px;"> 2、连接腾讯物联网平台,腾讯物联网平台端口为1883;</span></p>
<p><span style="font-size: 16px;"> 3、连接成功后进行订阅;</span></p>
<p><span style="font-size: 16px;"> 4、订阅成功后可以与腾讯物联网平台按照约定的json结构进行数据收发;</span></p>
<p><strong><span style="font-size: 16px;">具体程序如下所示:</span></strong></p>
<div style="background-color: #ffffff; padding: 0px 0px 0px 2px;">
<div style="color: #000000; background-color: #ffffff; font-family: 'Courier New'; font-size: 10pt; white-space: nowrap;">
<p> <span style="font-size: 16px;">驱动具体代码参考WiFi程序user_mqtt_tcp文件夹中文件;</span></p>
</div>
</div>
</div>
</div>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">*6、BOM清单</h3>
<hr class="horizontal-splitline normal-bold-2">
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/yEmFdnqdqQlLjfz3gizmn1OPmEu0rzYcnKfznxQK.png" alt="" width="1642" height="604"><img src="//image.lceda.cn/pullimage/vwmGgb1bdDXNmScBItJbgJzqET08LeLuVQ89RtE5.png" alt="" width="1649" height="420"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">*7、大赛LOGO验证</h3>
<hr class="horizontal-splitline normal-bold-2">
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/a5zAtAaICqJWPAItP3uoLcP6C8PcfvqP6EcZa9Ug.jpeg" alt="" width="1090" height="818"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/fvF8X1WtMBx3T2xD6vMxk6N5vL95p8Lzgi0v8D0b.jpeg" alt="" width="1094" height="821"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><img src="//image.lceda.cn/pullimage/Tvs46yhpmackD1r19NXqQHFbo4FyWWJScsXmoJ8O.jpeg" alt="" width="1097" height="1462"></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<h3 class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;">* 8、演示您的项目并录制成视频上传</h3>
<hr class="horizontal-splitline normal-bold-2">
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"><span style="font-size: 14px;">更多详情:<a href="/posts/15a52db9fd7d40c492eb505280278e45" target="_blank">https://diy.szlcsc.com/posts/15a52db9fd7d40c492eb505280278e45</a></span></p>
<p class="paragraph text-align-type-left pap-line-1.3 pap-line-rule-auto pap-spacing-before-3pt pap-spacing-after-3pt" style="line-height: 1.8;"> </p>
</div>
评论(15)