標(biāo)題: 各種單片機(jī)小車程序集合 [打印本頁(yè)]

作者: 2983606955    時(shí)間: 2020-12-22 09:40
標(biāo)題: 各種單片機(jī)小車程序集合
有小車循跡
有紅外遙控
有聲控小車
有超聲波避障


電路原理圖如下:


單片機(jī)源程序如下:
  1. #include<reg52.h>

  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. sbit pwm=P2^7;                                 //P2.7為PWM腳。
  5. uchar count,angle;                //計(jì)數(shù)和角度。


  6. void delay_100us()                         //100us延時(shí),相當(dāng)于0.1ms
  7. {
  8. uchar j;
  9.         for(j=0;j<31;j++)
  10.                 {
  11.                 ;
  12.                 }

  13. }

  14. void toji()
  15. {
  16.         while(count<200)        //count少于200時(shí),無(wú)限循環(huán),相當(dāng)于20ms為一個(gè)周期
  17.                 {
  18.                         if(count<angle) //count少于角度。
  19.                         {
  20.                         pwm=1;                         //pwm輸出高電平。
  21.                
  22.        
  23.                         }                                                       

  24.                         else                        //其它情況
  25.                         {                          
  26.                         pwm=0;                         //pwm輸出低電平。

  27.                         }
  28.                    delay_100us();         //延時(shí)100us,相當(dāng)于0.1ms

  29.                         count++;                 //count自加1。                
  30.                 }                                  
  31.          count=0;                                //當(dāng)count經(jīng)歷200次后,count歸0                               
  32. }



  33. void main()
  34. {
  35. count=0;

  36. while(1)
  37.         {                       
  38.          angle=5;  //角度為5ms
  39.          toji();         //調(diào)用舵機(jī)子程序。
  40.          


  41.          }

  42. }
復(fù)制代碼

所有資料51hei提供下載:
03 小車程序與電路.rar (3.23 MB, 下載次數(shù): 53)






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