Microcontroller › 8051 › Interfacing AT89S51 with ultrasonic sensor and LCD › #include
March 21, 2013 at 6:51 am
#9360
rohit pandey
Participant
#include<REGX51.h>
#include<intrins.h>// for using _nop_() function
sfr16 DPTR =0x82;
sbit trig=P3^1;
void send_pulse(void) //to generate 10 microseconds delay
{
TH0=0x00;TL0=0x00;
trig=1;
_nop_();_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();_nop_();
trig=0;
}
unsigned char get_range(void)
{
unsigned char range;
send_pulse();
while(!INT0);// in sake of these lines you can generate a delay of 40 Milli seconds=40000 micro
while (INT0);// seconds
DPH=TH0;DPL=TL0;
TH0=0xFF;TL0=0xFF;
if(DPTR<35000)//actually you need to use 38000 but the sensor may not work at higher levels
range=DPTR/59;
else
range=0; // indicates that there is no obstacle in front of the sensor
return range;
}
void main()
{
TMOD=0x09;//timer0 in 16 bit mode with gate enable
TR0=1;//timer run enabled
TH0=0x00;TL0=0x00;
P1=0xff;
P3|=0x04;//setting pin P3.2
}
this is my code please help me in howing distance on led as above mentioned led code it is giving me errors please patch them into this