大家帮忙看下怎么按键跳出这个死循环,又不影响死循环的运行
{
while(1) //无限循环
{
if(Left_B_led==1&&Right_B_led==1) //前面无物体时
run();
else
{
if(Right_B_led==0&&Left_B_led==0) //两边检测到红外 小车后退
{
delay(100);
backrun(); //调用电机向后转函数
}
if(Right_B_led==1&&Left_B_led==0)
{ Left_moto_go;
Right_moto_Stop; }
if(Right_B_led==0&&Left_B_led==1)
{ Right_moto_go;
Left_moto_Stop; } }
if (l==0) break; } }
void main(void)
{
m=0;
f=0;
IT1=1;
EX1=1;
TMOD=0x11;
TH0=0;
TL0=0;
TR0=1;
EA=1;
delay(100);
while(1) /*无限循环*/
{
if(IrOK==1)
{
switch(Im[2])
{
case 0x18:
l=0;
run(); //前进
break;
case 0x52:
l=1;
backrun(); //后退
break;
case 0x5a:
l=0;
leftrun(); //左转
break;
case 0x08:
l=0;
rightrun(); //右转
break;
case 0x1C:
l=0;
stoprun(); //停止
break;
case 0x45:
l=1;
xunji();
break;
case 0x46:
l=1;
mofashou();
break;
case 0x47:
l=1;
bizhang();
break;
default:break;
}
IrOK=0;
}
}
}
建议小编用定时器去实现void mofashou(void)里面的动作
uchar run_flag=0; //DD?ˉ×′ì? 0?a2??ˉ×÷?£1?a′?1¤×÷
uchar backrun_flag=0;
uchar leftrun_flag=0;
uchar rightrun_flag=0;
void mofashou(void)
{
{
if(Left_B_led==1&&Right_B_led==1)
{
run_flag=1;
backrun_flag=0;
leftrun_flag=0;
rightrun_flag=0;
}
{
if(Right_B_led==0&&Left_B_led==0)
{
run_flag=0;
backrun_flag=1;
leftrun_flag=0;
rightrun_flag=0;
}
if(Right_B_led==1&&Left_B_led==0)
{
run_flag=0;
backrun_flag=0;
leftrun_flag=1;
rightrun_flag=0;
}
if(Right_B_led==0&&Left_B_led==1)
{
run_flag=0;
backrun_flag=0;
leftrun_flag=0;
rightrun_flag=1;
}
void time0(void) interrupt 1 using 1
{
//-----------------------------------------------------
if((run_flag)||(backrun_flag)||(rightrun_flag)||(leftrun_flag))
{
if(run_flag)
{
run();
}
else
if(backrun_flag)
{
backrun();
}
else
if(rightrun_flag)
{
rightrun();
}
else
if(leftrun_flag)
{
leftrun();
}
}