基於STM32F4的TOF10120雷射測距

2021-10-12 20:03:44 字數 3506 閱讀 7401

使用的是串列埠觸發方式,板子還是icore3那塊,晶元是f4的,大同小異,直接上**

distance.c

#include

"..\include\distance.h"

#include

"..\include\sys.h"

#include

"..\include\delay.h"

#include

"..\include\timer3.h"

#include

"..\include\usart.h"

#include

"..\fwlib\inc\stm32f4xx_gpio.h"

#include

"..\fwlib\inc\stm32f4xx_rcc.h"

#include

"..\fwlib\inc\stm32f4xx_tim.h"

u8 flag =0;

u8 usart6_rx_buf[

100]

;u8 usart6_rx_sta =0;

unsigned

char rxbuf[6]

,rxempty, rxcnt,rxflag,waitflag;

unsigned

short

int length_val;

unsigned

int timeout;

//vcc 左2行 2/3列

//gnd 左2行 1列

//rx接 左11行 2列

//tx接 左11行 3列

void

usart6_init

(u32 bound)

void

usart6_irqhandler

(void

)//串列埠1中斷服務程式

}else}}

else

if(rxcnt>=16)

}else}}

void

send_data_to_usart6

(char dat)

void

usart_send_string

(usart_typedef* usartx,

unsigned

char

*str)

}

distance.h

#ifndef __distance_h__

#define __distance_h__

#include

"sys.h"

#define trig phout(2)

extern u8 flag;

extern u8 usart6_rx_buf[

100]

;extern u8 usart6_rx_sta;

void

usart6_init

(u32 bound)

;void

usart_send_string

(usart_typedef* usartx,

unsigned

char

*str)

;void

send_data_to_usart6

(char dat)

;#endif

main.c

#include

"..\include\led.h"

#include

"..\include\main.h"

#include

"..\include\usart.h"

#include

"..\include\timer3.h"

#include

"..\include\led.h"

#include

"..\include\distance.h"

#include

"..\include\sys.h"

#include

"..\include\delay.h"

#include

"..\include\exti.h"

#include

"..\include\key.h"

#include

"..\include\reset.h"

#include

"..\fwlib\inc\stm32f4xx_rcc.h"

#include

"..\fwlib\inc\stm32f4xx_tim.h"

#include

"..\fwlib\inc\stm32f4xx_gpio.h"

#include

#include

#include

#include

extern

unsigned

short

int length_val;

extern

unsigned

char rxbuf[6]

,rxempty, rxcnt,rxflag,waitflag;

extern

unsigned

int timeout;

intmain

(void);

unsigned

char str=

; led.

initialize()

; timer3.

initialize()

;extix_init()

;//外部中斷初始化

usart6_init

(9600);

usart4.

initialize

(9600);

send_data_to_usart6

('s');

send_data_to_usart6

('5');

send_data_to_usart6

('-');

send_data_to_usart6

('1');

send_data_to_usart6

('#');

//設為被動讀取模式

delay_ms(10

);rxcnt=0;

usart4.

printf

("hello! i am icore3!\r\n");

//串列埠4輸出

// usart_send_string(uart4,string);

usart_send_string

(usart6,str)

;// delay_ms(50);

usart_send_string

(usart6,string)

;while(1

)}} rxflag =0;

rxcnt =0;

usart_send_string

(uart4,rxbuf);}

delay_ms

(500);

}}

基於stm32f407建立stm32F427工程

分為三個部分 1.啟動檔案 2.fwilib 包含兩個資料夾inc和src。src裡面是stm32資源的c檔案,inc則是32資源的h檔案 3.user這也是我不太理解的部分 ddbugconfig只包含了用於debug的初始化,則是f4的系統檔案。我是在f407的基礎上改的 總的來說 1.改了晶元...

stm32f4 定時捕獲

概述 1000hz 20 80 占空比現象 1000hz 51 58 占空比現象 關於本文的更多詳情請往下看。筆者針對於初學者提供的例程都是去掉了許多不必要的功能,精簡了官方的 對初學者一看就明白,以簡單明瞭的工程供大家學習。stm32f4 tim輸入波形捕獲 脈衝頻率 占空比 例項 訪問密碼 st...

STM32F4與STM32F1的區別

作為cortex m3市場的最大佔有者,st公司在2011年又推出基於cortex m4核心的stm32f4系列產品,相對與stm32f1 f2等cortex m3產品,stm32f4最大的優勢,就是新增了硬體fpu單元以及dsp指令,同時,stm32f4的主頻也提高了很多,達到168mhz 可獲得...