void main ()
{
init();
TMOD=0x10; // T0和T1 的工作方式为方式1
TH1=(65535-46082)/256; // 装入初值 50ms
TL1=(65535-46082)%256;
EA=1; // 开总中断
ET1=1; // 开T1 中断
TR1=1; // 启动T1中断
while (1)
{
/* Motor go , stop if there is something blocking the way*/
while ( sensor03)
// while (!flag)
{
for (count00=230;count00>0;count00--)
{
if (relay_read == 0)
relay_send=1;
motor02=0; /* PWM */
motor01=0;
delayms0(10);
motor02=1;
// delayms0(preset_num);
motor01=1;
delayms0(20);
/* To check sensor01 and sensor02 good or not */
if ( sensor01 == 0)
led0=~led0;
else
led1=~led1;
if ( sensor02 == 0)
led2=~led2;
else
led3=~led3;
/* To record both motor V(sudu) */
if (sensor01==0)
{
delayms0(100);
if (sensor01==0)
count01++;
if( count01==130)
count01=0;
circle01++;
}
if (sensor02==0)
{
delayms0(100);
if (sensor02==0)
count02++;
if( count02==130)
count02=0;
circle02++;
}
}
/* To control preset_num , then car goes on line*/
while (circle02 > circle01)
{
motor02=0; /* PWM */
motor01=0;
delayms0(1);
motor01=1;
delayms0(20);
if (sensor01==0)
{
delayms0(100);
if (sensor01==0)
count01++;
if( count01==130)
count01=0;
circle01++;
}
}
}
motor01=0;
motor02=0;
/* LD E on, if motor stops */
while (!sensor03)
{
led0=~led0;
delayms0(6500);
write_time(0x80+8,circle01);
write_time(0x80+0x40+8,circle02);
}