51单片机定时器控制流水灯,直接定义为啥不行?

2019-11-22 15:45发布

<p><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> <span class="hljs-meta">#<span class="hljs-meta-keyword">include</span></span> <span class="hljs-keyword">typedef</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">int</span> u16; <span class="hljs-keyword">typedef</span> <span class="hljs-keyword">unsigned</span> <span class="hljs-keyword">char</span> u8; <span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> LED P2</span> u16 i; <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Tmier</span><span class="hljs-params">()</span> </span>{ TMOD |=<span class="hljs-number">0X01</span>; TH0=<span class="hljs-number">0XD8</span>; TL0=<span class="hljs-number">0XF0</span>; ET0=<span class="hljs-number">1</span>; TR0=<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">main</span><span class="hljs-params">()</span> </span>{ Tmier(); led=<span class="hljs-number">0xfe</span>; <span class="hljs-keyword">while</span>(<span class="hljs-number">1</span>) { led=<span class="hljs-number">0xfe</span>; IF(i==<span class="hljs-number">10</span>) { i=<span class="hljs-number">0</span>; led=_cror_(led,<span class="hljs-number">1</span>); } } } <span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Into</span> <span class="hljs-params">()</span> interrupt 1 </span>{ TH0=<span class="hljs-number">0XD8</span>; TL0=<span class="hljs-number">0XF0</span>; i++; }</code></pre> <font face="微软雅黑"><font style="font-size:18px">这样写为啥不行,而把led再定义之后就可以了呢?如在主函数中再加一句unsigned char data1=led;然后把后面的led换成data1流水灯就好了呢?为啥?</font></font><br> <p><br></p>
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
4条回答
wulinwl
2019-11-22 20:06
你既然宏定义#define LED P2  ,就必须都用大写,不可随意改为小写led。否则需要另外定义led。
  1. #include<reg52.h>
  2. #include<intrins.h>
  3. typedef unsigned int u16;
  4. typedef unsigned char u8;
  5. #define LED P2
  6. u8 i;
  7. void Tmier()
  8. {
  9.         TMOD |=0X01;
  10.         TH0=0XD8;
  11.         TL0=0XF0;
  12.         ET0=1;
  13.         TR0=1;
  14.         EA=1;
  15. }
  16. void main()
  17. {
  18.         Tmier();
  19.         LED=0x7f;
  20.         while(1)
  21.         {
  22. //                LED=0xfe;此句必须去掉
  23.                 if(i==10)
  24.                 {
  25.                         i=0;
  26.                         LED=_cror_(LED,1);
  27.                 }        
  28.         }
  29. }
  30. void Into () interrupt 1
  31. {
  32.         TH0=0XD8;
  33.         TL0=0XF0;
  34.         i++;
  35. }
复制代码 最佳答案

一周热门 更多>