这是控制语言,麻烦看一下。有问题帮忙修改,
#include <reg52.h>
#include "hardware.h"
#include "motor_out.h"
#include "led_show.h"
/*-----------------------------------------------*/
//延时函数
void delay(int t)
{
int j;
while(t--)
{for(j=5;j>0;j--);}
}
/*-----------------------------------------------*/
//小车状态函数
/*直行*/
void CarGoAhead(void)
{
motor_l_g();
motor_r_g();
}
/*左拐*/
void CarTurnLeft(int s)
{
switch (s)
{
case 1:
//减慢的左转
motor_l_s();
motor_r_s();
delay(2);
motor_l_s();
motor_r_g();
delay(2);
break;
case 2:
//加快的左转
motor_l_b();
motor_r_g();
break;
default:
//正常的左转
motor_l_s();
motor_r_g();
break;
}
//end swich
}
/*右拐*/
void CarTurnRight(int s)
{
switch (s)
{
case 1:
//减慢的右转
motor_r_s();
motor_l_s();
delay(2);
motor_r_s();
motor_l_g();
delay(2);
break;
case 2:
//加快的右转
motor_r_b();
motor_l_g();
break;
default:
//正常的右转
motor_r_s();
motor_l_g();
break;
}
//end swich
}
/*-----------------------------------------------*/
//小车控制函数
void CarRoadJudge(void)
{
if((!Left)&&Center&&Right)CarTurnLeft(2);
//全力左转
if((!Left)&&(!Center)&&Right)CarTurnLeft(0);
//正常左转
if(Left&&(!Center)&&Right)CarGoAhead();
if((!Left)&&Center&&(!Right))CarGoAhead();
if(Left&&Center&&(!Right))CarTurnRight(2);
//全力右转
if(Left&&(!Center)&&(!Right))CarTurnRight(0);
//正常右转
if(Left&&Center&&Right)CarGoAhead();
if((!Left)&&(!Center)&&(!Right))CarGoAhead();
}
/*-----------------------------------------------*/
//主函数
void main(void)
{
while(1)
{
led_show();
CarRoadJudge();
//调试传感器时把这条注释掉
}
//
end while
}//
end main
/*-----------------------------------------------*/