普中电路板实现流水灯操作时为什么所有灯都亮了?

2019-11-26 13:38发布

<p> 根据普中电路原理图,MCU通过P0控制,我让P0从0x01的取反开始移位,取七个,但是LED仍旧一起亮,这是为什么?是控制口写错了吗?还是我定义的有问题,再次求教各位大佬,谢谢。</p><p>&nbsp; <ignore_js_op><!--原理图--><img src="data/attach/1911/wgyb1mh5428iejks5sxna3twryatdt54.png" alt="原理图" title="原理图"> </ignore_js_op> <br> 源代码<br></p><pre style="max-width: 100%;"><code class="cpp hljs" codemark="1"><span class="hljs-meta"># <span class="hljs-meta-keyword">include</span> </span> sbit ADDR0 = P1^<span class="hljs-number">0</span>; sbit ADDR1 = P1^<span class="hljs-number">1</span>; sbit Addr2 = P1^<span class="hljs-number">2</span>; sbit Addr3 = P1^<span class="hljs-number">3</span>; sbit ENLED = P1^<span class="hljs-number">4</span>; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">()</span> </span>{ <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span> i = <span class="hljs-number">0</span>; <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span> cnt = <span class="hljs-number">0</span>; ENLED = <span class="hljs-number">0</span>; ADDR3 = <span class="hljs-number">1</span>; ADDR2 = <span class="hljs-number">1</span>; ADDR1 = <span class="hljs-number">1</span>; ADDR0 = <span class="hljs-number">0</span>; <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>) { P0 = ~(<span class="hljs-number">0x01</span> &lt;&lt; cnt); <span class="hljs-keyword">for</span>(i = <span class="hljs-number">0</span>; i &lt; <span class="hljs-number">40000</span>; i++) { cnt++; } IF(cnt &gt;= <span class="hljs-number">8</span>) { cnt = <span class="hljs-number">0</span>; } } }</code></pre><p><reg52.h> <br> <br> </reg52.h></p><p><br></p><p></p><p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。