Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[51] Interfacing HC-SR04 ultrasonic distance sensor with at89c2051

Status
Not open for further replies.

Sidaray

Newbie level 2
Joined
Aug 12, 2014
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
22
Hi sir,
I am using keil, In program for trigger pin i am giving 10us of pulse as data sheet of ultrasonic sensor but it is not responding through echo pin, P1.7=trigger and P1.6 echo pin.
Here i am not getting the problem whether it is in circuit connection or in code, But the same connection which i am using for led blink and sending data serially its working fine, Problem is in ultrasonic.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
sbit trig=P1^7;
sbit echo=P1^6; 
sbit led=P1^5;
 
unsigned int y,z,x,m;
unsigned char c,d=0,e;
 
void serial_init()
{
//  delay(50);
    TMOD = 0x21;
    TH1 = 0xFD; //set baud rate to 9600
    SCON = 0x50; //mode 1 and recieve enable
    TR1 = 1;    //Turn ON Timer
}
 
void delay(unsigned int n)  
{
    unsigned int i,j;
    for(i=0;i<n;i++)
    {
        for(j=1275;j>0;j--);
    }
}
 
void pulse()
{
//  TMOD=0x01;
 
    //trig=1;
    TH0=0xff;
    TL0=0xf7;
    trig=1;
    TR0=1;
    while(TF0==0);
    TR0=0;
    TF0=0;
    trig=0; 
 
}
 
 void conversion(ch1)
{
 // unsigned char a,b,c,d,e;
    unsigned char a,b;
    a=ch1;      //FOR CONVERSION TO ACTUAL ROOM TEMPERATURE
    b=a/10;
    c=a%10;
    d=b/10;
    e=b%10;
 
    d=d+0x30;
    e=e+0x30;
    c=c+0x30;
 
    
    delay(1);
    delay(1);
    delay(1);
    delay(1);
}
 
void main()
{
    trig=0;
    echo=1;
    led=0;
    TMOD=0X01;
    echo=0;
    trig=0;
 
 
 
    while(1)
    {
    //  TMOD=0X01;
        pulse();
        TH0=TL0=0x00;
        while(!echo);
        TR0=1;
        while(echo);
            TR0=0;
 
        x=TH0;
        m=TL0;
        y=(x*256)+m;
 
        d=(y*1.085)/58;   
        if(d==10)
        {
        led=1;  
        }
        conversion(d);
 
                     serial_init();
                     SBUF='R';
                     while(!TI);
                     TI=0;
                     SBUF=d;
                     while(!TI);
                     TI=0;
                     SBUF=e;
                     while(!TI);
                     TI=0;
                     SBUF=c;
                     while(!TI);
                     TI=0;
                     SBUF=0x0D;
                     while(!TI);
                     TI=0;
                     delay(50);
        
    }
}

 
Last edited by a moderator:

What microcontroller are you using..?
Also it looks to me,reading from your program,that you are building a temperature sensing system for your home.Am I right..?
If not,then explain what are you trying to do through the program.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top