//定時器中斷
void tm0_isr() interrupt 1 using 1
{
tim0[0]++;
if(Dista1>110)//加速正轉
{
tim0[3]=(Dista1-80);
tim0[2]=65536-FOSC/(tim0[3]*200);
TL0=tim0[2];
TH0=tim0[2]>>8;
switch(tim0[0])
{
case 1: ONA=0;ONB=1;ONC=1;OND=1;break;
case 2: ONA=1;ONB=0;ONC=1;OND=1;break;
case 3: ONA=1;ONB=1;ONC=0;OND=1;break;
case 4: ONA=1;ONB=1;ONC=1;OND=0;tim0[0]=0; break;
}
}
if(Dista1>80&&Dista1<140)//勻速正轉
{
tim0[2]=65536-FOSC/3000;
TL0=tim0[2];
TH0=tim0[2]>>8;
switch(tim0[0])
{
case 1: ONA=0;ONB=1;ONC=1;OND=1;break;
case 2: ONA=1;ONB=0;ONC=1;OND=1;break;
case 3: ONA=1;ONB=1;ONC=0;OND=1;break;
case 4: ONA=1;ONB=1;ONC=1;OND=0;tim0[0]=0; break;
tim0[2]=65536-FOSC/(tim0[3]*200);
TL0=tim0[2];
TH0=tim0[2]>>8;
switch(tim0[0])
{
case 1: ONA=1;ONB=1;ONC=0;OND=1;break;
case 2: ONA=1;ONB=0;ONC=1;OND=1;break;
case 3: ONA=0;ONB=1;ONC=1;OND=1;break;
case 4: ONA=1;ONB=1;ONC=1;OND=0;tim0[0]=0;break;
}
}
else if(Dista1<=50)//勻速反轉
{
tim0[2]=65536-FOSC/3000;
TL0=tim0[2];
TH0=tim0[2]>>8;
switch(tim0[0])
{
case 1: ONA=1;ONB=1;ONC=0;OND=1;break;
case 2: ONA=1;ONB=0;ONC=1;OND=1;break;
case 3: ONA=0;ONB=1;ONC=1;OND=1;break;
case 4: ONA=1;ONB=1;ONC=1;OND=0;tim0[0]=0;break;
}
}
else if(Dista1>50&&Dista1<80)//不轉
{
ONA=1;ONB=1;ONC=1;OND=1;
tim0[0]=0;
}
else if(Dista1>140)// 勻速轉
{
tim0[2]=65536-FOSC/6000;
TL0=tim0[2];
TH0=tim0[2]>>8;
switch(tim0[0])
{
case 1: ONA=0;ONB=1;ONC=1;OND=1;break;
case 2: ONA=1;ONB=0;ONC=1;OND=1;break;
case 3: ONA=1;ONB=1;ONC=0;OND=1;break;
case 4: ONA=1;ONB=1;ONC=1;OND=0;tim0[0]=0;break;