標(biāo)題: “T”字路口循跡程序 51單片機(jī)尋跡小車 [打印本頁(yè)]

作者: 51hei小胡    時(shí)間: 2017-4-3 22:57
標(biāo)題: “T”字路口循跡程序 51單片機(jī)尋跡小車

分享幾個(gè)調(diào)試通過(guò)的51單片機(jī)尋跡小車代碼

源程序:
  1. /*NewWay 循跡模塊專用程序*/
  2. /*簡(jiǎn)單循跡程序,此程序能讓小車尋到T字路后停下*/
  3. /*你可以任意使用、修改該程序,如果你要把該程序用于商業(yè),請(qǐng)與我聯(lián)系,不然一切后果自己承擔(dān)*/
  4. /*作者:劉偉*/
  5. /*當(dāng)你看到這個(gè)程序的時(shí)候,請(qǐng)注意,這個(gè)程序是不能直接使用的,你要自己實(shí)現(xiàn)小車的向前,向后,向左,向右,及其延時(shí)的子程序*/
  6. #include <REGX52.H>
  7. void CarGo();
  8. void CarBack();
  9. void CarTurnLeft();
  10. void CarTurnRight();
  11. void Delayms(unsigned char n);
  12. void CarStop();

  13. /*定義循跡傳感器管腳*/
  14. sbit CLP=P1^0;
  15. sbit SS1=P1^1;
  16. sbit SS2=P1^2;
  17. sbit SS3=P1^3;
  18. sbit SS4=P1^4;
  19. sbit SS5=P1^5;
  20. sbit Near=P1^6;


  21. void CarGoLine()         //小車沿黑線走
  22. {  
  23. if(SS2==0)
  24.                 {
  25.                          CarTurnLeft();
  26.                 }
  27.                 else
  28.                 {
  29.             if(SS4==0)
  30.                 {  
  31.                   CarTurnRight();
  32.                 }
  33.                 else
  34.                 {  
  35.                  CarGo();
  36.                 }
  37.                 }
  38. }
  39. void main()
  40. {           
  41. unsigned char flag;
  42. flag=0;
  43.      while(flag==0)
  44.          {
  45.           CarGoLine();
  46.           if((SS1==0)&&(SS5==0))
  47.           {  
  48.                  CarGo();
  49.                  Delayms(200);// 判斷不是 “十” 字形接口  具體延時(shí)時(shí)間看小車的速度和性能
  50.                  if(SS3==1) flag=1;
  51.           }
  52.          }

  53.    CarStop();

  54. }
復(fù)制代碼


完整源碼和資料下載:
http://www.torrancerestoration.com/bbs/dpj-80504-1.html









歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1