#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar pro_left,pro_right,i=0,j=0,u,v;
uintq,b;
sbit a=P2^4;
sbit left1=P2^0;
sbit left2=P2^1;
sbit right1=P2^2;
sbit right2=P2^3;
sbit left_red1=P1^2;
sbit left_red2=P1^3;
sbit right_red1=P1^5;
sbit right_red2=P1^7;
uint temp1=0;
uint temp2=0;
uint temp3=0;
uint temp4=0;
void delay(uintz)
{
uchar k;
while(z--)
{for(k=o;k<121;k++);}
}
void int()
{
left_red1=1;
left_red2=1;
right_red1=1;
right_red2=1;
TMOD=0x01;
TH0=(65536-1000)/256;
TH0=(65536-1000)%256;
EA=1;
ET0=1;
TR0=1;
left1=0;
left2=1;
right1=1;
right2=0;
}
void time0(void)interrupt1
{
i++;
j++;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
}
void straight()
{
pro_right=39;
pro_left=39;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
}
void turn_left2()
{
pro_right=39;
pro_left=0;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
u=50000;
v=400;
}
void turn_left1()
{
pro_right=39;
pro_left=0;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
}
void turn_left3()
{
pro_right=39;
pro_left=9;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
}
void turn_right2()
{
pro_right=0;
pro_left=39;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
u=50000;
v=400;
}
void turn_right1()
{
pro_right=0;
pro_left=39;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
}
void turn_right3()
pro_right=9;
pro_left=39;
temp1=0;
temp2=1;
temp3=1;
temp4=0;
}
void turn_back()
{
temp1=0;
temp2=0;
temp3=0;
temp4=1;
pro_right=39;
pro_left=39;
}
void infrared()
{
uchar flag;
if(left_red1==0&&left_red2==0&&right_red1=0&&right_red2=0)straight();
else
if(left_red1==0&&left_red2==0)turn_left1();
else
if(right_red1==0&&right_red2==0)turn_right1();
else
if(left_red1==0)turn_left3();
else
if(right_red1==0)turn_right3();
else
if(left_red2==0)turn_left1();
else
if(right_red2==0)turn_right1();
else
straight();
}
uint w;
void main(void)
{
q=0;
b=0;
left2=0;
right1=0;
while(a==1)
{
}
for(q=0;q<8;q++)//我怀疑这地方出错了//
for(b=0;b<20000;b++)
{
}
int();
delay(100);
i=0;
j=0;
u=0;
v=0;
pro_left=39;
pro_right=39;
while(1)
{
infrared();
if(i>=pro_left){left1=0;left2=0;}
if(i==40){left1=temp1;left2=temp2;i=0;}
if(j>=pro_right){right1=0;right2=0;}
if(j==40){right1=temp3;right2=temp4;j=0;}
}
}
void int0(void)interrupt 0
{
}
牛人好多
再帮忙看下这个又是错在哪儿呢?