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
  • Advertise
You are here: Home / Topics / Temperature display on LCD

Temperature display on LCD

|

Microcontroller › AVR › Temperature display on LCD

  • This topic has 13 replies, 7 voices, and was last updated 13 years, 2 months ago by AJISH ALFRED.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • March 19, 2011 at 1:48 pm #809
    hardeep
    Participant

    Hello everyone,
    I have interfaced 16×2 LCD and LM35 to atmega16….
    The temperature value is not getting printed on the LCD…its a garbage value coming…some special and different symbols…
    plz help me to convert hex value of adc to ascii to display on lcd…
    i am attaching my code too…

    #include<avr/io.h>
    #include<util/delay.h>
     
    #define LCD_DATA PORTB // LCD data port
    #define ctrl PORTA
    #define en PA7 // enable signal
    #define rw PA6 // read/write signal
    #define rs PA5 // register select signal
     
    //


     
     
    unsigned int ascii(unsigned char x)
    {
                if (x<9)
    x=x+0x30;
    if (x>9)
    x=x+0x37;
    return (x);
    }
    unsigned int ADC_read(unsigned char ch)
    {
    ch= ch & 0b00000111; // channel must be b/w 0 to 7
    ADMUX |= ch; // selecting channel
     
    ADCSRA|=(1<<ADSC); // start conversion
    while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
    ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it
     
    return (ADC);
    }
    void ADC_init1(void) // Initialization of ADC
    {
    int intt=0b10000000;
    SREG=SREG|intt;
    ADMUX=(1<<REFS0); // For Aref=AVcc;
       ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE);
    }
    void LCD_cmd(unsigned char cmd)
    {
    LCD_DATA=cmd;
    ctrl &=~ (1<<rs);
    ctrl&=~(1<<rw);
    ctrl|=(1<<en); // RS and RW as LOW and EN as HIGH
    _delay_ms(1);
    ctrl &=~ (1<<rs);
    ctrl&=~(1<<rw);
    ctrl&=~(1<<en); // RS, RW , LOW and EN as LOW
    _delay_ms(50);
    return;
    }
     
    void LCD_write(unsigned char data)
    {
    LCD_DATA= data;
    ctrl |= (1<<rs);
    ctrl&=~(1<<rw);
    ctrl|=(1<<en); // RW as LOW and RS, EN as HIGH
    _delay_ms(2);
    ctrl |= (1<<rs);
    ctrl&=~(1<<rw);
    ctrl&=~(1<<en); // EN and RW as LOW and RS HIGH
    _delay_ms(2); // delay to get things executed
    return ;
    }
    void init_LCD(void)
    {
    LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
    _delay_ms(1);
     
    LCD_cmd(0x01); // clear LCD
    _delay_ms(1);
     
    LCD_cmd(0x0E); // cursor ON
    _delay_ms(1);
     
    LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
    _delay_ms(1);
    return;
    }
      
     
    //


    int main(void)
    {
    unsigned int value_t;
    DDRB=0xff;
    PORTB=0x00;
    DDRA=0xfc;
    PORTA=0x02;
    init_LCD();
    _delay_ms(5);
    int temp;
    LCD_write(‘T’);
    LCD_write(‘E’);
    LCD_write(‘M’);
    LCD_write(‘P’);
    LCD_write(‘E’);
    LCD_write(‘R’);
    LCD_write(‘A’);
    LCD_write(‘T’);
    LCD_write(‘U’);
    LCD_write(‘R’);
    LCD_write(‘E’);
    LCD_write(‘=’);
    LCD_cmd(0xC0);
    _delay_ms(1);
    ADC_init1();
    while(1)
    {
    value_t=ADC_read(0x01);
    _delay_ms(1);
    value_t=(5.00*value_t*100.00)/1023.00;
    temp=value_t;
    temp=temp&0xf0;
    temp=temp>>4;
    ascii(temp);
    LCD_write(temp);
    _delay_ms(10);
    temp=value_t;
    temp=temp&0x0f;
    ascii(temp);
    LCD_write(temp);
    LCD_cmd(0xC0);
    _delay_ms(1);
    }
     
    }
     
     
     
     
     
     
     

     

    March 21, 2011 at 2:03 pm #5780
    Amit Joshi
    Participant

    as you get digital value you have to extract unit, decade and hundred position values. by dividing and taking remainder . for example

    for(i=0;i<2;i++)
    {
    ar=value%10;
    value=value/10;
    }
    for example if you get 123 you will found following values-
    when i=0;
    ar[0]=3;
    value=12;

    when i=1
    ar[1]=2
    value=1

    when i=2
    ar[2]=1
    value=0

    add 0x30 in ar values and print it one by one.

    hope this method will work

    March 21, 2011 at 4:57 pm #5783
    hardeep
    Participant

    Thanks a lot buddy…
    bt when i use this

    for(i=0;i<2;i++)
    {
    ar=(value_t)%10;
    (value_t)=(value_t)/10;
    }
    LCD_write(0x30+ar[2]);
    LCD_write(0x30+ar[1]);
    LCD_write(‘.’);
    LCD_write(0x30+ar[0]);
    LCD_write(‘d’);
    LCD_write(‘C’);
     

    _delay_ms(100);

    the first digit is not getting printed…plz help…!!! 

    March 22, 2011 at 8:31 am #5785
    dagakshay
    Participant

    for(i=0;value_t<=10;i++)
    {
    ar=(value_t)%10;
    (value_t)=(value_t)/10;
    }
    LCD_write(value_t);
    for(int j=i; j>=0;j–)
    {
    LCD_write(ar[j]);
    }
    _delay_ms(100);

    try this out and let me know the result….

    March 22, 2011 at 11:43 am #5796
    hardeep
    Participant

    Nothng is getting printed buddy …!!!

    March 22, 2011 at 12:52 pm #5797
    dagakshay
    Participant

    sorry mistake in first line
    for(i=0;value_t>=10;i++)
    {
    ar=(value_t)%10;
    (value_t)=(value_t)/10;
    }
    LCD_write(value_t);
    for(int j=i; j>=0;j–)
    {
    LCD_write(ar[j]);
    }
    _delay_ms(100);

    NOW try this out and let me know….

    March 22, 2011 at 4:52 pm #5798
    hardeep
    Participant

    Still not working…

    March 23, 2011 at 5:05 am #5799
    dagakshay
    Participant

    sorry for misconceptions you just need to do +48 in the values here i am sending the complete i my self compiled and checked it….

    /*
    LCD data transfer through 8 bit mode

    jsut writing a single letter 137 on LCD

    LCD DATA port—-PORT A
    signal port


    PORT B
    rs


    PB0
    rw


    PB1
    en


    PB2

    usidng internal clock frequency 1MHz

    */
    #include
    #include

    #define LCD_DATA PORTA //LCD data port

    #define signal PORTB
    #define en PB2 //enable signal
    #define rw PB1 //read/write signal
    #define rs PB0 //resister select signal

    void LCD_cmd(unsigned char cmd);
    void init_LCD(void);
    void LCD_write(unsigned char data);
    void character();

    int main()
    {
    DDRA=0xff; //making LCD_DATA port as out put port
    DDRB=0x07; //making signal as out put
    init_LCD(); //initialization of LCD
    _delay_ms(50); // delay of 50 mili seconds
    LCD_cmd(0xC0); // —8 go to first line and –0 is for 0th position
    _delay_ms(1);
    unsigned char value_t=137,i,j;
    unsigned char ar[4];
    for(i=0;value_t>=10;i++)
    {
    ar=(value_t)%10;
    (value_t)=(value_t)/10;
    }
    LCD_write(value_t+48);
    for(j=2;j>0 ;j–)
    {
    LCD_write(ar[j-1]+48);
    }
    _delay_ms(100);
    }

    void init_LCD(void)
    {

    LCD_cmd(0x38); //initializtion of 16X2 LCD in 8bit mode
    _delay_ms(1);

    LCD_cmd(0x01); //clear LCD
    _delay_ms(1);

    LCD_cmd(0x0E); //cursor ON
    _delay_ms(1);

    LCD_cmd(0x80); // —8 go to first line and –0 is for 0th position
    _delay_ms(1);
    return;
    }

    void LCD_cmd(unsigned char cmd)
    {
    LCD_DATA=cmd;
    signal =(0< _delay_ms(1);
    signal =(0< _delay_ms(50);
    return;
    }

    void LCD_write(unsigned char data)
    {
    LCD_DATA= data;
    signal = (1< _delay_ms(1);
    signal = (1< _delay_ms(50); // give a 10 milli second delay to get thigs executed
    return ;
    }

    March 23, 2011 at 5:07 am #5800
    dagakshay
    Participant

    wysiwyg_imageupload:918:

    March 13, 2012 at 10:51 am #7294
    muhammad
    Participant

    Hello Hardeep.can you share the circuit schematic diagram..it might help me..TQ

     

    March 17, 2012 at 2:22 pm #7310
    Dhruwank Vankawala
    Participant

    Try this code for displaying temperature on LCD

     

    #include <avr/io.h>
    #include<util/delay.h>
    #include<math.h>
    #include<stdlib.h>
    #define LCD_PRT PORTC
    #define LCD_PIN PINC
    #define LCD_DDR DDRC
    #define LCD_RS 0
    #define LCD_RW 1
    #define LCD_EN 2

    void delay_us(int d)
    {
    _delay_us(d);
    }

    void delay_ms(int d)
    {
    _delay_ms(d);
    }

    void lcdcommand(unsigned char cmnd)
    {
    LCD_PRT = (LCD_PRT & 0x0F)| (cmnd & 0xF0);
    LCD_PRT &=~(1<<LCD_RS);
    LCD_PRT &=~(1<<LCD_RW);
    LCD_PRT |=(1<<LCD_EN);
    delay_us(1);
    LCD_PRT &=~(1<<LCD_EN);
    delay_us(20);
    LCD_PRT = (LCD_PRT & 0x0F) | (cmnd<<4);
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &=~ (1<<LCD_EN);
    }

    void lcddata(unsigned char data)
    {
    LCD_PRT = (LCD_PRT & 0x0F) | (data & 0xF0);
    LCD_PRT |= (1<<LCD_RS);
    LCD_PRT &=~ (1<<LCD_RW);
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &=~ (1<<LCD_EN);
    delay_us(20);
    LCD_PRT = (LCD_PRT & 0x0F) | (data << 4);
    LCD_PRT |= (1<<LCD_EN);
    delay_us(1);
    LCD_PRT &=~ (1<<LCD_EN);
    }

    void LCD_init()
    {
    LCD_DDR = 0xFF;
    LCD_PRT &=~(1<<LCD_EN);
    delay_us(2000);
    lcdcommand(0x33);
    delay_us(100);
    lcdcommand(0x32);
    delay_us(100);
    lcdcommand(0x28);
    delay_us(100);
    lcdcommand(0x0E);
    delay_us(100);
    lcdcommand(0x01);
    delay_us(2000);
    lcdcommand(0x06);
    delay_us(100);
    }

    unsigned int adc_conv(void)
    {
    DDRA=0;
    ADCSRA=0x87;
    ADMUX=0xE0;
    ADCSRA|=(1<<ADSC);
    while((ADCSRA&(1<<ADIF))==0);
    return ADCH;
    }

    void LCD_gotoxy(unsigned char x, unsigned char y)
    {
    unsigned char firstcharadr[]={0x80, 0x85};
    lcdcommand(firstcharadr[y-1] + x – 1);
    delay_us(100);
    }

    void LCD_print(char * str)
    {
    unsigned char i=0;
    while(str!=0)
    {
    lcddata(str
    );
    i++;
    }
    }

    int main(void)
    {
        unsigned int val;
        LCD_init();
        while(1)
        {
        LCD_gotoxy(1,1);
        LCD_print(“Temp “);
        LCD_gotoxy(1,2);
        val=adc_conv();
        char buffer[10];
        itoa(val,buffer,10);
        LCD_print(buffer);
        delay_ms(1000);
    }
    return 0;
    }

    February 23, 2013 at 9:27 pm #9170
    hazrat ali
    Participant

    dear sir! 

             i have problem to interface external ADC0804 to atmega16 for temperature sensor…plz help me out obout this problem….Also their is problem to show value of temperature on lcd….how its value can be converted to decimal values…..

     

     
    February 23, 2013 at 9:33 pm #9169
    hazrat ali
    Participant

    Dear sir!

    how ADC080 can be interface with atmega16…..???? i am not using inbuilt adc of atmaga16..

    February 24, 2013 at 3:29 pm #9173
    AJISH ALFRED
    Participant

    Hi Hazrat Ali,

    Connect 8 digital output to any of the port of atmega16. Make sure that you’ve made all the pins of the port as input. Now simply read the port as a whole and you will get the value.

    Regarding the decimal conversion, all you need is a function which can convert integer to string. C library already has such a function. Use printf with %d option.

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

RSS Recent Posts

  • reviving old swordfish program but? May 17, 2026
  • Assistance locating a 'trail' camera gadget, please ? May 16, 2026
  • Analog multiplexer has gone obselete May 16, 2026
  • Difference between TTL, RS232 and RS485 May 16, 2026
  • Smart Buoy project May 16, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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
  • Advertise