#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit key=P3^5;
sbit shuchu=P3^3;
void delay(uint n)
{
uint i=0,j=0;
for(i=0;i<n;i++)
for(j=0;j<123;j++);
}
void main()
{
uchar i;
while(1)
{
if(key==0)
delay(100);
if(key==0)
{
i++;
if(i==2)
{
i=0;
shuchu=1;
}
while(!key);
}
if(i<2)
shuchu=0;
}
}
上面的的程序仿真时正常下载到单片机中就不行了,程序思路是独立按键按动两次才有一次输出,可是实际按动按键时有时候三次才有输出,有时候连着两次输出,延时函数应该没有问题,请教各位大师指点一下 |