程序有点小疑惑,望发烧友们指点迷津。

2019-11-25 15:35发布

<font face="微软雅黑"><font style="font-size:18px">想让单片机的一个LED闪烁500ms熄灭500ms,也达到目的了,可是对于程序的某个小地方有些不解,问题写在程序里面了。</font></font><br><pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-meta">#<span class="hljs-meta-keyword">include</span> <span class="hljs-string">"reg52.h"</span></span> <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> uint unsigned int</span> <span class="hljs-keyword">typedef</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span> uchar; sbit led=P2^<span class="hljs-number">1</span>; uint i; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">binter</span><span class="hljs-params">()</span></span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{ binter(); i=<span class="hljs-number">0</span>; <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>) { IF(TR0==<span class="hljs-number">1</span>) i++; <span class="hljs-comment">//(这个if语句删除后再在中断里加i++,载入单片机后能达到预期500ms,led变换一次,可是保留if语句就不行)</span> <span class="hljs-keyword">if</span>(i==<span class="hljs-number">10</span>) { i=<span class="hljs-number">0</span>; led=~led; } } } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">binter</span><span class="hljs-params">()</span> </span>{ EA=<span class="hljs-number">1</span>; ET0=<span class="hljs-number">1</span>; TR0=<span class="hljs-number">1</span>; TH0=(<span class="hljs-number">65536</span><span class="hljs-number">-50000</span>)/<span class="hljs-number">256</span>; TL0=(<span class="hljs-number">65536</span><span class="hljs-number">-50000</span>)%<span class="hljs-number">256</span>; TMOD=<span class="hljs-number">0x01</span>; } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">t50ms</span><span class="hljs-params">()</span> interrupt 1 </span>{ TH0=(<span class="hljs-number">65536</span><span class="hljs-number">-50000</span>)/<span class="hljs-number">256</span>; TL0=(<span class="hljs-number">65536</span><span class="hljs-number">-50000</span>)%<span class="hljs-number">256</span>; <span class="hljs-comment">//i++;</span> } </code></pre><p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
阿信509
1楼-- · 2019-11-25 19:11
IF(TR0==1)这个语句啥意思,你要达到什么目的呢
人中狼
2楼-- · 2019-11-25 23:48
这个要查中断标志的数据了,有的中断标志是会在中断执行完后由硬件自动置0的,如果TR0是这类中断标志的话,那么  IF(TR0==1)就永远不会成立了
lovezjf234
3楼-- · 2019-11-26 04:15
 精彩回答 2  元偷偷看……

一周热门 更多>