这本人作构成,总成本约150元啊
这构成图
这效果视频
下面控制单片机核心C语言代码
/***********************************************************************************************************/
//HC-SR04 超声波测距模块 DEMO 程序
//晶振:11。0592
//接线:模块TRIG接 P1.2 ECH0 接P1.1
//串口波特率9600
/***********************************************************************************************************/
// #include
#include
#include
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit RX=P0^1;
sbit TX=P0^2;
unsigned int time=0;
unsigned int timer=0;
float S=0;
bit flag =0;
sbit Led1=P2^1;
sbit Led2=P2^2;
unsigned char busy=0;
/***********************************************************************
引脚定义:串行口1: 发送————TxD/P3.1; 接收————RxD/P3.0
串行口2: 发送————TxD2/P1.3;接收————RxD2/P1.2
功能描述:STC12双串口通信(中断方式)
***********************************************************************/
#define S2RI 0x01 //串口2接收中断请求标志位
#define S2TI 0x02 //串口2发送中断请求标志位
/****************串行口初始化函数************