P0.4外接独立式按键。按下时低电平有效。
想法一:(失败)这个方法我感觉好些,但实验结果失败
void main ()
{
SP=0x5f;
TMOD=0x01;
TH0 = 0x3c;
TL0 = 0xb0;
TR0=1;
ET1 = 1;
ET0= 1;
EA= 1;
req= 0;
busy= 1;
while (1)
{
if (flag_b==1)
{
if (P0_4==0)
{
delay(4);
if (P0_4==0)
{
////do something 2,用方法一只能something 2只能做一次??
why?????
}
}
flag_b=0;
}
}
void t0(void) interrupt 1 using 0
{
bit flag;
uchar t02s;
TH0 = 0x3c;
TL0 = 0xb0;
TR0=1;
t02s++;
if(t02s==2)
{
t02s=0;
flag=~flag;
}
if(flag==1)
{
/////do something 1
flag_a=1
}
}
想法二:(实验成功,但不知道妥不妥,合理不合理,自己感觉在中断里检测按键不是很合理)
void main
{
TMOD=0x01;
TH0 = 0x3c;
TL0 = 0xb0;
ET1 = 1;
ET0= 1;
EA= 1;
req= 0;
busy= 1;
while (1);
}
void t0(void) interrupt 1 using 0
{
bit flag;
uchar t02s;
TH0 = 0x3c;
TL0 = 0xb0;
TR0=1;
t02s++;
if(t02s==2)
{
t02s=0;
flag=~flag;
}
if(flag==1)
{
///// first do something 1
if (P0_4==0)
{
TR0=0;///主要是这个 -————合理吗?
delay(4);
if (P0_4==0)
{
///// then do something 2
}
TR0=1;
}
}
} |