标题: 51单片机流水灯从左到右 源程序+电路图 [打印本页]

作者: Scorpionx    时间: 2019-10-12 12:33
标题: 51单片机流水灯从左到右 源程序+电路图
流水灯左右走程序.docx (12.96 KB, 下载次数: 7)
图加程序


单片机源程序如下:
  1. #include <REG52.H>
  2. void Delay1ms(unsigned int count)
  3. {
  4.     unsigned int i,j;
  5.     for(i=0;i<count;i++)
  6.     for(j=0;j<120;j++);
  7. }
  8. main()
  9. {
  10.     unsigned char LEDIndex = 0;
  11.     bit LEDDirection = 1;
  12.     while(1)【满足条件执行下面程序】
  13.     {
  14.         if(LEDDirection)
  15.             P1 = ~(0x01<<LEDIndex);【满足】<<表示逻辑移位
  16.         else
  17.             P1 = ~(0x80>>LEDIndex);【不满足】~表示按位取反
  18.         if(LEDIndex==7)
  19.             LEDDirection = !LEDDirection;
  20.         LEDIndex = (LEDIndex+1)%8;    【%】取余数
  21.         Delay1ms(100);
  22.     }
  23. }

复制代码







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