电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

单片机的循迹小车程序

单片机的循迹小车程序_第1页
1/4
单片机的循迹小车程序_第2页
2/4
单片机的循迹小车程序_第3页
3/4
#include#define uint unsigned int#define uchar unsigned charsbit port_1=P3^5;sbit port_2=P3^4;sbit port_3=P3^1;sbit port_4=P3^0;sbit en_1=P3^2;sbit en_2=P3^3;sbit infrared1 = P0^2;sbit infrared2 = P0^3;sbit infrared3 = P0^4;uchar infrared,num,left,right;void init(){TMOD=0x01;TH0=(65536-1000)/256;TR0=(65536-1000)%256;EA=1;ET0=1;TR0=1;en_1 = 1;en_2 = 1;}void motor(uchar pesition){if(pesition == 0){port_1=0; //左电机port_2=1;port_3=0; //右电机port_4=1;}if(pesition == 1){port_1=0; //左电机port_2=1;port_3=1; //右电机port_4=0;}if(pesition == 2){port_1=1; //左电机port_2=0;port_3=0; //右电机port_4=1;} if(pesition == 3){port_1=1; //左电机port_2=0;port_3=1; //右电机port_4=0;} if(pesition == 4){port_1=0; //左电机port_2=0;port_3=0; //右电机port_4=0;}}void infraredscan(){if(!infrared1 && !infrared2 && !infrared3){motor(4);}if(!infrared1 && !infrared2 && infrared3){//if(num <= 60)motor(1);//else//motor(4);}if(!infrared1 && infrared2 && !infrared3){// if(num <= 60)motor(0);// else//motor(4);}if(!infrared1 && infrared2 && infrared3){// if(num <= 60)motor(1);// else//motor(4);} if(infrared1 && !infrared2 && !infrared3){//if(num <= 60)motor(2); //else//motor(4);} if(infrared1 && !infrared2 && infrared3){//if(num <= 60)motor(4); //else//motor(4);} if(infrared1 && infrared2 && !infrared3){//if(num <= 60)motor(2);//else//motor(4);} if(infrared1 && infrared2 && infrared3){//if(num <= 60)motor(0);//else//motor(4); }}void main(){init();while(1){infraredscan();}}void T0_time() interrupt 1{TH0=(65536-10000)/256;TR0=(65536-10000)%256;num++;if(num == 100){num = 0;}}

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

单片机的循迹小车程序

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部