|
這是一個(gè)使用STM32驅(qū)動(dòng)小車實(shí)現(xiàn)超聲波避障功能的程序,親測(cè)可用
實(shí)驗(yàn)器材:
ZYSTM32-A0智能機(jī)器人產(chǎn)品
實(shí)驗(yàn)?zāi)康?
本實(shí)驗(yàn)為新建工程實(shí)驗(yàn),僅供大家新建工程時(shí)參考。
新建工程詳細(xì)步驟,請(qǐng)看《STM32不完全手冊(cè)-庫(kù)函數(shù)版本》第3.3節(jié)。
實(shí)驗(yàn)現(xiàn)象:
本實(shí)驗(yàn)下載后,控制板上接到13端口的LED會(huì)閃爍!
注意事項(xiàng):
無(wú).
單片機(jī)源程序如下:
- #include "stm32f10x.h"
- #include "delay.h"
- #include "motor.h"
- #include "keysacn.h"
- #include "IRSEARCH.h"
- #include "IRAvoid.h"
- #include "usart.h"
- #include "UltrasonicWave.h"
- #include "timer.h"
- //extern int U_temp;
- /*
- void ZYSTM32_run(int speed,int time); //前進(jìn)函數(shù)
- void ZYSTM32_brake(int time); //剎車函數(shù)
- void ZYSTM32_Left(int speed,int time); //左轉(zhuǎn)函數(shù)
- void ZYSTM32_Spin_Left(int speed,int time); //左旋轉(zhuǎn)函數(shù)
- void ZYSTM32_Right(int speed,int time); //右轉(zhuǎn)函數(shù)
- void ZYSTM32_Spin_Right(int speed,int time);//右旋轉(zhuǎn)函數(shù)
- void ZYSTM32_back(int speed,int time); //后退函數(shù)
- */
- int main(void)
- {
- delay_init();
- KEY_Init();
- IRSearchInit();
- IRAvoidInit();
- Timerx_Init(5000,7199); //10Khz的計(jì)數(shù)頻率,計(jì)數(shù)到5000為500ms
- UltrasonicWave_Configuration(); //對(duì)超聲波模塊初始化
- uart_init(115200);
- TIM4_PWM_Init(7199,0); //初始化PWM
- ZYSTM32_brake(500);
- keysacn();
- while(1)
- {
- //printf("測(cè)到的距離值為:%d\n",UltrasonicWave_StartMeasure());
- if(UltrasonicWave_StartMeasure()<40)
- {
-
- ZYSTM32_back(50,500);
- ZYSTM32_Right(50,500);
- BEEP_SET;
- }
- else
- {
- ZYSTM32_run(50,1);
- BEEP_RESET;
- }
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
超聲波避障程序(無(wú)舵機(jī)).rar
(297.69 KB, 下載次數(shù): 173)
2017-9-15 02:17 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|