2 u012052289 u012052289 于 2014.03.06 20:55 提问

hc-sr04驱动 问题:烧入开发板之后,结果距离隔一段时间就突然增大。请大侠解答。

请各位大侠帮我看看我的驱动程序那里有问题。
sbit TRIG = P3^3;
sbit ECHO = P3^2;
void Measure(void)
{
unsigned long Time;
uint Distance,ge,shi,bai;
float D;
ECHO = TRIG = 0;
TMOD = 0X11;
TH1 = 0XFF;
TL1 = 0XF1;
TH0 = TL0 = 0;
IE = 0X8A;
TRIG = 1;
TR1 = 1;
while(!ECHO){}
TR1 = 0;
TR0 = 1;
while(ECHO){}
TR0 = 0;
Time = TH0*256+TL0;
Distance = ((unsigned long)Time*344)/2000;
D = Distance/10.0;
if(Distance>0&&Distance<900)
{
bai = Distance/100;
shi = Distance/10-(bai*10);
ge = Distance-bai*100-shi*10;
Dis0[0] = bai+'0';
Dis0[1] = shi+'0';
Dis0[2] = '.';
Dis0[3] = ge+'0';
}
else
Dis0[0] = Dis0[1] = Dis0[2] = Dis0[3] = '0';

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!