#include
#define uint unsigned int
sbit Fir=P3^2; //外中断0
sbit Sec=P1^2;
sbit Thi=P1^3;
sbit For=P1^4;
sbit Fif=P3^3; //外中断1
//右轮
sbit IN1 = P2^1;
sbit IN2 = P2^2;
//左轮
sbit IN3 = P2^3;
sbit IN4 = P2^4;
#define tLeft {IN1=0;IN2=1;IN3=0;IN4=0;}
#define tALeft {IN1=0;IN2=1;IN3=0;IN4=1;}
#define tRigh {IN1=0;IN2=0;IN3=1;IN4=0;}
#define tARigh {IN1=1;IN2=0;IN3=1;IN4=0;}
#define Go {IN1=0;IN2=1;IN3=1;IN4=0;}
#define Stop {IN1=0;IN2=0;IN3=0;IN4=0;}
#define GoBack {IN1=1;IN2=0;IN3=0;IN4=1;}
void delays(uint t)
{
uint x,y;
for(x=t; x>0; x--)
for(y=110; y>0; y--);
}
void init()
{
EA=1;
EX0=1;
EX1=1;
IT0=1; //下降沿触发
IT1=1;
}
void GoOnline()
{
uint flag;
if(Sec==0)
{
tLeft
flag=1;
}
if(For==0)
{
tRigh
flag=0;
}
if(Thi==0)
{
if(flag==0)
{
tLeft
}
else
{
tRigh
}
}
if((Thi==0)&&(Sec==0)&&(For==0))
Go
}
void main()
{
init();
Go
while(1)
{
GoOnline();
}
}
void INT_0() interrupt 0
{
EA=0;
if((Thi==0)&&(Sec==0)&&(For==0))
{
Go
EA=1;
return;
}
tLeft//GoBack
delays(2);
tALeft
//delays(25);
//tLeft
while(Thi!=0);
EA=1;
}
void INT_1() interrupt 2
{
EA=0;
if((Thi==0)&&(Sec==0)&&(For==0))
{
Go
EA=1;
return;
}
tRigh//GoBack
delays(2);
tARigh
//delays(25);
//tRigh
while(Thi!=0);
EA=1;
}