51单片机(ST89C52):利用JDY-16蓝牙模块控制LED小灯亮灭,程序编译没有问题,但为什么功能实现不了?

2019-11-22 14:50发布

<pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-comment">//利用蓝牙模块控制单片机上一个LED小灯亮灭</span> <span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-meta-string">&lt;reg52.h&gt;</span></span> sbit LED=P2^<span class="hljs-number">0</span>; <span class="hljs-comment">//LED控制IO口</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">chushihua</span><span class="hljs-params">()</span></span>; <span class="hljs-comment">//初始化串口</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span> dat; <span class="hljs-comment">//利用dat接收蓝牙发送的信息</span> <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{ chushihua(); <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>) { IF(dat==<span class="hljs-number">1</span>) { LED=<span class="hljs-number">0</span>; } <span class="hljs-keyword">else</span> { LED=<span class="hljs-number">1</span>; } } } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">chushihua</span><span class="hljs-params">()</span> </span>{ SCON=<span class="hljs-number">0x50</span>; TMOD=<span class="hljs-number">0x20</span>; PCON=<span class="hljs-number">0x00</span>; TH1=<span class="hljs-number">0xFD</span>; <span class="hljs-comment">//波特率9600,晶振11.0592M</span> TL1=<span class="hljs-number">0XFD</span>; TR1=<span class="hljs-number">1</span>; ES=<span class="hljs-number">1</span>; EA=<span class="hljs-number">1</span>; } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">zhongduan</span><span class="hljs-params">(<span class="hljs-keyword">void</span>)</span> interrupt 4 <span class="hljs-keyword">using</span> 1 </span>{ <span class="hljs-keyword">if</span> (RI==<span class="hljs-number">1</span>) <span class="hljs-comment">//传送信息后串口中断</span> { RI=<span class="hljs-number">0</span>; <span class="hljs-comment">//重置串口</span> dat=SBUF; <span class="hljs-comment">//将寄存器信息放入dat中</span> } } </code></pre><p><br></p>