欢迎来到天天文库
浏览记录
ID:40734309
大小:36.00 KB
页数:5页
时间:2019-08-06
《红外循迹小车c程序(舵机小车)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、#includesbitservo=P2^5;uintcontrol=12;uintjishu;uintpianchu;sbitzuo11=P3^4;//为0为左边正转sbitzuo12=P3^5;//为1为左边正转sbityou21=P3^6;//为1为右边正转sbityou22=P3^7;//为0为右边正转uintsp,speed=3;uintji=1,guang,bi;//判断循迹寻光变量uintstop1,stop2,stop3;voiddelay(uinta){uintb,
2、c;for(b=a;b>0;b--)for(c=115;c>0;c--);}voidqianjin()//可以当做延时函数来用{//P3=0x0f;//delay(speed);P3=0xf9;}voidinitial_T0(){TMOD=0x21;TH1=0x8c;TL1=0x8c;EA=1;ET1=1;TR1=1;}voidxunji(){if(P1==0x00){qianjin();}//if(P1==0x20)//{////加速//qianjin();//speed=2;//qianjin()
3、;//qianjin();//}if(P1==0x10){//左转qianjin();control+=1;qianjin();while(P1!=0x20){if(P1==0x08){//大角度左转qianjin();qianjin();control+=1;while(P1!=0x10){//if(P1==0x00)//偏出跑道,小车停止//{//speed=10000;//}pianchu++;if(pianchu>=20000){break;}}pianchu=0;control-=1;qia
4、njin();qianjin();}pianchu++;if(pianchu>=20000){break;}}pianchu=0;control-=1;qianjin();qianjin();}if(P1==0x40){//右转qianjin();control-=1;qianjin();while(P1!=0x20){if(P1==0x80){//大角度右转qianjin();control-=1;qianjin();while(P1!=0x40){//if(P1==0x00)//偏出跑道,小车停止
5、//{//speed=10000;//}pianchu++;if(pianchu>=20000){break;}}pianchu=0;qianjin();control+=1;qianjin();}pianchu++;if(pianchu>=20000){break;}}pianchu=0;qianjin();control+=1;qianjin();}}voidmain(){initial_T0();P1=0xf8;while(1){stop1=P1;if(stop1==stop2){stop3++
6、;}else{stop3=0;}xunji();if(P1==0x80
7、
8、P1==0x08
9、
10、stop3>10000){P3=0x00;while(1);}stop2=P1;}}voidT0_waytwo()interrupt3{if(jishu
此文档下载收益归作者所有