ultrasonic.h
来自「超声波测距 超声波测距程序,AT89S52超声波测距仪设计方法 超声波测距 超声」· C头文件 代码 · 共 48 行
H
48 行
#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 + =
减小字号Ctrl + -
显示快捷键?