按键无法以逾期的设想控制流水灯
预期是使其中一个不亮的灯从左往右移动
但是按下按键灯一直以一个亮着的灯从左往右移动
刚刚接触这方面的东西,已经卡在这里好久好久,求各位解惑,万分感谢!
下面是代码和proteus的图
#include <REGX52.H>
void Delay1ms(unsigned int xms)
{
unsigned char i, j;
while(xms)
{
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
xms--;
}
}
void main()
{
while(1)
{
if(P3_4==0)
{
P2=0X01;//0111 1111
Delay1ms(500);
P2=0X02;//1011 1111
Delay1ms(500);
P2=0X04;//1101 1111
Delay1ms(500);
P2=0X08;//1110 1111
Delay1ms(500);
P2=0X10;//1111 0111
Delay1ms(500);
P2=0X20;//1111 1011
Delay1ms(500);
P2=0X40;//1111 1101
Delay1ms(500);
P2=0X80;//1111 1110
Delay1ms(500);
}
else if(P3_5==0)
{
P2=0X81;//1000 0001
Delay1ms(500);
P2=0XC3;//1100 0011
Delay1ms(500);
P2=0XE7;//1110 0111
Delay1ms(500);
P2=0XFF;//1111 1111
Delay1ms(500);
P2=0XE7;//1110 0111
Delay1ms(500);
P2=0XC3;//1100 0011
Delay1ms(500);
P2=0X81;//1000 0001
Delay1ms(500);
P2=0X00;//0000 0000
Delay1ms(500);
}
else if(P3_6==0)
{
P2=0XF0;//1111 0000
Delay1ms(500);
P2=0X0F;//0000 1111
Delay1ms(500);
P2=0XF0;//1111 0000
Delay1ms(500);
P2=0X0F;//0000 1111
Delay1ms(500);
}
else if(P3_7==0)
{
P2=0XAA;//1010 1010
Delay1ms(500);
P2=0X55;//0101 0101
Delay1ms(500);
P2=0XAA;//1010 1010
Delay1ms(500);
P2=0X55;//0101 0101
Delay1ms(500);
}
}
}