《循迹小车程序》doc版.doc_第1页
《循迹小车程序》doc版.doc_第2页
《循迹小车程序》doc版.doc_第3页
《循迹小车程序》doc版.doc_第4页
《循迹小车程序》doc版.doc_第5页
全文预览已结束

VIP免费下载

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1. #include2. #include3. #include4. unsignedcharcodexiaoche=xiaoche;5. unsignedcharcodemm=mm;6. unsignedcharcodedistance=distance;7. unsignedcharcodetime=time;8. unsignedcharzkbz=0;/*占空比*/9. unsignedcharzkby=0;10. unsignedchart=0;/*定时器中断计数器*/11. unsignedintjuli=0;/*距离*/12. unsignedchara=0;13. unsignedcharsl=0;/*时间秒*/14. unsignedcharsh=0;/*时间秒*/15. unsignedcharfl=0;/*时间分*/16. unsignedcharfh=0;/*时间分*/17. unsignedintdis=0;/*实际距离*/18. bitflag=0;/*标志位*/19. sbitgm=P23;/*光敏*/20. 21. /*22. 控制口定义23. */24. sbiten1=P11;/*L298的EnableA*/25. sbits1=P10;/*L298的Input1*/26. sbits2=P12;/*L298的Input2*/27. sbiten2=P14;/*L298的EnableA*/28. sbits3=P13;/*L298的Input1*/29. sbits4=P15;/*L298的Input2*/30. sbitGuandian0=P20;31. sbitGuandian1=P21;32. sbitGuandian2=P22;33. 34. 35. /*36. 外部中断计算路程37. */38. voidservice_int0()interrupt039. 40. EX0=0;41. if(flag=0)juli+;42. elsejuli-;43. dis=juli*5;44. DispOneChar(9,1,dis/10000);45. DispOneChar(11,1,dis/1000%10);46. DispOneChar(12,1,dis/100%10);47. EX0=1;48. 49. 50. /*51. 定时器0服务程序52. */53. 54. voidtimer0()interrupt1/*T0中断服务程序*/55. 56. if(tzkbz)en1=1;elseen1=0;/*产生电机1的PWM信号*/57. if(t=100)t=0;/*1个PWM信号由100次中断产生*/60. 61. 62. /*63. 定时器1服务程序64. */65. voidtimer1()interrupt366. 67. unsignedcharcnt;68. TH1=(65536-50000)/256;69. TL1=(65536-50000)%256;70. cnt+;71. if(cnt=20)72. 73. cnt=0;74. +sl;75. if(sl=10)76. 77. sl=0;78. +sh;79. if(sh=6)80. 81. sh=0;82. +fl;83. if(fl=10)84. 85. fl=0;86. +fh;87. 88. 89. 90. 91. 92. 93. /*94. 循迹程序95. */96. voidxunji(void)97. 98. switch(a)99. 100. case0x02:flag=0;s1=0;s2=1;s3=0;s4=1;zkbz=40;zkby=40;break;101. case0x01:flag=0;s1=0;s2=1;s3=1;s4=0;zkbz=70;zkby=15;break;102. case0x04:flag=0;s1=1;s2=0;s3=0;s4=1;zkbz=15;zkby=70;break;103. case0x03:flag=0;s1=0;s2=1;s3=0;s4=1;zkbz=65;zkby=15;break;104. case0x06:flag=0;s1=0;s2=1;s3=0;s4=1;zkbz=15;zkby=75;break;105. case0x00:flag=1;s1=1;s2=0;s3=1;s4=0;zkbz=30;zkby=30;break;106. default:break;107. 108. Delay5Ms();109. 110. 111. 112. /*113. 内部资源初始化114. */115. voidInit(void)116. 117. TMOD=0x12;/*设定T0的工作模式为2,设定T0的工作模式为1*/118. TH0=0xB6;/*装入定时器的初值*/119. TL0=0xB6;120. TH1=(65536-50000)/256;121. TL1=(65536-50000)%256;122. IT0=1;123. IP=0x03;124. EA=1;/*开总中断*/125. ET0=1;/*定时器0允许中断*/126. ET1=1;/*定时器1允许中断*/127. TR1=1;/*启动定时器1*/128. TR0=1;/*启动定时器0*/129. EX0=1;/*开中断0*/130. 131. 132. 133. voidmain(void)134. 135. Init();/*系统初始化*/136. LcdReset();/*液晶初始化*/137. DisplayListChar(0,0,time,4);138. DispOneChar(7,0,:);139. DisplayListChar(0,1,distance,8);140. DispOneChar(10,1,:);141. 142. zkbz=40;143. zkby=40;144. s1=0;s2=1;s3=0;s4=1;145. 146. do/*循迹*/147. a=P2;148. a=a&0x07;149. xunji();150. while(a!=0x07);151. 152. zkbz=40;/*避障*/153. zkby=40;154. s1=0;s2=1;s3=0;s4=1;/前155. delay(20000);156. s1=0;s2=1;s3=1;s4=0;/左157. delay(65000);158. s1=0;s2=1;s3=0;s4=1;/前159. delay(60000);160. s1=1;s2=0;s3=0;s4=1;/右161. delay(50000);162. s1=0;s2=1;s3=0;s4=1;/前163. delay(60000);164. /*s1=1;s2=0;s3=0;s4=1;/右165. delay(60000);166. s1=0;s2=1;s3=0;s4=1;/前167. delay(60000);168. s1=0;s2=1;s3=1;s4=0;/左169. delay(60000);*/170. s1=0;s2=1;s3=0;s4=1;/前171. 172. do/*趋光*/173. 174. a=P2;175. a=a&0x07;176. if(!gm)177. 178. zkbz=60;zkby=0;179. else180. zkbz=0;zkby=70;181. delay(10000);182. while(a=0);183. 184. s1=s2=s3=s4=0;185. s1=0;s2=1;s3=0;s4=1;186. delay(20000)

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论