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 / how to display ADC values to 16×2 LCD

how to display ADC values to 16×2 LCD

|

Microcontroller › 8051 › how to display ADC values to 16×2 LCD

  • This topic has 8 replies, 3 voices, and was last updated 8 years, 5 months ago by shruthikandakatla.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • March 15, 2011 at 11:49 am #798
    romel emperado
    Participant

    guys i have problem on converting my ADC output values to String and display it to 16×2 LCD.. Im using keil compiler.. i have the code and its almost done…

    #include <REG51.H>

    #define adc_port P3
    #define LCD P2
    #define LCD_EN        0x80
    #define LCD_RS        0x20

    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;

    //LCD Commands       

    #define LCD_SETMODE       0x04
    #define LCD_SETVISIBLE       0x08
    #define LCD_SETFUNCTION       0x28
    #define LCD_SETDDADDR       0x80
                        

    void delayms(unsigned char);
    void delayus(unsigned char);
    void lcd_init();
    void lcd_reset();
    void lcd_cmd (char);
    void lcd_data(unsigned char);
    void lcd_str (unsigned char*);

    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 select_channel(char c,char b,char a)
    {
      ADD_A = a;
      ADD_B = b;
      ADD_C = c;
    }

    void convert()
    {
      delay(1);
      ale=0;      //activate the ale PIN
      ale=1;
      sc=1;         //initaite convertion
      sc=0;
      delay(1);

    }
    void read_adc()
    {

       while(eoc == 0);     //end of convertion
       oe = 1;             //enable adc output
       delay(1);
       oe = 0;
       delay(1);

    }

    void main()
    {

     

      adc_port = 0xff;
     
      TMOD =  0x22;  //timer0 setting for generating clock of 500KHz using interrupt enable mode.
      TH0  =  0xFD;
      IE   =  0x82;
      TR0  =  1;
      lcd_init();

     while(1)
     {
      
       select_channel(0,0,1);
       convert();
       read_adc();

      
       lcd_cmd(0x80);            // 1st line address
       lcd_str(“WindV: ” );

       lcd_cmd(0xC0);              // 2nd line address
       lcd_str(“BattV: “);
      

     }
    }

    void delayus(unsigned char delay)
    {
        while(delay–);
    }

    void delayms(unsigned char delay)
    {
        while(delay–)
        delayus(149);
    }

    void lcd_reset()
    {
        LCD = 0xFF;
        delayms(40);
        LCD = 0x03+LCD_EN;
        LCD = 0x03;
        delayms(40);
        LCD = 0x03+LCD_EN;
        LCD = 0x03;
        delayms(5);
        LCD = 0x03+LCD_EN;
        LCD = 0x03;
        delayms(5);
        LCD = 0x02+LCD_EN;
        LCD = 0x02;
        delayms(5);
    }

    void lcd_init ()
    {
        lcd_reset();
        lcd_cmd(LCD_SETFUNCTION);                    // 4-bit mode – 1 line – 5×7 font.
        lcd_cmd(LCD_SETVISIBLE+0x04);                // Display no cursor – no blink.
        lcd_cmd(LCD_SETMODE+0x02);                   // Automatic Increment – No Display shift.
        lcd_cmd(LCD_SETDDADDR);                      // Address DDRAM with 0 offset 80h.
     }

     void lcd_cmd (char cmd)
    {
        LCD = ((cmd >> 4) & 0x0F)|LCD_EN;
        LCD = ((cmd >> 4) & 0x0F);

        LCD = (cmd & 0x0F)|LCD_EN;
        LCD = (cmd & 0x0F);
        delayus(250);
        delayus(250);
    }

    void lcd_data (unsigned char dat)
    {
        LCD = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
        LCD = (((dat >> 4) & 0x0F)|LCD_RS);
       
        LCD = ((dat & 0x0F)|LCD_EN|LCD_RS);
        LCD = ((dat & 0x0F)|LCD_RS);
        delayus(250);
        delayus(250);
    }

    void lcd_str (unsigned char *str)
    {
        while(*str)
        {
            lcd_data(*str++);
        }
    }

    March 15, 2011 at 12:05 pm #5752
    dagakshay
    Participant

    to display the numbers on LCD you have to add 48 in the asii number..
    for example you have unsigned char i=1;
    LCD_write(i+48);

    just try that…(i din’t put my hand in your magii….. {code})… 

    March 15, 2011 at 1:16 pm #5755
    romel emperado
    Participant

    why it is displaying weird characters?
    float volt;

       volt = ((volt * 5)/256) * 4.2;
       lcd_data(volt+48);

    pls give some example.. this is my first project… :)

    March 16, 2011 at 4:33 am #5765
    dagakshay
    Participant

    http://www.engineersgarage.com/microcontroller/8051projects/display-number-LCD-AT89C51-circuit 

    April 4, 2011 at 2:25 am #5868
    romel emperado
    Participant

    it’s now okay.. I just use mikroC builtit Library.. hehe

    April 4, 2011 at 4:49 am #5874
    dagakshay
    Participant

    using inbuilt library is a good option but you must know how actully the thing works…

    April 4, 2011 at 2:49 pm #5884
    romel emperado
    Participant

    yeah.. i might know that if you teach me.. hehe

    April 5, 2011 at 5:13 am #5895
    dagakshay
    Participant

    mha pleasure….

    February 19, 2014 at 8:48 am #11057
    shruthikandakatla
    Participant

    can u please mail me the circuit diagram for this code…

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

RSS Recent Posts

  • How to power up two stereo audio amplifiers from a single source of power supply August 11, 2022
  • uc3843 Buck-boost August 11, 2022
  • Drill speed controller fault August 11, 2022
  • Code suggestion from Android Studio. Good? August 11, 2022
  • Nokia 5110 HW in Oshonsoft August 11, 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