通过按键控制LED上移和下移!
仿真原理图:

程序设计:
#include <reg52.h>#include <intrins.h>#define uchar unsigned char#define uint unsigned intvoid DelayMS(uint x){uchar i;while(x--){for(i=200;i>0;i--);}}void Move_LED(){if((P1 &= 0x10)==0) P0 = _cror_(P0,1);else if((P1 &= 0x20)==0) P0 = _crol_(P0,1);else if((P1 &= 0x40)==0) P2 = _cror_(P2,1);else if((P1 &= 0x80)==0) P2 = _crol_(P2,1);}void main(){uchar Recent_Key=0xff;P0=0xfe;P1=0xfe;P2=0xfe;while(1){if(Recent_Key != P1){Recent_Key=P1;Move_LED();DelayMS(10);}}}
该博客介绍了如何通过C语言编写程序,实现利用按键控制LED灯在仿真原理图上的上移和下移操作。程序中包含了延迟函数、按键状态判断以及LED位移函数,主要涉及单片机和嵌入式硬件领域的知识。
430

被折叠的 条评论
为什么被折叠?



