资源介绍
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit Echp = P2^1; //模块引脚
sbit Trig = P2^0;
sbit test =P1^0;
uint succeed_flag,time,timeL,timeH;
uint distance;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay(uint z)
{
uint x,y;
for (x=z;x>0;x--)
for(y=110;y>0;y--);
}
void delay_20us()
{
uchar a;
for(a=0;a<100;a++);
}
void display(uint temp)
{
uchar ge,shi,bai;
bai=temp/100;
shi=(temp0)/10;
ge=temp;
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
}
void main()
{
test=0;
Trig=0;
TMOD=0x10;
while(1)
{
EA=0;
TH1=0;
TL1=0;
Trig=1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
Trig=0;
while(Echp==0);
EA=1;
ET1=1;
TR1=1;
while(Echp!=0);
TR1=0;
EA=0;
time=TH1*256+TL1;
distance=time*0.01844;
display(distance);
}
}
下载里有完整板