标题: 基于51单片机的红外避障扫地小车源程序 [打印本页]

作者: ljc1023    时间: 2020-3-14 11:53
标题: 基于51单片机的红外避障扫地小车源程序
元件包括驱动芯片L298N,整流二极管,电机,由于是四轮,固有四个电机稳压模块L7805等
电路原理图如下:


单片机源程序如下:
  1. #include"motor_pwm.h"

  2. sbit hw=P1^0;
  3. sbit key=P3^6;
  4. sbit key1=P3^7;
  5. sbit fengji=P3^4;

  6. void main(void)  
  7. {         
  8.         uint T1_data=0;
  9.         uchar flag;
  10.         uint count,aaa;          
  11.         char pwm_l=52,pwm_r=52;

  12.         pwm_init();       
  13. //        int_init();
  14. //        Timer1_Init();

  15.         while(1)   
  16.         {         
  17.                 if(!key1){while(!key1);fengji=~fengji;}//吸尘风机打开/关闭开关

  18.                 if(!key){while(!key);flag++;if(flag>2)flag=0;}//模式切换               
  19.                 if(flag==1)//模式一 来回往返清扫模式
  20.                 {

  21.                         motor(pwm_l,pwm_r);
  22.                
  23.                         if(!hw)
  24.                         {
  25.                                 if(aaa)
  26.                                 {
  27.                                         aaa=0;
  28.                                         count=100;while(count--){Delay(10);motor(0,0);}//停止1S
  29.                                         //count=100;while(count--){Delay(10);motor(-25,-25);}//后退1S
  30.                                         count=100;while(count--){Delay(40);motor(65,-65);}//右转90度
  31.                                         count=100;while(count--){Delay(27);motor(65,65);}//前进1S
  32.                                         count=100;while(count--){Delay(32);motor(65,-65);}//右转90度
  33.                                         count=100;while(count--){Delay(45);motor(-50,-50);}//后退2S       
  34.                                 }
  35.                                 else
  36.                                 {
  37.                                         aaa=1;
  38.                                         count=100;while(count--){Delay(10);motor(0,0);}//停止1S
  39.                                         //count=100;while(count--){Delay(10);motor(-25,-25);}//后退1S
  40.                                         count=100;while(count--){Delay(40);motor(-65,65);}//右转90度
  41.                                         count=100;while(count--){Delay(27);motor(65,65);}//前进1S
  42.                                         count=100;while(count--){Delay(30);motor(-65,65);}//右转90度
  43.                                         count=100;while(count--){Delay(45);motor(-50,-50);}//后退2S       
  44.                                 }
  45.                         }
  46.                 }
  47.                 else if(flag==2)//模式二 任意清扫模式
  48.                 {
  49.                         motor(50,50);
  50.                         if(!hw)
  51.                         {
  52.                        
  53.                                 count=100;while(count--){Delay(12);motor(-50,-50);}//后退1S
  54.                                 count=100;while(count--){Delay(34);motor(-50,50);}//右转90度
  55.                                
  56. //              count=100;while(count--){Delay(12);motor(-50,-50);}//后退1S
  57. //                                count=100;while(count--){Delay(34);motor(-50,50);}//右转90度

  58.                        
  59.                         }       
  60.                 }
  61.                 else if(flag==0)//停止模式
  62.                 {
  63.                         motor(0,0);
  64.                 }
  65.                
  66.                
  67.                                                    
  68.         }  
  69. }
复制代码

所有资料51hei提供下载:
扫地机器人源程序.rar (24.24 KB, 下载次数: 83)




作者: 白银无足鸟    时间: 2020-11-18 22:45
程序是全部的程序吗?编译出错了呢
作者: 接口    时间: 2020-12-14 00:11
想请教楼主是用什么软件画图的,我很多元件都找不到
作者: zhongluqi    时间: 2021-6-2 20:54
有哪位大神能讲解一下程序吗?
作者: aking991    时间: 2021-6-3 08:37
还是得下载附件才能用,因为上面的代码只是其中的一部份,还缺1个头文件
作者: zhongluqi    时间: 2021-6-4 17:34
白银无足鸟 发表于 2020-11-18 22:45
程序是全部的程序吗?编译出错了呢

请问你可以看得懂这个程序吗
作者: zhongluqi    时间: 2021-6-4 17:52
请问一下这里的aaa,count还有if(!hw)代表什么,是什么意思啊
作者: 172624    时间: 2022-2-5 21:32
这资料也太有用了,感谢楼主的分享
作者: apple1860w    时间: 2022-2-8 11:52
这个必须支持 51单片机就是给力
作者: happyzhmab    时间: 2023-6-1 21:51
诶呦,不错哦,谢谢啦




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