您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 电气安装工程 > 智能红外循迹小车程序
#includereg52.h#defineuintunsignedint#defineucharunsignedchar#defineulongunsignedlongsbityou_2=P2^0;//红外探测端口定义sbityou_1=P2^1;sbitzhong=P2^2;sbitzuo_1=P2^3;sbitzuo_2=P2^4;sbitCG=P0^1;sbitDC=P0^0;ucharcodeL_F[8]={0x10,0x30,0x20,0x60,0x40,0xc0,0x80,0x90};//左电机正转ucharcodeL_B[8]={0x90,0x80,0xc0,0x40,0x60,0x20,0x30,0x10};//左电机反转ucharcodeR_F[8]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};//右电机正转ucharcodeR_B[8]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};//右电机反转ucharcodeB_F[8]={0x91,0x83,0xc2,0x46,0x64,0x2c,0x38,0x19};//左反右正ucharcodeF_B[8]={0x19,0x38,0x2c,0x64,0x46,0xc2,0x83,0x91};//左正右反ucharcodeduandian[8]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};//断电unsignedcharcodeqianjin[]={0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99};//前进unsignedcharh[]={0x11,0x33,0x22,0x66,0x44,0xcc,0x88,0x99};//uchari;voiddelay(uintz){uintk;uintj;for(k=0;kz;k++)for(j=0;j110;j++);}voidQJ(unsignedinti){for(i=0;i8;i++){P1=h[i]=qianjin[i];delay(13);}}voidDD(){P1=0x00;delay(300);}voidwtj(){while(1){if(P2==0xff){DD();delay(1000);break;}else{QJ(8);}}}voidYG_1(){unsignedchari;for(i=0;i8;i++){P1=h[i]=F_B[i];delay(10);}}voidZG_1(){unsignedchari;for(i=0;i8;i++){P1=h[i]=B_F[i];delay(10);}}voidbyg(){while(1){if(P2==0xfb)break;elseif(P2==0xf9)break;elseif(P2==0xfd)break;/*if(P2^0==0)break;elseif(P2^1==0)break;/*elseif(P2^2==0)break;elseif(P2^3==0)break;elseif(P2^4==0)break;*/elseYG_1();}}voidbzg(){while(1){if(P2==0xfb)break;elseif(P2==0xf3)break;elseif(P2==0xf7)break;/*if(P2^0==0)break;elseif(P2^1==0)break;elseif(P2^2==0)break;if(P2^3==0)break;elseif(P2^4==0)break;*/elseZG_1();}}voidYG_2(){//unsignedchari;//unsignedcharg;if(P2==0xfa){//delay(4000);wtj();byg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=F_B[i];delay(20);}}*/}elseif(P2==0xf2){//delay(4000);wtj();byg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=F_B[i];delay(20);}}*/}elseif(P2==0xf6){//delay(4000);wtj();byg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=F_B[i];delay(20);}}*/}elseif(P2==0xf4){//delay(4000);wtj();byg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=F_B[i];delay(20);}}*/}else;}voidZG_2(){//unsignedchari;//unsignedcharg;if(P2==0xeb){//delay(4000);wtj();bzg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=B_F[i];delay(20);}}*/}elseif(P2==0xe9){//delay(4000);wtj();bzg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=B_F[i];delay(20);}}*/}elseif(P2==0xed){//delay(4000);wtj();bzg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=B_F[i];delay(20);}}*/}elseif(P2==0xe5){//delay(4000);wtj();bzg();/*for(g=0;g40;g++){for(i=0;i8;i++){P1=B_F[i];delay(20);}}*/}else;}voidZG(){unsignedchari;for(i=0;i8;i++){P1=h[i]=R_F[i];delay(11);}}voidYG(){unsignedchari;for(i=0;i8;i++){P1=h[i]=L_F[i];delay(11);}}/*voidHT(){unsignedchari;for(i=0;i8;i++){P1=houtui[i];delay(55);}}*/voidzd(){while(1){if(P2==0xe0)QJ(8);elseif(P2==0xff){while(1){DD();}}else{QJ(80);if(P2==0xff){while(1){DD();}}else{DC=0;break;break;}}}}voidzd1(){while(1){if(P2==0xe0)QJ(8);elseif(P2==0xff){while(1){DD();}}else{QJ(80);if(P2==0xff){while(1){DD();}}else{DC=0;break;}}}}voidhy(){unsignedchari;for(i=0;i8;i++){P1=h[i];delay(10);}}voidmain(){DC=1;while(1){QJ(8);if(P2!=0xff){DD();delay(9000);break;}}while(1){DC=1;if(CG==1){delay(9000);DC=1;while(1){switch(P2){case0xfb:QJ(8);break;//11011case0xf1:QJ(8);break;//10001case0xf3:QJ(8);break;//10011case0xf7:ZG();break;//10111case0xe7:ZG_1();break;//00111case0xef:ZG_1();break;//01111case0xe3:ZG_1();break;//00011case0xe1:ZG_1();break;//00001case0xf9:QJ(8);break;//11001case0xfd:YG();break;//11101case0xfc:YG_1();break;//11100case0xfe:YG_1();break;//11110case0xf8:YG_1();break;//11000case0xf0:YG_1();break;//10000case0xfa://11010QJ(16);//delay(4000);YG_2();//f7break;case0xf2://10010QJ(16);//delay(4000);YG_2();break;case0xf6://10110QJ(16);//delay(4000);YG_2();break;case0xf4://10100QJ(16);//delay(4000);YG_2();break;case0xeb://01011QJ(16);//delay(4000);ZG_2();//fdbreak;case0xe9://01001QJ(16);//delay(4000);ZG_2();break;case0xed://01101QJ(16);//delay(4000);ZG_2();break;case0xe5://00101QJ(16);//delay(4000);ZG_2();break;case0xe0:zd1();break;//00000case0xff:hy();break;//11111default:QJ(8);break;}}}else{switch(P2){case0xfb:QJ(8);break;//11011case0xf1:QJ(8);break;//10001case0xf3:QJ(8);break;//10011case0xf7:ZG();break;//10111case0xe7:ZG_1();break;//00111case0xef:ZG_1();break;//01111case0xe3:ZG_1();break;//00011case0xe1:ZG_1();break;//00001case0xf9:QJ(8);break;//11001case0xfd:YG();break;//11101case0xfc:YG_1();break;//11100case0xfe:YG_1();break;//11110case0xf8:YG_1();break;//11000case0xf0:YG_1();break;//10000case0xfa://11010QJ(16);//delay(4000);YG_2();//f7break;case0xf2://10010QJ(16);//delay(4000);YG_2();break;case0xf6://10110QJ(16);//delay(4000);YG_2();break;case0xf4://10100QJ(16);//delay(4000);YG_2();break;case0xeb://01011QJ(16);//delay(4000);ZG_2();//fdbreak;case0xe9://01001QJ(16);//delay(4000);ZG_2();break;case0xed://01101QJ(16);//delay(4000);ZG_2();break;case0xe5://00101QJ(16);//delay(4000);ZG_2();break;case0xe0:zd();break;//00000case0xff:hy();break;//11111default:QJ(8);break;}}}}
本文标题:智能红外循迹小车程序
链接地址:https://www.777doc.com/doc-2201976 .html