新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2017-6-7
- 在线时间
- 1 小时
|
#include"echo.h"
#include"sys.h"
#include"delay.h"
//将超声波的Trig口电平先拉低,再发送高于10微秒的高电平,用PF2
void sendhigh(u16 hightime)
{
//发送大于10微秒的高电平
GPIO_SetBits(GPIOF,GPIO_Pin_2);
delay_us(hightime);
GPIO_ResetBits(GPIOF,GPIO_Pin_2);
}
void Trig_Init()
{
GPIO_InitTypeDef GPIO_InitTypeTEXT;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);//使能时钟
GPIO_InitTypeTEXT.GPIO_Mode =GPIO_Mode_Out_PP;
GPIO_InitTypeTEXT.GPIO_Pin =GPIO_Pin_2;
GPIO_InitTypeTEXT.GPIO_Speed =GPIO_Speed_50MHz;
GPIO_Init(GPIOF,&GPIO_InitTypeTEXT);
GPIO_ResetBits(GPIOF,GPIO_Pin_2);//拉低Trig口的电平
}
//输入捕获,设置PB0为io口接受捕获的高电平时间
void TIM3_Cap_Init(u16 arr,u16 psc)
{
TIM_ICInitTypeDef TIM3_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //使能TIM3时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能GPIOB时钟
GPIO_InitStructure.GPIO_Pin |
|