US-100超声波(测距与测温)基于stm32f103源码------方式串口通信(测距与测温)

///======================US100.c=================================

#include "US100.h"

#include "systick.h"
#include "usart.h"


extern char RxCounter2,RxBuffer2[100];


char buff[100] = {0};
int tem = 0;
int distance = 0;
int index = 0;
void clear_buff2()//串口2缓存清理函数
{
	int i;
	for(i=0;i<100;i++)
	RxBuffer2[i]=0;
	RxCounter2=0;
	index=0;
}
void readTembuff()//读取温度与距离 :周期36+55+5=96ms;频率约等于10hz
{
	UART2_send_byte(0x55);//发送测距命令
	delay_ms(36);
	delay_ms(55);
	UART2_send_byte(0x50);//发送测温命令
	delay_ms(5);
	distance = RxBuffer2[0]*256+RxBuffer2[1];
	tem = RxBuffer2[2]-45;
	clear_buff2();
}

========&#
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值