欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1220|回復: 1
收起左側

單片機避障小車代碼

[復制鏈接]
ID:466394 發表于 2019-1-11 12:25 | 顯示全部樓層 |閱讀模式
一種可調速避障小車源程序

單片機源程序如下:
  1. #include "reg52.h"                         //此文件中定義了單片機的一些特殊功能寄存器
  2. #include<intrins.h>                //因為要用到左右移函數,所以加入這個頭文件
  3. #include "Timer.h"

  4. typedef unsigned int u16;          //對數據類型進行聲明定義
  5. typedef unsigned char u8;


  6. sbit leftmoto1 = P1^7;       
  7. sbit leftmoto2 = P1^6;       
  8. sbit rightmoto1=P1^5;       
  9. sbit rightmoto2=P1^4;
  10.        
  11. sbit L1 = P1^3;       
  12. sbit L2 = P1^2;       
  13. sbit R1=P1^0;       
  14. sbit R2=P1^1;

  15. //#define Leftmotogo {left-moto1= 0 ;left-moto2= 1 ; };
  16. //#define Leftmotoback {left-moto1= 1 ;left-moto2= 0 ; };
  17. //#define Leftmotostop {left-moto1= 1 ;left-moto2= 1 ; };
  18. //#define Rightmotogo {right-moto1= 0 ;right-moto2= 1 ;};
  19. //#define Rightmotoback {right-moto1= 1 ;right-moto2= 0 ; };
  20. //#define Rightmotostop {right-moto1= 1 ;right-moto2= 1 ; };

  21. void run()
  22. {
  23.         leftmoto1= 1 ;
  24.         leftmoto2= 0 ;
  25.         rightmoto1= 1 ;
  26.         rightmoto2= 0 ;            //正轉
  27. }

  28. void left()
  29. {
  30.         leftmoto1= 0 ;
  31.         leftmoto2= 1 ;          //左輪反轉
  32.         rightmoto1= 1 ;
  33.         rightmoto2= 0 ;          //右輪正轉
  34. }
  35. void right()
  36. {
  37.         leftmoto1= 1 ;
  38.         leftmoto2= 0 ;           //左輪正轉
  39.         rightmoto1= 0 ;
  40.         rightmoto2= 1 ;          //右輪反轉
  41. }
  42. void stop()
  43. {
  44.         leftmoto1= 1 ;
  45.         leftmoto2= 1 ;
  46.         rightmoto1= 1 ;
  47.         rightmoto2= 1 ;
  48. }

  49. void back()
  50. {
  51.         leftmoto1= 0 ;
  52.         leftmoto2= 1 ;
  53.         rightmoto1= 0 ;
  54.         rightmoto2= 1 ;
  55. }

  56. void delay_ms(u16 x)
  57. {        while(x--);
  58. //    unsigned int i,j;
  59. //        for(i = x;i > 0;i--)
  60. //        {
  61. //        for(j = 10 ;j > 0;j--);
  62. //        }       
  63. }

  64. void main()
  65. {
  66.    ENA = 1 ;
  67.    ENB = 1 ;
  68.    while(1)
  69.    {
  70.   
  71.           InitTimer0();
  72.         while(1)
  73.         {
  74.         if(L1&&L2&&R1&&R2)        run();
  75.         if((!L1)&&(!L2)&&R1&&R2)  //right();
  76.         {
  77.         stop();
  78.         //delay_ms( 1 );
  79.         right();
  80.         }
  81.         if(L1&&(!L2)&&R1&&R2)  
  82.         {
  83.         stop();
  84.         //delay_ms( 1 );
  85.         right();
  86.         }
  87.         if((!L1)&&L2&&R1&&R2)  
  88.         {
  89.         stop();
  90.         //0delay_ms( 10 );
  91.         right();         
  92.         }
  93.         if((!L1)&&(!L2)&&(!R1)&&R2)  
  94.         {
  95.         stop();
  96.         //delay_ms( 1 );
  97.         right();         
  98.         }
  99.         if(L1&&L2&&R1&&(!R2))
  100.         {
  101.         stop();
  102.         //delay_ms( 1 );
  103.         left();         
  104.         }
  105.         if(L1&&L2&&(!R1)&&R2)
  106.         {
  107.         stop();  
  108.         left();
  109.         }
  110.         if(L1&&L2&&(!R2)&&(!R2))
  111.         {
  112.         stop();  
  113.         left();
  114.         }
  115.         if(L1&&(!L2)&&(!R1)&&(!R2))  
  116.         {
  117.         stop();  
  118.         left();
  119.         }
  120.         if((!L1)&&(!L2)&&(!R1)&&(!R2))  
  121.         {
  122.         stop();  
  123.         back();
  124.         }
  125.                
  126.         }                         
  127. }
  128. }
復制代碼

所有資料51hei提供下載:
小車.zip (28.5 KB, 下載次數: 8)



回復

使用道具 舉報

ID:1 發表于 2019-1-11 15:30 | 顯示全部樓層
需要補全原理圖即可獲得100黑幣+
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表