EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
You are here: Home / Topics / Interfacing of three sensors with 8051 together.

Interfacing of three sensors with 8051 together.

|

Microcontroller › 8051 › Interfacing of three sensors with 8051 together.

  • This topic has 2 replies, 2 voices, and was last updated 9 years, 5 months ago by Pradip Saikia.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • March 5, 2013 at 11:50 am #2161
    Pradip Saikia
    Participant

    Hi all I want to interface a temp sensor (LM35) , a Light sensor (LDR) & a Humidity sensor together to a 8051 MC (p89v21rd2) using adc0808. Plz help me how can I write the program in c. Plz help me…

    March 5, 2013 at 4:07 pm #9248
    preethi
    Participant

    The input which is to be converted to digital form can be selected by using three address lines using three address lines. So, that you can connect three sensors at a time..

    the code is as follows… but you have to write the logics of 3 sensors which you are using….i have left space for that ..and also once check the ports that you are using for adc, lcd connection as per your circuit diagram..i have declared roughly..

     

    #include<reg51.h>
    sbit ale=P1^0;       // Address latch enable
    sbit oe=P1^3;        // Output enable
    sbit sc=P1^1;            // Start conversion
    sbit eoc=P1^2;          // End of conversion
    sbit clk=P1^7;           // Clock
    sbit ADD_A=P1^4;      //Address pins for selecting input channels.
    sbit ADD_B=P1^5;
    sbit ADD_C=P1^6;
    sfr lcd_data_pin=0xA0;  //Port P2
    sbit rs=P3^0;
    sbit rw=P3^1;
    sbit en=P3^6;
    sfr input_port=0x80;  //Port P0
     
    void timer0  interrupt 1 ( )  // Function to generate clock of frequency 500KHZ using Timer 0 interrupt.
    {
    clk=~clk;
    }
     
    void delay(unsigned int count)  // Function to provide time delay in msec.
    {
    int i,j;
    for(i=0;i<count;i++)
      for(j=0;j<1275;j++);
    }
     
    void lcd_command(unsigned char comm)  //Function to send command to LCD.
    {
    lcd_data_pin=comm;
    en=1;
    rs=0;
    rw=0;
    delay(1);
    en=0;
    }
               
    void lcd_data(unsigned char disp)         //Function to send data to LCD.
    {
    lcd_data_pin=disp;
    en=1;
    rs=1;
    rw=0;
    delay(1);
    en=0;
    }
     
    lcd_data(unsigned char *disp)             //Function to send string data to LCD.
    {
    int x;
    for(x=0;disp[x]!=0;x++)
    {
      lcd_data(disp[x]);
    }
    }
     
    here you declare the function of your 3 sensors logic seperatly
     
    void lcd_ini()                        //Function to inisialize the LCD
    {
    lcd_command(0x38);                                 // for using 8-bit 2 row LCD
    delay(5);
    lcd_command(0x0F);                                 // for display on cursor blinking
    delay(5);
    lcd_command(0x80);
    delay(5);                                                              //Force cursor to blink at line 1 positon 0
    }
     
     
    void adc( )                                           //Function to drive ADC
    {
    while(1)
      {
       if(temp1==0)
       {
        ADD_C=0;                                               // Selecting input channel 1 using address lines
        ADD_B=0;
        ADD_A=0;
       }
       if(temp1==1)
       {
        ADD_C=0;  // Selecting input channel 2 using address lines
        ADD_B=0;
        ADD_A=1;
       }
       if(temp1==2)
       {
        ADD_C=0;                    // Selecting input channel 3 using address lines
        ADD_B=1;
        ADD_A=0;
       }
       delay(2);
       ale=1;
       delay(2);
       sc=1;
       delay(1);
       ale=0;
       delay(1);
       sc=0;
       while(eoc==1);
       while(eoc==0);
       oe=1;
       BCD();
       delay(2);
       oe=0;
       temp1++;
       if(temp1==3)
       temp1=0;
      }
    }
     
    void main( )
    {
      eoc=1;
        ale=0;
       oe=0;
       sc=0;
      TMOD=0x02;                     //Timer0 setting for generating clock of 500KHz using interrupt enable mode.
      TH0=0xFD;
      IE=0x82;
      TR0=1;
      temp1=0;
    key1=0;
    lcd_ini();
     
     
     
     
    here you add your desired sensor call statement
     
     
     
     
     
       adc( );
    }
    March 8, 2013 at 7:22 pm #9282
    Pradip Saikia
    Participant

    Plz complete this prog for LM35(temp sensor), LDR (light sensor) and HR201(humidity sensor). thanks

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Capacitor to eliminate speaker hum August 16, 2022
  • Help identify a part August 16, 2022
  • Digital Display Information August 16, 2022
  • Is there a discord for this forum? August 16, 2022
  • Peltier control August 16, 2022

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools