Microcontroller › 8051 › Interfacing AT89S51 with ultrasonic sensor and LCD
- This topic has 40 replies, 28 voices, and was last updated 6 years, 2 months ago by Shirsendu Das.
-
AuthorPosts
-
October 7, 2015 at 7:54 am #13360Nilesh BhavsarParticipant
#include
/* LPC21xx definitions */ #include "lcd.h" void LCD_Init(void); unsigned char String1[16]={" iblocks "}; unsigned char String2[16]={" ARM LPC2148 "}; unsigned int ultrasonic_read() { int b; T1TCR = 0x01; T1TC=0; T1PR=0; T1PC=0; IO1SET =(1<<16); // trig pin of ultrasonic sensor Delay1(100); IO1CLR =(1<<16); while((IO1PIN &0x00020000)==0); //echo pin of ultrasonic sensor T1TCR = 0x00; //enable timer while((IO1PIN &0x00020000)==1); T1TCR = 0x01; //stop timer b=T1TC; return b; } int main(void) { unsigned int a; PINSEL0 = 0x00000000; // Enable GPIO on all pins PINSEL1 |= 0x15000000; PINSEL2 = 0x00000000; Delay(20); IO0DIR = (1<<22) | (1<<21) | (1<<20) | (1<<19) | (1<<18) | (1<<17) | (1<<16); // Set P0.16, P0.17, P0.18, P0.19, P0.20, P0.21, P0.22 as Output IO1DIR =(1<<16)|(0<<17); LCD_Init(); // Initialize LCD LCD_Command(0x01); Delay(20); LCD_Command(0x80); LCD_String(&String1[0]); LCD_Command(0xC0); LCD_String(&String2[0]); Delay(200); LCD_Command(0x01); LCD_String("value:"); while(1) { a=ultrasonic_read(); LCD_Command(0xc0); LCDWriteInt(a,3); } } January 21, 2016 at 3:42 pm #13644Shirsendu DasParticipantPlease 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);
}January 28, 2016 at 5:20 am #13662abhishekParticipanthi…
this is abhishek shettar,plz help me i want to ARM7 code for ultersonic sensor…if u have send me
my email id is:[email protected]
February 20, 2016 at 9:45 am #13720Sarika DevkarParticipantTHANK YU..
March 31, 2016 at 8:57 am #13830zaid hussamParticipantplease , i want the block circuit and the program to the ultrasonic finder distance with lcd using at89s51
April 2, 2016 at 8:45 am #13844apoorvaParticipantcan someone provide me the code using lcd to display the distance in Keil uvision software ??
November 25, 2016 at 7:31 am #14246prasannakumarParticipanthi,
can any body tell me how measure distance using ultasonic sensor HC-SR04 using lpc2148
March 4, 2017 at 12:59 pm #14503pranaliParticipanti want to interface buzzer and ultrasonic with 8051 can u pls hlp….
March 7, 2017 at 7:13 am #14509Hari Prasaath KParticipantUltrasonic sensor uses a technique called ECHO in which you somthing reflecting back after striking from the surface. sensor provides an output signal proportional to distance based on the echo. The sensor here generates a sound vibration in ultrasonic range upon giving a trigger, after that it waits for the sound vibration to return.
steps to calculate distance:
1. Triggering the sensor by pulling up the trigger pin for atleast 12uS.2. Once echo goes high we get an external interrupt and we are going to start a counter (enabling a counter) in the ISR (Interrupt Service Routine) which is executed right after an interrupt triggered.3. Once echo goes low again an interrupt is generated, this time we are going to stop the counter (disabling the counter).4. So for a pulse high to low at echo pin, we have started a counter and stopped it. This count is updated to memory for getting the distance, as we have the width of echo in count now.5. We are going to do further calculations in the memory to get the distance in cm6. The distance is displayed on 16×2 LCD display.September 14, 2017 at 5:23 am #14662AnonymousGuestI want the same program using 8051 microcontroller only… Plz help me out…
January 30, 2018 at 6:29 pm #14704Shirsendu DasParticipant#this function will only work on 8051 @12MHz
unsigned int get_distance()
{
unsigned int time;
trig=1;trig=1;trig=1;trig=1;trig=1; // 5us /
TMOD=0x01; // 2us / use timer0 16 bit mode
TH0=0x00; // 1us / clear reg
TL0=0x00; // 1us / clear reg
trig=0; // 1us / Total(5+2+1+1+1)=10us
while(!echo); // Wait until echo beome high
TR0=1; // Start the Timer
while(echo); // Wait until echo become low
TR0=0; // Stop the timer
time=((TH0<<+TL0)/58; // Load timer value to register. 58us per cm.
return time;
} -
AuthorPosts
- You must be logged in to reply to this topic.