程序逻辑不对
#include "reg52.h"
typedef unsigned int u16;
typedef unsigned char u8;
sbit led=P2^0;
sbit k3=P3^2;
u16 flag=0,t=0;
void delay(u16 i)
{
while(i--);
}
void keyscan()
{
u8 t=0;
if(k3==0)
{
delay(100);
if(k3==0)
{
led=0;
while(t<50&&k3==0)
{
flag=1;
t++;
}
}
}
}
void Timer0Init()
{
TMOD|=0X01;
TH0=0XFC;
TL0=0X18;
ET0=1;
EA=1;
TR0=1;
}
void main()
{
Timer0Init();
while(1)
{
keyscan();
}
}
void Timer0() interrupt 1
{
static u16 i;
TH0=0XFC;
TL0=0X18;
if(flag==1)
{
flag=0;
i++;
if(i==5000)
{
i=0;
led=1;
}
}
}
|