📄 ultrasonic.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 + -