基本信息
源码名称:超声波测距
源码大小:6.79M
文件格式:.zip
开发语言:C/C++
更新时间:2015-08-11
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
文件为压缩包,解压后是一个Keil工程。板子是stm32f103ze,串口输出。
int main(void) { BSP_Init(); while(1) { if(eventMeasureACC) { eventMeasureACC = false; task_MeasureACC(); } } } void BSP_Init(void) { __set_PRIMASK(1); TIM_Config(); USART_Config(); GPIO_Config(); __set_PRIMASK(0); } void task_MeasureACC(void) { GPIO_SetBits(GPIOA,GPIO_Pin_11); Wait10us(3); GPIO_ResetBits(GPIOA,GPIO_Pin_11); time=0; while((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12))==NULL) { } Tick10us=0; while((GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_12))!=NULL) { } time=Tick10us; distance=(float)time*10/58.82; if(distance<500) printf("距离为: %f 厘米\r\n",distance); else printf("超出测试距离.\r\n"); } void GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init(GPIOA, &GPIO_InitStructure); }