找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3388|回复: 2
收起左侧

stm32超声波避障源码

[复制链接]
ID:269293 发表于 2017-12-30 20:21 | 显示全部楼层 |阅读模式
stm32超声波避障
舵机信号口:A0
超声波信号口:TRIG===B8
              ECHO==B9

小车电机驱动口依次:左电机:C8 C9  右电机:C6 C7
小车电机驱动EA使能端口:A6,A7

单片机源程序如下:
  1. /**
  2.   ******************************************************************************
  3.   * @file    main.c
  4.   * @author  MCD Application Team
  5.   * @version V3.5.0
  6.   * @date    08-April-2011
  7.   * @brief   Main program body
  8. **/
  9. /* Includes ------------------------------------------------------------------*/
  10. #include "stm32f10x.h"
  11. #include "usart1.h"
  12. #include "SysTick.h"
  13. #include "motor_control.h"
  14. #include "UltrasonicWave.h"
  15. #include "TIM3.h"
  16. #include "pwm_output.h"
  17. /* Private typedef -----------------------------------------------------------*/
  18. /* Private define ------------------------------------------------------------*/
  19. /* Private macro -------------------------------------------------------------*/
  20. /* Private variables ---------------------------------------------------------*/
  21. vu32 Onward_flag=0;
  22. vu8 RxBuffer[2];
  23. vu32 PWM_flag=0;
  24. vu32 Left_flag=0;
  25. vu32 Right_flag=0;
  26. vu32 Backward_flag=0;
  27. vu32 Stop_flag=0;
  28. vu32 Xunji_flag=0;
  29. vu32 Auto_flag=0;
  30. vu8  count=0;

  31. /* Private function prototypes -----------------------------------------------*/
  32. void NVIC_Configuration(void);

  33. /* Private functions ---------------------------------------------------------*/

  34. /*******************************************************************************
  35. * 函数名         : main
  36. * 描述           : 主函数
  37. * 输入           : 无
  38. * 输出           : 无
  39. * 返回           : 无
  40. *******************************************************************************/
  41. int main(void)
  42. {
  43.    /* NVIC configuration */
  44.    NVIC_Configuration();
  45.    /* Configure the Usart1 */
  46.    USART1_Config();
  47.    /* Configure the DMA1 */
  48.    DMA_Configuration();
  49.    /* Configure the GPIO */
  50.    GPIO_Configuration();
  51.    /* Configure the TIM2 */
  52.    TIM2_Configuration();
  53.    /* Configure the TIM3 */
  54.    TIM4_Configuration();
  55.    /* Configure the TIM4 */
  56.         Control_GPIOE_Config();  /*配置传感器输入信号管脚*/
  57. //   TIM4_Configuration();
  58.           TIM3_GPIO_Config();
  59.    /* Configure the systick */
  60.    SysTick_Init();
  61.    /* Configure the UltrasonicWave */
  62.    UltrasonicWave_Configuration();

  63.    Degree(85,1);

  64.          
  65. //         Delay_ms(1500);

  66.    while (1)
  67.   {
  68.                
  69.                         Auto_run();
  70.                
  71. //         if(Onward_flag==1)
  72. //          {
  73. //            Forward_run();                         //前进
  74. //          }
  75. //         else if(Backward_flag==1)
  76. //          {
  77. //            Backward_run();                  //后退
  78. //          }
  79. //         else if(Left_flag==1)
  80. //          {
  81. //            Left_turn();                     //左转
  82. //          }
  83. //         else if(Right_flag==1)
  84. //          {
  85. //            Right_turn();                    // 右转
  86. //          }
  87. //          else if(Auto_flag==1)
  88. //          {
  89. //            Auto_run();                                         //自动避障行驶
  90. //          }
  91. //                else if(Xunji_flag==1)
  92. //          {
  93. //            Xunji_run();                                         //自动循迹行驶
  94. //          }
  95. //          else
  96. //          {
  97. //           Stop();                           //暂停
  98. //          }
  99.         }
  100.   }                       
  101.   




  102. /*******************************************************************************
  103. * 函数名         : NVIC_Configuration
  104. * 描述           : 初始化NVIC
  105. * 输入           : 无
  106. * 输出           : 无
  107. * 返回           : 无
  108. *******************************************************************************/
  109. void NVIC_Configuration(void)
  110. {
  111.    NVIC_InitTypeDef NVIC_InitStructure;

  112.    /* Configure the Priority Group to 2 bits */
  113.   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  114.   
  115. ……………………

  116. …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码

所有资料51hei提供下载:
stm32-超声波避障.rar (306.3 KB, 下载次数: 105)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:143223 发表于 2018-1-3 13:47 | 显示全部楼层
避障,再加上点循迹,来个摄像头,完美。
回复

使用道具 举报

ID:262559 发表于 2018-2-1 22:23 | 显示全部楼层
谢谢分享  用上了
回复

使用道具 举报

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

本版积分规则

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

Powered by 单片机教程网

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