Microcontroller › 8051 › Interfacing AT89S51 with ultrasonic sensor and LCD › please explain
January 21, 2016 at 3:42 pm
#13644
Shirsendu Das
Participant
Please explain the calculation part,
And why you use for loop 10times.
And the delay function.)????!!!
void Distance_Measure()
{
count=count1=0;
TH0=0x00;TL0=0x00;
TR0=0;
for(i=0;i<10;i++)
{
TX=0;
Delay(1000);
TX=1;
Delay(10);
TX=0;
while(RX==0);
TR0=1;
while(RX==1);
TR0=0;
count=TH0<<8;
count=count|TL0;
TH0=TL0=0x00;
count1=count1+count;
Delay(5000);
}
count=count1/10;
inch1=count%10000/1000;
inch2=count%1000/100;
result=(inch1*10)+inch2;
obj_distance=result-2;
Lcd8_Decimal3(0XCb,obj_distance);
}