51跟踪汽车纸
# defineuchar?未签名?茶
#定义?uint?未签名?(同Internationalorganizations)国际组织
sbit?p1_o=p1^0;
sbit?p1_1=p1^1;
sbit?p1_2=p1^2;
sbit?p1_3=p1^3;
sbit?p0_2=p0^1;
sbit?p0_3=p0^2;
作废?delaym1(uint?z)
{
uint?我;
for(I = 0;我& ltz;i++);
}
作废?主要(无效)
{?
while(1);
{
?TRIG = 1;
?延时(1);
?TRIG = 0;
?while(ECHO = = 0);
?while(ECHO==1)?a++;?//a每次加1,时间大概是21us。
?延迟(30);
?a =((340 * a * 21)/1000)/2;
?显示();
?scan();
?z = a;
?a = 0;
?延迟(200);}
作废?zhiliudianji1()
{
uint?I,j;
P0 = 0X00?
//走直线
for(I = 0;我& lt200;i++)
{?for(I = 0;我& lt500;i++)
?{?
?P0 _ O = 1;
?P0 _ 1 = 0;
??delay m 1(280);
?P0 _ O = 0;
?P0 _ 1 = 0;
?P0 _ 2 = 1;
?P0 _ 3 = 0;
?delay m 1(420);
?P0 _ 2 = 0;
?P0 _ 3 = 0;
}
P0 = 0X00
?delay m 1(30000);
?delay m 1(30000);}
//向右转
作废?直流店2()
{ for(j = 0;j & lt300;j++)
{ P0 _ O = 1;
P0 _ 1 = 0;
?delay m 1(300);
?P0 _ O = 0;
?P0 _ 1 = 0;
P0 _ 2 = 1;
?P0 _ 3 = 0;
?delay m 1(160);
?P0 _ 2 = 0;
?P0 _ 3 = 0;
?}
P0 = 0X00
delay m 1(30000);
delay m 1(30000);
//向左转
作废?直流店集3()
{ for(I = 0;我& lt600;i++)
?{?
?P0 _ O = 1;
?P0 _ 1 = 0;
??delay m 1(155);
?P0 _ O = 0;
?P0 _ 1 = 0;
?P0 _ 2 = 1;
?P0 _ 3 = 0;
?delay m 1(650);
?P0 _ 2 = 0;
?P0 _ 3 = 0;
}
P0 = 0X00
delay m 1(30000);
?delay m 1(30000);}
P0 = 0x00
while(1);
}
}
作废?主要(无效)
{?
while(1)
{
?TRIG = 1;
?延时(1);
?TRIG = 0;
?while(ECHO = = 0);
?while(ECHO==1)?a++;?//a每次加1,时间大概是21us。
?延迟(30);
?a =((340 * a * 21)/1000)/2;
如果(a==50)
esle
{?作废?zhi Liu dianji 3();}
延迟(200);
作废?zhiliu dianji 1();
?z = a;
?a = 0;
?延迟(200);
}