Sunday, March 30, 2014

Ultrasonic Distance Finder By Using 89c51

Ultrasonic Distance Finder By Using  89c51

                                                       Bismiallah Hirahman Niraheem 

As you see below there are two code one is main code and another is a external function code and this is for serial transmit ...when main code call this function then serial transmission is occur .
Important thing is that i use cyrstal oscillator of   11.0592 Mhz    for serial communication ...12Mhz oscillator not worked .

You can Also DOWNLOAD  hex File from Link   given in the end of this page


Main Code :

#include <AT89X51.h>
#include <stdio.h>

extern void SerialTx(signed int);

sbit Trigger=P1^0;
sbit Eco=P1^1;
sbit Led=P1^2;

void main (void)
    int c;
    unsigned int t;
    float s;
    float f;

    SerialTx(-3);      // External Function Call  ( board rate 9600 )
TMOD=0x21;     //use Timer 1 in mode 2 and Timer 0 in mode 1 ,  {timer 0 } start and stop from externally

    Trigger=0;                          // Make trigger as output
    Eco=1;                              // Make Eco as Input
         TH0=0xD8;                     // initialized by  38ms  for Eco check

        for(c=0;c<1;c++);               // From calculation this is Aprox 14 usec delay
        while(Eco==0){ ; }                 //  Wait until eco = 0
        while(Eco==1)                       //  Wait until eco = 1
            if(TF0 == 1)
                 printf("Object is out of range...........\n ");     
                TF0 = 0;
        TR0 = 0;
        t = TH0;
        t = t<<8;
        t = t+TL0;
        t = t - 0xD8F0;
         s=.0165F*t;                       //formula for coverting into centimeter
        f=s*.0300F;                            //formula for converting into foots



        printf("Timer Exact Value = %u \n\n\n" ,t);                                              // Exact value
        printf("Counted Distance Value = %f cm \n\n\n " ,s);
        printf("Counted Distance Value = %f  Foot \n\n\n " ,f);                             // Calculated Distance

          External Function Serial Transmit   SerialTx


#include <reg51.h>
#include <stdio.h>
void SerialTx(signed int );
void SerialTx(signed int a)

TH1=a; //9600 baud rate  FD = -3

Download  Hex File Click Here  

Electronics Lab Created By Muhammad Irfan

No comments:

Post a Comment