找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 5018|回复: 2
打印 上一主题 下一主题
收起左侧

STM32红外避障程序

[复制链接]
跳转到指定楼层
楼主
ID:263339 发表于 2017-12-18 20:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32红外避障程序

单片机源程序如下:
  1. //连接方式 :请参考interface.h文件
  2. //部份源码来源网络--请试用24小时后删除
  3. #include "stm32f10x.h"
  4. #include "interface.h"
  5. #include "LCD1602.h"
  6. #include "IRCtrol.h"
  7. #include "motor.h"
  8. #include "UltrasonicCtrol.h"

  9. //全局变量定义
  10. unsigned int speed_count=0;//占空比计数器 50次一周期
  11. char front_left_speed_duty=SPEED_DUTY;
  12. char front_right_speed_duty=SPEED_DUTY;
  13. char behind_left_speed_duty=SPEED_DUTY;
  14. char behind_right_speed_duty=SPEED_DUTY;

  15. unsigned char tick_5ms = 0;//5ms计数器,作为主函数的基本周期
  16. unsigned char tick_1ms = 0;//1ms计数器,作为电机的基本计数器
  17. unsigned char tick_200ms = 0;//刷新显示

  18. char ctrl_comm = COMM_STOP;//控制指令

  19. char ctrl_comm_last = COMM_STOP;//上一次的指令
  20. unsigned char continue_time=0;

  21. unsigned char duoji_count=0;
  22. unsigned char zhuanjiao = 11;
  23. char ctrl_comm1 = COMM_UP;//控制指令

  24. ////全局变量定义
  25. unsigned char const table3[]=" GOGO ";
  26. unsigned char const table4[]=" STOP ";



  27. ///获取前方的距离,进来前方向为向前
  28. void GetAllDistance(unsigned int *dis_direct)
  29. {
  30.         CarStop();
  31.         GetDistanceDelay();
  32.         *dis_direct = distance_cm;
  33.         LCD1602WriteDistance(distance_cm);
  34.        
  35. }


  36. void BarrierProc()
  37. {
  38.         if(distance_cm < 25)//前方有障碍物
  39.         {
  40.                 unsigned int dis_direct;//前方距离

  41.                 CarStop();
  42.                 Delayms(400);
  43.                 LCD1602WriteCommand(ctrl_comm);
  44.                 GetAllDistance(&dis_direct);
  45.                
  46.         }
  47.         else
  48.         {
  49.                 CarGo();
  50.                 LCD1602WriteCommand(ctrl_comm1);
  51.         }
  52. }

  53. int main(void)
  54. {
  55.         delay_init();
  56.         GPIOCLKInit();
  57.         UserLEDInit();
  58.         LCD1602Init();
  59.         //IRCtrolInit();
  60.         TIM2_Init();
  61.         MotorInit();
  62.         UltraSoundInit();
  63.        
  64.         Delayms(500);
  65.         CarGo();

  66. while(1)
  67. {         
  68.                  if(tick_5ms >= 5)
  69.                 {
  70.                         tick_5ms = 0;

  71.                         Distance();//计算距离
  72.                         BarrierProc();

  73.                 }
  74.                
  75. }
  76. }

复制代码

所有资料51hei提供下载:
STM32红外避障实验.rar (281.86 KB, 下载次数: 115)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶1 踩
回复

使用道具 举报

沙发
ID:290911 发表于 2018-7-2 23:54 | 只看该作者
谢谢分享
回复

使用道具 举报

板凳
ID:65348 发表于 2020-7-2 14:03 | 只看该作者
好东东,有空学习一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表