第2个回答 2014-09-20
/***µç»ú¿ØÖÆÒý½Å*****/
sbit ML1=P0^2;
sbit ML2=P0^3;
sbit MR1=P0^4;
sbit MR2=P0^5;
/*****ʹÄܶË******/
sbit ENA=P0^0;
sbit ENB=P0^1;
void delays(unsigned int ms)
{
unsigned int i;
while(ms--)
{
for(i=0;i<114;i++);
}
}
void stop()
{
ML1=0;
ML2=0;
MR1=0;
MR2=0;
}
void init()
{
ENA=1;
ENB=1;
num=200;
TMOD=0x02;
EA=1;
ET0=1;
TH0=145;
TL0=145;
TR0=1;
uart1_init();
}
void left(bit f)
{
if(f)
{
ML1=1;
ML2=0;
}
else
{
ML1=0;
ML2=1;
}
}
void right(bit f)
{
if(f)
{
MR1=1;
MR2=0;
}
else
{
MR1=0;
MR2=1;
}
}
void cl()
{
hightL=9;
hightR=199;
right(1);
left(1);
}
void cr()
{
hightL=199;
hightR=9;
right(1);
left(1);
}
void bcl()
{
hightL=9;
hightR=199;
right(0);
left(0);
}
void bcr()
{
hightL=199;
hightR=9;
right(0);
left(0);
}
void turnR()
{
hightL=150;
hightR=140;
right(0);
left(1);
}
void turnL()
{
hightR=150;
hightL=140;
right(1);
left(0);
}
void go()
{
hightR=189;
hightL=199;
left(1);
right(1);
}
void back()
{
hightR=189;
hightL=199;
left(0);
right(0);
}
void main()
{
init();
go();
}
void time0() interrupt 1
{
TR0=0;
if(count==hightL)
{
ENA=0;
}
if(count==hightR)
{
ENB=0;
}
if(count==num)
{
count=0;
ENA=1;
ENB=1;
}
count++;
TR0=1;
}本回答被提问者和网友采纳