1.小车组装图:
2.code:
//main.c
#include "motor.h"
#include "delay.h"
#include "uart.h"void main()
{
UartInit();
while(1){
}
}
//moto.hvoid goRight();
void goLeft();
void goForward();
void goBack();
void stop();//delay.h
void Delay1000ms();
//uart.h
void UartInit(void);
//moto.c
#include "reg52.h"
sbit RightCon1A = P3^2;
sbit RightCon1B = P3^3;sbit LeftCon1A = P3^4;
sbit LeftCon1B = P3^5;void goForward()
{
LeftCon1A = 0;
LeftCon1B = 1;
RightCon1A = 0;
RightCon1B = 1;
}void goRight()
{
LeftCon1A = 0;
LeftCon1B = 1;
RightCon1A = 0;
RightCon1B = 0;
}
void goLeft()
{
LeftCon1A = 0;
LeftCon1B = 0;
RightCon1A = 0;
RightCon1B = 1;
}void goBack()
{
LeftCon1A = 1;
LeftCon1B = 0;
RightCon1A = 1;
RightCon1B = 0;
}void stop()
{
LeftCon1A = 0;
LeftCon1B = 0;
RightCon1A = 0;
RightCon1B = 0;
}