当前位置:文档之家› 超声波测距C语言源程序代码

超声波测距C语言源程序代码

a = 1;
b = 1;
c = 0;
P2 =~ CharacterCode[GE];
delay(600);
if( (1 == moshi)&&(0 == t3) )
goto loop;
if(2 == moshi)
{
t3 = 2;
if(0 == QD)
goto loop;
}
}
}TL0 = 0x00;
/*1号定时器不用,所以没有TH1,TL1*/
b = 0;
c = 1;
P2 =~ CharacterCode[min[1]];
delay(100);
if(GX==0)//个位
{
P2=~0x00;
min[2]++;
if(min[2]==10)
min[2]=0;
delay(60000);
}
a = 1;
b = 1;
c = 0;
P2 =~ CharacterCode[min[2]];
}
a = 0;
b = 1;
c = 1;
P2 =~ CharacterCode[max[0]];
delay(100);
if(SX==0)//十位
{
P2=~0x00;
max[1]++;
if(max[1]==10)
max[1]=0;
delay(60000);
}
a = 1;
b = 0;
c = 1;
P2 =~ CharacterCode[max[1]];
#include<>
#define UC unsigned char
#define UI unsigned int
void delay(UI);sbit BX = P3^0;void TimeConfiguration();a = 0;
b = 0;
c = 0;
P2 =~ 0x00;goto loop;
}
}
}
else
{
beep = 1;
Lv = 1;
Hong = 1;
while( t3-- )
{
a = 0;
b = 1;
c = 1;
P2 =~ CharacterCode[BAI];
delay(600);
a = 1;
b = 0;
c = 1;
P2 =~ CharacterCode[SHI];
delay(600);
min[0]=0;
delay(60000);
}
a = 0;
b = 1;
c = 1;
P2 =~ CharacterCode[min[0]];
delay(100);
if(SX==0)//十位
{
P2=~0x00;
min[1]++;
if(min[1]==10)
min[1]=0;
距C语言源程序代码
/*{HZ即单位s的倒数}本晶振为12MHZ,因此外部的时钟频率为12MHZ,所以内部的时钟频率为(12MHZ)/12=1MH
即1000000HZ,而机械频率为1/(1MHZ),即每完成一次计算(即定时器的值加一)用时,
即1us(微秒).*/
/***********************************************************************************/
{
Lv = 0;
Hong = 1;
while( t2-- )
{
a = 0;
b = 1;
c = 1;
P2 =~ CharacterCode[BAI];
delay(500);
a = 1;
b = 0;
c = 1;
P2 =~ CharacterCode[SHI];
delay(500);
a = 1;
b = 1;
c = 0;
P2 =~ CharacterCode[GE];
delay(400);
beep = 0;
delay(100);
beep = 1;
if( (1 == moshi)&&(0 == t2) )
goto loop;
if(2 == moshi)
{
t2 = 2;
if(0 == QD)
goto loop;
}
time = TL0 + TH0*256;juli = ( int )( (time*/2 );
BAI = ( (juli%1000)/100 );SHI = ( (juli%100)/10 ); GE = ( juli%10 );
/******************************************两种模式的距离显示********************************************/
}
/***********************************************************************************/
void xiaxian()//修改下限
{
while(1)
{
if(BX==0)//百位
{
P2=~0x00;
min[0]++;
if(min[0]==10)
delay(100);
if(GX==0)//个位
{
P2=~0x00;
max[2]++;
if(max[2]==10)
max[2]=0;
if(juli > MAX)
{
Hong = 0;
Lv = 1;
while( t1-- )
{
a = 0;
b = 1;
c = 1;
P2 =~ CharacterCode[BAI];
delay(400);
a = 1;
b = 0;
c = 1;
P2 =~ CharacterCode[SHI];
delay(400);
delay(100);
if(QD==0)
{
a = 0;
b = 0;
c = 0;
P2 = 0xff;
break;
}
}
}
void shangxian()//修改上限
{
while(1)
{
if(BX==0)//百位
{
P2=~0x00;
max[0]++;
if(max[0]==10)
max[0]=0;
delay(60000);
a = 1;
b = 1;
c = 0;
P2 =~ CharacterCode[GE];
delay(390);
beep = 0;
if( (1 == moshi)&&(0 == t1) )
goto loop;
if(moshi == 2)
{
t1 = 2;
if(0 == QD)
goto loop;
}
}
}
else if(juli < MIN)
相关主题