标题: 各种单片机小车程序集合 [打印本页]

作者: 2983606955    时间: 2020-12-22 09:40
标题: 各种单片机小车程序集合
有小车循迹
有红外遥控
有声控小车
有超声波避障


电路原理图如下:


单片机源程序如下:
  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;                //计数和角度。


  6. void delay_100us()                         //100us延时,相当于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时,无限循环,相当于20ms为一个周期
  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();         //延时100us,相当于0.1ms

  29.                         count++;                 //count自加1。                
  30.                 }                                  
  31.          count=0;                                //当count经历200次后,count归0                               
  32. }



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

  36. while(1)
  37.         {                       
  38.          angle=5;  //角度为5ms
  39.          toji();         //调用舵机子程序。
  40.          


  41.          }

  42. }
复制代码

所有资料51hei提供下载:
03 小车程序与电路.rar (3.23 MB, 下载次数: 53)






欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1