找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2751|回复: 0
收起左侧

51单片机流水灯从左到右 源程序+电路图

[复制链接]
ID:622126 发表于 2019-10-12 12:33 | 显示全部楼层 |阅读模式
流水灯左右走程序.docx (12.96 KB, 下载次数: 7)
图加程序
SK6$MFA$[5}BP2FSO3`19~T.png

单片机源程序如下:
  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. }

复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表