标题: 基于51单片机的流水灯 [打印本页]

作者: 59595959    时间: 2020-12-9 17:19
标题: 基于51单片机的流水灯
  1. #include<reg52.h>

  2. #define uchar unsigned char

  3. #define uint unsigned int

  4. unsigned char TAB[]= {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; // 改变这dao里 LED 各种花样du

  5. uchar t,i;

  6. void main()

  7. {

  8. TMOD=0x10;

  9. TH1=(65535-50000)/256; // 50ms一次zhi

  10. TL1=(65535-50000)%256;

  11. EA=1;

  12. ET1=1;//开定时器dao1中断

  13. TR1=1;//启动定时器1

  14. t=0;

  15. i=1;

  16. P2=TAB[0];

  17. while(1)

  18. {
  19.        
  20.         if(t==20)

  21.         {
  22.             
  23.                 t=0;
  24.                
  25.                 P2=TAB[i];
  26.                
  27.                 i++;
  28.                
  29.                 if(i==8)
  30.                 { i=0;}
  31.        
  32.         }
  33. }

  34. }

  35. void timer1() interrupt 3

  36. {

  37. TH1=(65535-50000)/256; // 50ms一次

  38. TL1=(65535-50000)%256;

  39. t++;



  40. }
复制代码
以前的小东西





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1