STM32驅動超聲波測距感測器

2021-09-29 05:28:46 字數 707 閱讀 9190

先貼**,以後再補說明

tim_icinittypedef  tim5_icinitstructure;

void tim5_cap_init(u16 arr,u16 psc)

u8 tim5ch1_capture_sta=0; //輸入捕獲狀態

u16 tim5ch1_capture_val; //輸入捕獲值

//定時器5中斷服務程式

void tim5_irqhandler(void)

else tim5ch1_capture_sta++;

} } if (tim_getitstatus(tim5, tim_it_cc1) != reset)//捕獲1發生捕獲事件

else //還未開始,第一次捕獲上公升沿

}

} tim_clearitpendingbit(tim5, tim_it_cc1|tim_it_update); //清除中斷標誌位

}

主函式呼叫如下:

tim5_cap_init(0xffff,72-1);	//以1mhz的頻率計數 

if(tim5ch1_capture_sta&0x80)//成功捕獲到了一次上公升沿

列印log直接輸出取樣到的高電平時間和目標到感測器的直線距離。

在STM32上驅動超聲波測距模組

include sys.h include stm32f10x.h include delay.h include usart.h include time.h void hcsr04 init u16 arr,u16 psc u8 tim2ch1 capture sta 0 輸入捕獲狀態 u16 ...

超聲波感測器測距報警器

hc sr04超聲波測距模組 lcd 蜂鳴器 qmc5883l電子羅盤模組 步進機 可無 position.c qmc5883l電子羅盤模組 include lcd.h extern uchar buf 8 資料快取 延時5us void delay 5us 起始訊號 void qmc5883 st...

超聲波感測器 單介紹超聲波

超聲波是聲波的一部分,是人耳聽不見 頻率高於20khz的聲波,它和聲波有共同之處,即都是由物質振動而產生的,並且只能在介質中傳播 同時,它也廣泛地存在於自然界,許多動物都能發射和接收超聲波,其中以蝙蝠最為突出,它能利用微弱的超聲回波在黑暗中飛行並捕捉食物。但超聲還有它的特殊性質 如具有較高的頻率與較...