#include
#define uchar unsigned char
#define uint unsigned int
sbit L1=P1^0; //左边里侧寻迹灯
sbit L2=P1^1; //左边外侧寻迹灯
sbit R2=P1^2; //右边外侧寻迹灯
sbit R1=P1^3; //右边里侧寻迹灯
sbit IN1=P0^0;
sbit IN2=P0^1;
sbit IN3=P0^2;
sbit IN4=P0^3;
void init()
{
TMOD=0x02;
TH0=6;
TL0=6;
EA=1;
ET0=1;
TR0=1;
IN1=1;
IN2=1;
IN3=1;
IN4=1;
}
void detect()
{
if((R1==1&&L1==1)||(R2==0&&L2==0)){
IN1=0;
IN3=0;
}
if(R1==0&&L1==0){
IN1=1;
IN3=1;
}
if((R1==1&&L1==0)||(R2==1&&L2==0)){
IN1=1;
IN3=0;
}
if((R1==0&&L1==1)||(R2==0&&L2==1)){
IN3=1;
IN1=0;
}
}
void main()
{
init();
while(1){
detect();
}
}
void T0_tine() interrupt 1
{
TH0=6;
TL0=6;
if((R1==1&&L1==1)||(R2==0&&L2==0)){
IN1=0;
IN3=0;
}
if((R1==1&&L1==0)||(R2==1&&L2==0)){
IN1=1;
IN3=0;
}
if((R1==0&&L1==1)||(R2==0&&L2==1)){
IN3=1;
IN1=0;
}
}