#include "CarDrive.h"
//左电机正转
void LeftMotorCorotation(void)
{
LeftMotor_1 = 1;
LeftMotor_2 = 0;
}
//左电机反转
void LeftMotorRollback(void)
{
LeftMotor_1 = 0;
LeftMotor_2 = 1;
}
//右电机正转
void RightMotorCorotation(void)
{
RightMotor_1 = 1;
RightMotor_2 = 0;
}
//右电机反转
void RightMotorRollback(void)
{
RightMotor_1 = 0;
RightMotor_2 = 1;
}
//小车前进
void CarGoAhead(void)
{
LeftMotorCorotation();
RightMotorRollback();
}
//小车慢速左拐
void CarTurnLeft_Low(void)
{
LeftMotor_1 = 0;
LeftMotor_2 = 0;
RightMotorRollback();
}
//小车慢速右拐
void CarTurnRight_Low(void)
{
RightMotor_1 = 0;
RightMotor_2 = 0;
LeftMotorCorotation();
}
//小车快速左拐
void CarTurnLeft_High(void)
{
LeftMotorRollback();
RightMotorRollback();
}
//小车快速右拐
void CarTurnRight_High(void)
{
LeftMotorCorotation();
RightMotorCorotation();
}
//小车道路判断
void CarRoadJudge(void)
{
if(LeftPhotoelectricCell_1&&(!LeftPhotoelectricCell_2)&&(!RightPhotoelectricCell_2)&&RightPhotoelectricCell_1)
CarGoAhead();
if(LeftPhotoelectricCell_1&&(!LeftPhotoelectricCell_2)&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
CarGoAhead();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&(!RightPhotoelectricCell_2)&&RightPhotoelectricCell_1)
CarGoAhead();
if((!LeftPhotoelectricCell_1)&&(!LeftPhotoelectricCell_2)&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
CarTurnLeft_Low();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&(!RightPhotoelectricCell_2)&&(!RightPhotoelectricCell_1))
CarTurnRight_Low();
if((!LeftPhotoelectricCell_1)&&LeftPhotoelectricCell_2&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
CarTurnLeft_High();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&RightPhotoelectricCell_2&&(!RightPhotoelectricCell_1))
CarTurnRight_High();
if(LeftPhotoelectricCell_1&&LeftPhotoelectricCell_2&&RightPhotoelectricCell_2&&RightPhotoelectricCell_1)
//CarTurnRight_Low();
CarGoAhead();
if((!LeftPhotoelectricCell_1)&&(!LeftPhotoelectricCell_2)&&(!RightPhotoelectricCell_2)&&(!RightPhotoelectricCell_1))
CarGoAhead();
}
#ifndef _CarDrive_H_
#define _CarDrive_H_
#include
#define uint unsigned int
#define uchar unsigned char
sbit LeftMotor_1 = P0^0;
sbit LeftMotor_2 = P0^1;
sbit RightMotor_1 = P0^2;
sbit RightMotor_2 = P0^3;
sbit LeftPhotoelectricCell_1 = P3^0;
sbit LeftPhotoelectricCell_2 = P3^1;
sbit RightPhotoelectricCell_2 = P3^2;
sbit RightPhotoelectricCell_1 = P3^3;
void CarGoAhead(void);
//void CarBackOff(void);
void CarTurnLeft_Low(void);
void CarTurnRight_Low(void);
void CarTurnLeft_High(void);
void CarTurnRight_High(void);
//void CarBrake(void);
void CarRoadJudge(void);
#endif