#includereg51.h#definesen_portP1sbitSEN1=P1^0;sbitSEN2=P1^1;sbitEN1=P2^2;sbitA1=P1^1;sbitA2=P1^2;sbitEN2=P2^5;sbitB1=P1^3;SbitB2=P1^4;voiddelay(intn)//延时子程序{unsignedchari,j,k;for(i=n;i0;i--)for(j=100;j0;j--)for(k=200;k0;k--);}unsignedcharsensor_inp(){unsignedcharsensor;sensor=sen_port;sensor&=0x03;P0=sensor;returnsensor;}voidforward()//twomotosareruningforward{IN1=1;IN2=0;IN3=1;IN4=0;EN1=1;EN2=1;}voidbackward()//twomotosareruningbackward{IN1=0;IN2=1;IN3=0;IN4=1;EN1=1;EN2=1;}voidturn_left()//leftmotoisruning,butrightmotoisbrake{IN1=1;IN2=0;IN3=0;IN4=0;EN1=1;EN2=1;}voidrotate_left()//rightmotoisruningforward,andleftmotoisrunningbackward{IN1=1;IN2=0;IN3=0;IN4=1;EN1=1;EN2=1;}voidturn_right()//rightmotoisruning,butleftmotoisbrake{IN1=0;IN2=0;IN3=1;IN4=0;EN1=1;EN2=1;}voidrotate_right()//leftmotoisrunningforward,andrightmotoisrunningbackward{IN1=0;IN2=1;IN3=1;IN4=0;EN1=1;EN2=1;}voidfree()//twomotosisfree{IN1=0;IN2=0;IN3=0;IN4=0;EN1=0;EN2=0;}voidstop()//twomotosstop{IN1=1;IN2=1;IN3=1;IN4=1;EN1=1;EN2=1;}voidmain(void){delay(10);P0=0x55;while(1){//P0=P1;//delay(100);forward();//delay(100);stop();delay(100);backward();delay(100);stop();delay(100);turn_left();delay(100);stop();delay(100);turn_right();delay(100);stop();delay(100);rotate_left();delay(100);stop();delay(100);rotate_right();delay(100);stop();delay(100);stop();delay(20);forward();delay(20);backward();delay(20);/**/}}