Home > other >  Big help genuflect is begged! Written in 51 single chip ultrasonic ranging, always shows zero, I don
Big help genuflect is begged! Written in 51 single chip ultrasonic ranging, always shows zero, I don

Time:12-01

#include
#include
# define uchar unsigned char
# define uint unsigned int
Uchar code shuzi []={x5b x3f 0, 0 x06, 0, 0 x4f,
X6d 0 x66, 0, 0 x7d, 0 x07,
X6f 0 x7f, 0, 0 x77, 0 x7c,
X5e 0 x39, 0, 0 x79, 0 x71
};
Unsigned long time;
Bit flag.
Sbit dula=P2 ^ 6;
Sbit wela=P2 ^ 7;
Sbit trig P1=^ 0;
P1 sbit echo=^ 1;
//millisecond delay function
Void delayms (XMS)
{
Uchar I, j;
for(i=xms; I> 0; I -)
For (j=110; J> 0; j--);
}
//delay millisecond
Void delayus (uchar xus)
{
Uchar I;
For (I=xus; I> 0; I -)
_nop_();
}
//digital tube display function
Void the display (uint temp)
{
Uchar qian, bai, shi ge;
Qian=temp/1000;
Bai temp %=1000/100;
Shi=temp % 1000% 100/10;
Ge=temp % 1000% 100% 10;

Dula=1;
P0=shuzi [qian];
Dula=0;
P0=0 XFF;
Wela=1;
P0=0 xfe;
Wela=0;
Delayms (5);

Dula=1;
P0=shuzi (bai);
Dula=0;
P0=0 XFF;
Wela=1;
P0=0 XFD;
Wela=0;
Delayms (5);

Dula=1;
P0=shuzi (shi);
Dula=0;
P0=0 XFF;
Wela=1;
P0=0 XFB;
Wela=0;
Delayms (5);

Dula=1;
P0=shuzi (ge),
Dula=0;
P0=0 XFF;
Wela=1;
P0=0 xf7;
Wela=0;
Delayms (5);

}
Void Init ()
{
Trig=0;
Echo=0;
TMOD=0 x01;
EA=1;
ET0=1;
TH0=0;
TL0=0;
Flag=0;
}
Void the count ()
{
Uint short;
Time=TH0 * 256 + TL0;
TH0=0;
TL0=0;
Short=time * 0.01853;
If ((distance> 400) | | flag==1)
{
Flag=0;
Display (100);
}
The else
{
The display (short);
}
}
Void main ()
{
The Init ();
While (1)
{
Trig=1;
Delayus (20);
Trig=0;
while(! Echo);
TR0=1;
While (echo)
TR0=0;
The count ();
}
}
Void time0 () interrupt 1
{
Flag=1;
TH0=0;
TL0=0;
}

CodePudding user response:

Using the hardware emulation to look so faster than only look at the code

CodePudding user response:

This things no hardware drawings see don't understand, make sure the hardware is there any trouble,
  • Related