//======================================================================
// (C) COPYRIGHT 2010 THU
// ALL RIGHTS RESERVED
// The entire notice above must be reproduced on all authorized copies.
//======================================================================
//============================================================
// zhylaker编写
//
// 工程名称: car_follow.aps
// 功能描述: 智能小车循迹
// IDE环境: keilc uv3 8.16
// 操作系统: windows xp sp3
// 涉及的库:
// 组成文件: main.c
// 硬件连接: 左---中---右
// P0.0--P0.1--P0.2
// 压线:P0n = 0
// 离线:P0n = 1
//
// 晶振7.3728MHz
// 维护记录: 2010年4月3日 v1.0
//======================================================================
//======================================================================
// 文件名称: main.c
// 功能描述: 智能小车循迹
// 维护记录: 2010年4月3日 v1.0
//======================================================================
#include "car.h"
//======================================================================
// 函 数: void sensor_init(void)
// 实现功能: 循迹传感器初始化
// 入口参数: 无
// 返回 值: 无
//======================================================================
void sensor_init(void)
{
}
//======================================================================
// 函 数: void car_follow(void)
// 实现功能: 循迹
// 入口参数: 无
// 返回 值: 无
//======================================================================
void car_follow(void)
{
unsigned int temp;
temp = P0&0x07;
switch(temp)
{
case 0x00: // 全部压线,原转
car_right();
while((P0&0x07) != 0x05);
car_ahead();
break;
case 0x01: // 右中压线,右转
car_right();
while((P0&0x07) != 0x05);
car_ahead();
break;
case 0x02: // 左右压线,直走
car_ahead();
break;
case 0x03: // 右压线, 右转
car_right();
while((P0&0x07) != 0x05);
car_ahead();
break;
case 0x04: // 左中压线,左转
car_left();
while((P0&0x07) != 0x05);
car_ahead();
break;
case 0x05: // 中间压线,直行
car_ahead();
break;
case 0x06: // 左压线, 左转
car_left();
while((P0&0x07) != 0x05);
car_ahead();
break;
case 0x07: // 全不压线,直行
car_ahead();
break;
}
}
//======================================================================
// 函 数: int main(void)
// 实现功能: 主函数 循迹
// 入口参数: 无
// 返回 值:
//======================================================================
int main(void)
{
car_init();
sensor_init();
car_ahead(); // 小车启动
while(1)
{
car_follow();
}
}