汇编语言:51单片机与蓝牙模块通信
<p>大二学年的小学期,初次接触蓝牙模块,到网上查找了很多教程,在实操过程中仍然遇到许多状况,整理自己的经验和心得,以飨读者,如有错漏,欢迎批评指正!</p><p>1、连接蓝牙模块与USB转TTL模块</p>
<p><img src="https://img2018.cnblogs.com/blog/1741983/201907/1741983-20190716105734983-1723992139.jpg"></p>
<p>如图所示,上面的器件是USB转TTL模块,下面的是蓝牙模块(型号:HC-05)。GND-GND,VCC-5V,TXD-RXD,RXD-TXD。</p>
<p>注意:USB转TTL模块用不到的两个管脚(3.3V和VCC)要短接,否则此模块连接笔记本电脑时读不到此串口。</p>
<p>2.安装蓝牙串口驱动软件</p>
<p><img src="https://img2018.cnblogs.com/blog/1741983/201907/1741983-20190716111227435-1668434688.jpg"></p>
<p>这个真的是写给第一次用蓝牙模块的新手小白看的。</p>
<p>拿到USB转TTL模块直接往电脑USB接口上怼,怼了一下午,刷新了好多次电脑也没有显示COM口(就是串行接口,也叫串口),原因就是缺少相应的驱动程序,电脑根本读不到这个器件。</p>
<p>下面分享的是驱动程序,由于电脑不一样,所以这个链接里面有很多个版本的驱动程序,多试几次,总有一款比较合适。</p>
<p>注意:如果在安装的时候显示安装失败,那就点击卸载,然后再点安装,这样就可以安装成功了。</p>
<p>链接:https://pan.baidu.com/s/1ovdtNxp-2jsohM0REJbkXw <br>提取码:bdpb </p>
<p>3.串口调试软件</p>
<p><img src="https://img2018.cnblogs.com/blog/1741983/201907/1741983-20190716112444806-1480452913.jpg"></p>
<p>这一步可以参照这篇的Step1和Step2:</p>
<h1><span style="font-size: 14px">51单片机使用和配置HC-05蓝牙模块</span></h1>
<h1 class="title-article"><span style="font-size: 14px">https://blog.csdn.net/qimi923511491/article/details/82928743</span></h1>
<p>里面也给了这个串口调试软件的下载链接,为防失效,下面再附上一个下载链接。</p>
<p>链接:https://pan.baidu.com/s/1n1TWC1Vsfhzk_MS8kITFeQ <br>提取码:gygz</p>
<p>4.汇编语言对单片机编程</p>
<p>设置好蓝牙模块之后,把蓝牙模块拆下来连接51单片机,连接方法和上面USB转TTL模块的一样,注意TX和RX之间要交叉连接。</p>
<p>然后烧录单片机程序,蓝牙就会把单片机串口发送来的数据向已经连接上的蓝牙设备进行发送。</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> <span style="color: rgba(0, 0, 0, 1)">ORG 0000H
</span><span style="color: rgba(0, 128, 128, 1)"> 2</span> <span style="color: rgba(0, 0, 0, 1)">SJMP MAIN
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span> <span style="color: rgba(0, 0, 0, 1)">ORG 0060H
</span><span style="color: rgba(0, 128, 128, 1)"> 4</span> <span style="color: rgba(0, 128, 128, 1)">MAIN:</span>
<span style="color: rgba(0, 128, 128, 1)"> 5</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span><span style="color: rgba(0, 0, 0, 1)"> TMOD,#20H
</span><span style="color: rgba(0, 128, 128, 1)"> 6</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span><span style="color: rgba(0, 0, 0, 1)"> TH1,#0FDH
</span><span style="color: rgba(0, 128, 128, 1)"> 7</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span><span style="color: rgba(0, 0, 0, 1)"> TL1,#0FDH
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span> PCON,#<span style="color: rgba(128, 0, 128, 1)">0</span>
<span style="color: rgba(0, 128, 128, 1)"> 9</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span><span style="color: rgba(0, 0, 0, 1)"> SCON,#40H
</span><span style="color: rgba(0, 128, 128, 1)">10</span> <span style="color: rgba(0, 0, 255, 1)">SETB</span><span style="color: rgba(0, 0, 0, 1)"> EA
</span><span style="color: rgba(0, 128, 128, 1)">11</span> <span style="color: rgba(0, 0, 255, 1)">SETB</span><span style="color: rgba(0, 0, 0, 1)"> ES
</span><span style="color: rgba(0, 128, 128, 1)">12</span> <span style="color: rgba(0, 0, 255, 1)">SETB</span><span style="color: rgba(0, 0, 0, 1)"> TR1
</span><span style="color: rgba(0, 128, 128, 1)">13</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span><span style="color: rgba(0, 0, 0, 1)"> A,#01h
</span><span style="color: rgba(0, 128, 128, 1)">14</span> <span style="color: rgba(0, 128, 128, 1)">L1:</span>
<span style="color: rgba(0, 128, 128, 1)">15</span> <span style="color: rgba(0, 128, 0, 1)">;</span><span style="color: rgba(0, 128, 0, 1)">INC A</span>
<span style="color: rgba(0, 128, 128, 1)">16</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span><span style="color: rgba(0, 0, 0, 1)"> SBUF,A
</span><span style="color: rgba(0, 128, 128, 1)">17</span> <span style="color: rgba(0, 0, 255, 1)">mov</span><span style="color: rgba(0, 0, 0, 1)"> p2,a
</span><span style="color: rgba(0, 128, 128, 1)">18</span> <span style="color: rgba(0, 128, 128, 1)">LL1:</span><span style="color: rgba(0, 0, 255, 1)">JNB</span><span style="color: rgba(0, 0, 0, 1)"> TI,LL1
</span><span style="color: rgba(0, 128, 128, 1)">19</span> <span style="color: rgba(0, 0, 0, 1)">CLR TI
</span><span style="color: rgba(0, 128, 128, 1)">20</span> <span style="color: rgba(0, 0, 255, 1)">MOV</span> R2,#<span style="color: rgba(128, 0, 128, 1)">255</span>
<span style="color: rgba(0, 128, 128, 1)">21</span> <span style="color: rgba(0, 128, 128, 1)">DD1:</span><span style="color: rgba(0, 0, 255, 1)">MOV</span> R3,#<span style="color: rgba(128, 0, 128, 1)">255</span>
<span style="color: rgba(0, 128, 128, 1)">22</span> <span style="color: rgba(0, 128, 128, 1)">DD2:</span><span style="color: rgba(0, 0, 0, 1)">DJNZ R3,DD2
</span><span style="color: rgba(0, 128, 128, 1)">23</span> <span style="color: rgba(0, 0, 0, 1)">DJNZ R2,DD1
</span><span style="color: rgba(0, 128, 128, 1)">24</span> <span style="color: rgba(0, 0, 0, 1)">SJMP L1
</span><span style="color: rgba(0, 128, 128, 1)">25</span> END</pre>
</div>
<p>实现效果:单片机不停地向蓝牙模块发送1。</p>
<p>5.在手机上下载一个蓝牙串口软件,搜索蓝牙设备(在蓝牙上电的情况下),输入密码(未修改过的话应该是1234),实现配对与连接,实现可视化显示,能够看到接收到数据1。</p><br><br>
来源:https://www.cnblogs.com/Annion-blog/p/11193865.html
頁:
[1]