当前位置:   article > 正文

51单片机通过按键控制LED灯闪烁_单片机按键双击点亮led灯

单片机按键双击点亮led灯

缘由https://bbs.csdn.net/topics/396573224    示例工程下载

  1. #include "reg52.h"
  2. sbit K1 = P1^4;//按键
  3. sbit K2=P1^5;//按键
  4. sbit K3=P1^6;//按键
  5. sbit K4=P1^7;//按键
  6. bit k1=0,k2=0,k3=0,k4=0,k=0;//标记
  7. unsigned char code LedBiao[] = {0,15,240,85,170};//前4后4奇数偶数
  8. void main()
  9. {
  10. unsigned char Xd=0;
  11. unsigned int Ys=47474;
  12. while(1)
  13. {
  14. if(!K1&&!--Xd){k1=~k1;k2=k3=k4=0;while(!K1);}
  15. if(!K2&&!--Xd){k2=~k2;k1=k3=k4=0;while(!K2);}
  16. if(!K3&&!--Xd){k3=~k3;k2=k1=k4=0;while(!K3);}
  17. if(!K4&&!--Xd){k4=~k4;k2=k3=k1=0;while(!K4);}
  18. if(--Ys==0)
  19. {
  20. k=~k;if(!k) P2=0;else P2=255;Ys=47474;
  21. if(k&&k1)P2=LedBiao[1];
  22. if(k&&k2)P2=LedBiao[2];
  23. if(k&&k3)P2=LedBiao[3];
  24. if(k&&k4)P2=LedBiao[4];
  25. }
  26. }
  27. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/685658
推荐阅读
相关标签
  

闽ICP备14008679号