程序
#include <REGX52.H>
void main()
{
while(1)
{
if(P3_1 == 0) //DOWN
{
P2_0 = 0xFE;
}
if(P3_1 == 1) //UP
{
P2_0 = 0XFF;
}
};
}
按键的抖动问题
软件实现解决-按键的抖动问题
通过延时解决
#include <REGX52.H>
void Delay(unsigned int xms)
{
while(xms)
{
unsigned char data i, j;
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
xms--;
};
}
void main()
{
while(1)
{
if(P3_1 == 0) //down
{
Delay(20);
while(P3_1 == 0); //check down
Delay(20);
P2_0 = ~P2_0; //change
}
};
}