供大家参考,有不懂的可以问我,QQ#include#defineuiintunsigninted#defineucharunsigniedcharuity,countucharpro//*驱动电机调速*//ucharfinish=0;//停车标志SBITLE1=P10;//*Left传感器*/sbitle2=P11;sbitle3=p1^2;sbitle4=p1^3;sbitle5=p1^4;sbitle6=p1^5;sbitmid=p1^6;//*Middle传感器*//sbitri6=P17;sbitri5=p2^3;sbitri4=p2^4;sbitri3=p2^5;sbitri2=p2^6;sbitri1=p2^7;//*Right传感器*/sbitena=p20;//驱动电机PWM//sbitmot1=p21;//电机控制//sbitmot2=p22;sbitpwm=p3^5;//舵机PWM//sbitbz=P37;//障碍管初始化{TMOD=0x11;//设置双定时器EA=1;TR0=1;TR1=1;TH0=0x0B1//设置定时初始值,下载一个定时器计算软件,TL0=0x0E0TH1=/256;TL1=%6ET0=1;ET1=1;ENA=1;}voiddelay//延迟函数{uchara,b,c;forforfor}voiddelay2{uchara,b,c;forforfor}Voidqctyp/光电当管道完全无状态时,会脱离轨道,读取之前的状态{LE1=P10;le2=p1^1;le3=p1^2;le4=p1^3;le5=p1^4;le6=p1^5;mid=p1^6;ri6=p1^7;ri5=p2^3;ri4=p2^4;ri3=p2^5;ri2=p2^6;ri1=p2^7;}void//正向函数{pro=y;//变量y是改变车速,这里的范围是0-39moto1=1;moto2=0;}voidback//back函数{pro=z;//改变z可以改变行驶速度moto1=0;moto2=1;}voidDJ///舵机控制{PWM=1;延迟;//改变M可以改变转向器的转向角度,PWM=0;}voidcheck_stop//为了检查终点线,我用了13对管道,自己分析了8个管道的停车状态{ucharstart_flagif


文章TAG:tcrt5000  传感器  光电  tcrt5000光电传感器  
下一篇