话不多说,自己下载研究。用的STM32F103C8T6,引脚自己打开程序里面看。串口输出四路超声波检测结果,单位cm。
单片机源程序如下:
- /**
- ******************************************************************************
- * @file main.c
- * @author fire
- * @version V1.0
- * @brief 串口中断接收测试
- */
-
- #include "stm32f10x.h"
- #include "bsp_usart1.h"
- #include "stdio.h"
- #include "timer2_cap.h"
- #include "UltrasonicWave.h"
- #include "delay.h"
- /**
- * @brief 主函数
- * @param 无
- * @retval 无
- */
- int main(void)
- {
- unsigned char count=0;
- delay_init();
- /* USART1 配置模式为 115200 8-N-1,中断接收 */
- USART1_Config();
-
- NVIC_Configuration();
-
- TIM2_Cap_Init(0xffff,72-1); //以1Mhz的频率计数
- UltrasonicWave_Configuration();
-
- while(1)
- {
- switch(count)
- {case 0:UltrasonicWave_StartMeasure();
- count=1;
- break;
- case 1:UltrasonicWave_StartMeasure2();
- count=2;
- break;
- case 2:UltrasonicWave_StartMeasure3();
- count=3;
- break;
- case 3:UltrasonicWave_StartMeasure4();
- count=0;
- break;
- }
-
- printf("1:%d|2:%d|3:%d|4:%d\n",tempup1,tempup2,tempup3,tempup4);
- delay_ms(500);
- if(tempup1<=300)
- {
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
- delay_ms(1000);
-
- }
- else
- {
- delay_ms(1000);
- }
- }
- }
- /*********************************************END OF FILE**********************/
复制代码
所有资料51hei提供下载:
STM32F103C8T6四通道超声波检测(串口).rar
(339.43 KB, 下载次数: 74)
|