⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ultrasonic.h

📁 超声波测距 超声波测距程序,AT89S52超声波测距仪设计方法 超声波测距 超声波电路单片机 超声波发射接收电路 超声波 单片机测距
💻 H
字号:
#ifndef __Ultrasonic_H__
#define __Ultrasonic_H__

unsigned char temp_time1,temp_time2;

void INT0_Ultrasonic() interrupt 0 using 2
{
	flag=1;//外部中断标志位
	TR0=0;//关定时器0
	ET0=0;//关外部中断
	//EA=0;
	temp_time1=TL0;
	temp_time2=TH0;
	if((temp_time1!=0)&&(temp_time2!=0))
	{
		high_time=TH0;
		low_time=TL0;
	}
}

float Distance_count()//距离计算函数
{
	float temp;
	temp=high_time*256+low_time;	
	temp=((temp/1000)/1000)/2;
	temp*=340;
	return temp;
}

void Send_wave()//脉冲波发送
{
	uchar i;
	TH0=0;
	TL0=0;//清定时0
	TR0=1;//开定时0
	for(i=0;i<3;i++)
		{
			vout=~vout;//超声波发送引脚
			_nop_();_nop_();_nop_();
			_nop_();_nop_();_nop_();
		}
	vout=1;
	EX0=1;//开外部中断	
	//EA=1;
}

#endif 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -