欢迎来到天天文库
浏览记录
ID:43556727
大小:1.66 MB
页数:7页
时间:2019-10-10
《循迹小车基本思路》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、循迹小车基本思路1)基本车架:两个直流减速电动机;万向轮一个;模板一块;2)基本模块:7.2V电源一块;输出为5V的稳压模块一个;单片机最小系统主控模块;L298电机驱动;光电传感器4个。3)黑线循迹。4)组装车型:5)L298驱动内部电路:6)调试程序:另附~。#include7)#defineucharunsignedchar1)#defineuintunsignedint2)sbitPWM1=P1^0;//电机使能3)sbitPWM2=P1^1;4)sbitIN1=P1^2;//电机输入控制5)sbitIN2=P1
2、^3;6)sbitIN3=P1^4;7)sbitIN4=P1^5;8)sbitRP1=P2^0;//传感器管脚声明9)sbitRP2=P2^1;10)sbitRP3=P2^2;11)sbitRP4=P2^3;12)intnum1,num2,s1,s2;13)14)voidinit()15){16)TMOD=0x01;17)TH0=(65536-1000)/256;18)TL0=(65536-1000)%256;19)ET0=1;20)EA=1;21)TR0=1;22)}1)voiddelay(uintz)2){3)uintx,y;4)fo
3、r(x=z;x>0;x--)5){for(y=110;y>0;y--);}6)}7)voidforward1()//电机前进8){9)IN1=0;10)IN2=1;11)}12)voidforward2()13){14)IN3=0;15)IN4=1;16)}17)voidback1()//电机后退18){19)IN1=1;20)IN2=0;21)}22)voidback2()1){2)IN3=1;3)IN4=0;4)}5)voidspeed(num1,s1,num2,s2)//速度控制pwm;6){7)if(num14、=1;}9)else10){PWM1=0;}11)if(num25、P2==0&&RP3==1&&RP4==1)//微右偏9){forward1();forward2();speed(num1,2,num2,7);}10)if(RP1==0&&RP2==1&&RP3==1&&RP4==1)//微左偏11){forward1();forward2();speed(num1,6,num2,5);}12)if(RP1==0&&RP2==0&&RP3==0&&RP4==1)//左偏13){forward1();forward2();speed(num1,4,num2,8);}14)if(RP1==0&&RP2==6、0&&RP3==1&&RP4==0)//右偏15){forward1();forward2();speed(num1,7,num2,5);}16)if(RP3==1&&RP4==1&&RP1==0&&RP2==0)//直道17){forward1();forward2();speed(num1,9,num2,8);}18)}19)voidmain()20){21)init();22)while(1)1){2)kongzhi();3)if(RP1==1&&RP2==0&&RP3==0&&RP4==0)4){forward1();forwar7、d2();speed(num1,7,num2,4);}5)if(RP1==1&&RP2==1&&RP3==0&&RP4==1)//dayou6){forward1();forward2();speed(num1,10,num2,3);delay(100);}7)if(RP1==0&&RP2==0&&RP3==0&&RP4==0)8){forward1();forward2();speed(num1,10,num2,3);delay(100);}9)if(RP1==1&&RP2==1&&RP3==1&&RP4==0)10){forward18、();forward2();speed(num1,10,num2,3);delay(100);}11)/*if(RP1==1&&RP2==1&&RP3==1&&RP4==0)12)//{for
4、=1;}9)else10){PWM1=0;}11)if(num25、P2==0&&RP3==1&&RP4==1)//微右偏9){forward1();forward2();speed(num1,2,num2,7);}10)if(RP1==0&&RP2==1&&RP3==1&&RP4==1)//微左偏11){forward1();forward2();speed(num1,6,num2,5);}12)if(RP1==0&&RP2==0&&RP3==0&&RP4==1)//左偏13){forward1();forward2();speed(num1,4,num2,8);}14)if(RP1==0&&RP2==6、0&&RP3==1&&RP4==0)//右偏15){forward1();forward2();speed(num1,7,num2,5);}16)if(RP3==1&&RP4==1&&RP1==0&&RP2==0)//直道17){forward1();forward2();speed(num1,9,num2,8);}18)}19)voidmain()20){21)init();22)while(1)1){2)kongzhi();3)if(RP1==1&&RP2==0&&RP3==0&&RP4==0)4){forward1();forwar7、d2();speed(num1,7,num2,4);}5)if(RP1==1&&RP2==1&&RP3==0&&RP4==1)//dayou6){forward1();forward2();speed(num1,10,num2,3);delay(100);}7)if(RP1==0&&RP2==0&&RP3==0&&RP4==0)8){forward1();forward2();speed(num1,10,num2,3);delay(100);}9)if(RP1==1&&RP2==1&&RP3==1&&RP4==0)10){forward18、();forward2();speed(num1,10,num2,3);delay(100);}11)/*if(RP1==1&&RP2==1&&RP3==1&&RP4==0)12)//{for
5、P2==0&&RP3==1&&RP4==1)//微右偏9){forward1();forward2();speed(num1,2,num2,7);}10)if(RP1==0&&RP2==1&&RP3==1&&RP4==1)//微左偏11){forward1();forward2();speed(num1,6,num2,5);}12)if(RP1==0&&RP2==0&&RP3==0&&RP4==1)//左偏13){forward1();forward2();speed(num1,4,num2,8);}14)if(RP1==0&&RP2==
6、0&&RP3==1&&RP4==0)//右偏15){forward1();forward2();speed(num1,7,num2,5);}16)if(RP3==1&&RP4==1&&RP1==0&&RP2==0)//直道17){forward1();forward2();speed(num1,9,num2,8);}18)}19)voidmain()20){21)init();22)while(1)1){2)kongzhi();3)if(RP1==1&&RP2==0&&RP3==0&&RP4==0)4){forward1();forwar
7、d2();speed(num1,7,num2,4);}5)if(RP1==1&&RP2==1&&RP3==0&&RP4==1)//dayou6){forward1();forward2();speed(num1,10,num2,3);delay(100);}7)if(RP1==0&&RP2==0&&RP3==0&&RP4==0)8){forward1();forward2();speed(num1,10,num2,3);delay(100);}9)if(RP1==1&&RP2==1&&RP3==1&&RP4==0)10){forward1
8、();forward2();speed(num1,10,num2,3);delay(100);}11)/*if(RP1==1&&RP2==1&&RP3==1&&RP4==0)12)//{for
此文档下载收益归作者所有