|
畢業(yè)設(shè)計(jì)要用到這個(gè)紅外測(cè)距模塊,收到貨后簡(jiǎn)單寫(xiě)了個(gè)測(cè)試程序,當(dāng)物體與模塊的距離大約在4cm左右時(shí)led會(huì)亮起
實(shí)物圖:
單片機(jī)源程序如下:
- #include "stm32f10x.h"
- #include "delay.h"
- #include "adc.h"
- #include "led.h"
- int main(void)
- {
- u16 adcx;
- float temp;
- Adc_Init();
- LED_Init();
- delay_init();
-
- while(1)
- {
- adcx=Get_Adc_Average(ADC_Channel_1,10);
- temp=(float)adcx*(3.3/4096);
- if (temp > 2.6 & temp < 3)
-
- GPIO_ResetBits(GPIOE,GPIO_Pin_5);
-
- else
- GPIO_SetBits(GPIOE,GPIO_Pin_5);
- delay_ms(250);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
test.zip
(1.98 KB, 下載次數(shù): 226)
2018-4-17 22:10 上傳
點(diǎn)擊文件名下載附件
|
評(píng)分
-
查看全部評(píng)分
|