智能红外循迹小车程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#define uint unsigned int
#define uchar unsigned char
#define ulong unsigned long
sbit you_2=P2^0;//红外探测端口定义
sbit you_1=P2^1;
sbit zhong=P2^2;
sbit zuo_1=P2^3;
sbit zuo_2=P2^4;
sbit CG=P0^1;
sbit DC=P0^0;
uchar code L_F[8]= {0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90};//左电机正转uchar code L_B[8]= {0x90,0x80,0xc0,0x40,0x60,0x20,0x30,0x10};//左电机反转uchar code R_F[8]= {0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};//右电机正转uchar code R_B[8]= {0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};//右电机反转uchar code B_F[8]= {0x91,0x83,0xc2,0x46,0x64,0x2c,0x38,0x19};//左反右正uchar code F_B[8]= {0x19,0x38,0x2c,0x64,0x46,0xc2,0x83,0x91}; //左正右反
uchar code duandian[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//断电unsigned char code qianjin[]={0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99};//前进unsigned char h[]={0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99};//
uchar i;
void delay(uint z)
{
uint k ;
uint j;
for(k=0; k for(j=0; j<110; j++); } void QJ(unsigned int i) { for(i=0;i<8;i++) { P1=h[i]=qianjin[i]; delay(13); } } void DD() { P1=0x00; delay(300); } void wtj() { while(1) { if(P2==0xff) { DD(); delay(1000); break; } else { QJ(8);} } } void YG_1() { unsigned char i; for(i=0;i<8;i++) {P1=h[i]=F_B[i]; delay(10); } } void ZG_1() { unsigned char i; for(i=0;i<8;i++) {P1=h[i]=B_F[i]; delay(10); } } void byg() { while(1) { if(P2==0xfb) break; else if(P2==0xf9) break; else if(P2==0xfd) break; /*if(P2^0==0) break; else if(P2^1==0) break; /*else if(P2^2==0) break; else if(P2^3==0) break; else if(P2^4==0) break;*/ else YG_1(); } } void bzg() { while(1) { if(P2==0xfb) break; else if(P2==0xf3) break; else if(P2==0xf7) break; /*if(P2^0==0) break; else if(P2^1==0) break; else if(P2^2==0) break; if(P2^3==0) break; else if(P2^4==0) break;*/ else ZG_1(); } } void YG_2() { //unsigned char i; //unsigned char g; if(P2==0xfa) {//delay(4000); wtj(); byg(); /*for(g=0;g<40;g++) { for(i=0;i<8;i++) {P1=F_B[i]; delay(20); } } */ } else if(P2==0xf2) { //delay(4000); wtj(); byg(); /*for(g=0;g<40;g++) { for(i=0;i<8;i++) {P1=F_B[i]; delay(20); } }*/ } else if(P2==0xf6) { //delay(4000);