标题:
stm32超声波避障源码
[打印本页]
作者:
sdlqwql
时间:
2017-12-30 20:21
标题:
stm32超声波避障源码
stm32超声波避障
舵机信号口:A0
超声波信号口:TRIG===B8
ECHO==B9
小车电机驱动口依次:左电机:C8 C9 右电机:C6 C7
小车电机驱动EA使能端口:A6,A7
单片机源程序如下:
/**
******************************************************************************
* @file main.c
* @author MCD Application Team
* @version V3.5.0
* @date 08-April-2011
* @brief Main program body
**/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "usart1.h"
#include "SysTick.h"
#include "motor_control.h"
#include "UltrasonicWave.h"
#include "TIM3.h"
#include "pwm_output.h"
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
vu32 Onward_flag=0;
vu8 RxBuffer[2];
vu32 PWM_flag=0;
vu32 Left_flag=0;
vu32 Right_flag=0;
vu32 Backward_flag=0;
vu32 Stop_flag=0;
vu32 Xunji_flag=0;
vu32 Auto_flag=0;
vu8 count=0;
/* Private function prototypes -----------------------------------------------*/
void NVIC_Configuration(void);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* 函数名 : main
* 描述 : 主函数
* 输入 : 无
* 输出 : 无
* 返回 : 无
*******************************************************************************/
int main(void)
{
/* NVIC configuration */
NVIC_Configuration();
/* Configure the Usart1 */
USART1_Config();
/* Configure the DMA1 */
DMA_Configuration();
/* Configure the GPIO */
GPIO_Configuration();
/* Configure the TIM2 */
TIM2_Configuration();
/* Configure the TIM3 */
TIM4_Configuration();
/* Configure the TIM4 */
Control_GPIOE_Config(); /*配置传感器输入信号管脚*/
// TIM4_Configuration();
TIM3_GPIO_Config();
/* Configure the systick */
SysTick_Init();
/* Configure the UltrasonicWave */
UltrasonicWave_Configuration();
Degree(85,1);
// Delay_ms(1500);
while (1)
{
Auto_run();
// if(Onward_flag==1)
// {
// Forward_run(); //前进
// }
// else if(Backward_flag==1)
// {
// Backward_run(); //后退
// }
// else if(Left_flag==1)
// {
// Left_turn(); //左转
// }
// else if(Right_flag==1)
// {
// Right_turn(); // 右转
// }
// else if(Auto_flag==1)
// {
// Auto_run(); //自动避障行驶
// }
// else if(Xunji_flag==1)
// {
// Xunji_run(); //自动循迹行驶
// }
// else
// {
// Stop(); //暂停
// }
}
}
/*******************************************************************************
* 函数名 : NVIC_Configuration
* 描述 : 初始化NVIC
* 输入 : 无
* 输出 : 无
* 返回 : 无
*******************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure the Priority Group to 2 bits */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
stm32-超声波避障.rar
(306.3 KB, 下载次数: 106)
2017-12-31 00:55 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
hello_bug
时间:
2018-1-3 13:47
避障,再加上点循迹,来个摄像头,完美。
作者:
可可分享
时间:
2018-2-1 22:23
谢谢分享 用上了
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1