├── LICENSE ├── README.md ├── SmartTracingCar.c ├── car.JPG ├── design.png ├── map.png └── tou.c /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SmartTracingCar 2 | 一个基于51单片机的智能寻迹小车
3 | 4 | ![image](https://github.com/linyacool/SmartTracingCar/blob/master/car.JPG)
5 | 6 | ![image](https://github.com/linyacool/SmartTracingCar/blob/master/design.png)
7 |  部分地图
8 | ![image](https://github.com/linyacool/SmartTracingCar/blob/master/map.png)
9 | -------------------------------------------------------------------------------- /SmartTracingCar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "intrins.h" 3 | 4 | 5 | #define BLACK 0 6 | #define WHITE 1 7 | 8 | //---------------------------------ADC查询部分说明------------------------------------ 9 | #define FOSC 18432000L 10 | #define BAUD 9600 11 | 12 | #define ADC_POWER 0x80 13 | #define ADC_FLAG 0x10 14 | #define ADC_START 0x08 15 | #define ADC_SPEEDLL 0x00 16 | #define ADC_SPEEDL 0x20 17 | #define ADC_SPEEDH 0x40 18 | #define ADC_SPEEDHH 0x60 19 | #define uint unsigned int 20 | #define uchar unsigned char 21 | //---------------------------------ADC查询部分说明------------------------------------ 22 | typedef unsigned char BYTE; 23 | typedef unsigned int WORD; 24 | 25 | sbit L298_IN1=P2^1; 26 | sbit L298_IN2=P2^2; 27 | sbit L298_IN3=P2^3; 28 | sbit L298_IN4=P2^4; 29 | sbit L29B_ENA=P2^5; 30 | sbit L29B_ENB=P2^6; 31 | char L298_flag=0; 32 | sbit BSD=P3^7; 33 | sfr ADC_LOW2 = 0xBE; 34 | 35 | 36 | //-----------------------------------------传感器部分声明-------------------------------------------- 37 | #define uchar unsigned char 38 | #define uint unsigned int 39 | 40 | //char state ; 41 | unsigned char disbuf[4]; 42 | unsigned int ADC_select=0; //5路通道AD选择 43 | unsigned int ADC0_value; //0通道AD数据 44 | unsigned int ADC1_value; //1通道AD数据 45 | unsigned int ADC2_value; //2通道AD数据 46 | unsigned int ADC3_value; //3通道AD数据 47 | unsigned int ADC4_value; //4通道AD数据 48 | sbit LED=P0^2; 49 | sbit LY=P3^6; 50 | sbit GD=P3^2; 51 | sbit TEST=P3^7; 52 | 53 | unsigned int OUTPUT_select=0; //5路通道AD输出选择 54 | //声明 55 | void _delay_ms(unsigned int ms);//延时 56 | void InitUart();//初始化串口 57 | void SendUart(unsigned char dat);//串口发送一字节 58 | void ADC_Init(void);//初始化ADC 59 | //-----------------------------------------传感器部分声明-------------------------------------------- 60 | 61 | int gray[10]; 62 | int flag=0; 63 | int R; 64 | int last_color; 65 | int now_color; 66 | /*************前进*************/ 67 | void L298_forward(char speed_M2,char speed_M1,char timer) //speed_M1、speed_M2的范围为0~20;数值越大速度越大 68 | { 69 | int i,j; 70 | for(j=0;j