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 Atmega 16A with LM35 and LCD

Interfacing Atmega 16A with LM35 and LCD

|

Microcontroller › AVR › Interfacing Atmega 16A with LM35 and LCD

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 5 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • March 14, 2015 at 10:06 am #3552
    Rajib Saha
    Participant

    hi frnds i am trying to interface Atmega16A with LM35 and LCD that is i am trying to see the temperature on Lcd..but some how my code is not working on hardware….pls help

    my codes…

    header for lcd

     

     

    #ifndef LCD_H_
    #define LCD_H_
     
     
    #define rs PA7
    #define rw PA6
    #define en PA4
     
    #define F_CPU 16000000UL
    #include<avr/io.h>
    #include<util/delay.h>
    #include<inttypes.h>
     
    void lcd_init();
    void dis_cmd(char);
    void dis_data(char);
    void lcdcmd(char);
    void lcddata(char);
    void clrscr();
    void gotoxy(char,char);
    void LCD_write_string(const char *);
     
    void LCD_write_string(const char *str) //store address value of the string in pointer *str
    {
    int i=0;
    while(str!='') // loop will go on till the NULL character in the string
    {
    dis_data(str); // sending data on LCD byte by byte
    i++;
    }
    return;
    }
     
     
     
     
     
     
    void lcd_init() // function for initialize
    {
    DDRA=0xFF;
    dis_cmd(0x02); // to initialize LCD in 4-bit mode.
    dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
    dis_cmd(0x0C);
    dis_cmd(0x06);
     
    dis_cmd(0x80); // 8– 1st line 0- 0TH position
    }
     
    void dis_cmd(char cmd_value)
    {
    char cmd_value1;
     
    cmd_value1 = ((cmd_value>>4) & 0x0F); //shift 4-bit and mask
    lcdcmd(cmd_value1); // send to LCD
     
    cmd_value1 = cmd_value & 0x0F; //mask lower nibble because PA4-PA7 pins are used.
    lcdcmd(cmd_value1); // send to LCD
    }
     
     
    void dis_data(char data_value)
    {
    char data_value1;
     
    data_value1=((data_value>>4)&0x0F);
     
    lcddata(data_value1);
     
    data_value1=data_value&0x0F;
    lcddata(data_value1);
    }
     
    void lcdcmd(char cmdout)
    {
    PORTA=cmdout;
    PORTA&=~(1<<rs);
    PORTA&=~(1<<rw);
    PORTA|=(1<<en);
    _delay_ms(1);
    PORTA&=~(1<<en);
    }
     
    void lcddata(char dataout)
    {
    PORTA=dataout;
    PORTA|=(1<<rs);
    PORTA&=~(1<<rw);
    PORTA|=(1<<en);
    _delay_ms(1);
    PORTA&=~(1<<en);
    }
    void clrscr()
    {
    _delay_ms(100);
    dis_cmd(0x01);
    _delay_ms(10);
    }
    void gotoxy(char a,char b)
    {
     
    if(a==0)  a=0b10000000;
    else if(a==1) a=0b11000000;
     
    dis_cmd(a|b); 
    }
    #endif
     
                                                                       The Main program
     
     
    /*
     * temperature.c
     *
     * Created: 10-03-2015 23:07:08
     *  Author: rajib saha
     */ 
     
    #define F_CPU 16000000UL
    #include <avr/io.h>
    #include <util/delay.h>
    #include <stdlib.h>
    #include "lcd.h"
    void ADC_init(void);
    unsigned int ADC_read(unsigned char);
    int main(void)
    {
    //void adc_conv();
    DDRA=0x00;
    //DDRD=0x03;
    //ADC_init(); // Initialization of ADC
    // ch=0;
    while(1)
    {
      
       unsigned int value;
    float farhen,celsius;
    char buffer[10];
       value=ADC_read(0);
    //PORTA=value;
            farhen = (value*9.0/5.0+32.0);
    celsius = (value*0.49);
    lcd_init();
    LCD_write_string("Temperature is");
    gotoxy(2,1);
    itoa(farhen,buffer,10);
    LCD_write_string(buffer);
    LCD_write_string("C");
    itoa(celsius,buffer,10);
    gotoxy(2,4);
    LCD_write_string(buffer);
    LCD_write_string("F");
    _delay_ms(500);
    }
     //return(0);
    }
    void ADC_init(void) // Initialization of ADC
    {
    ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF
    ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);// Enable ADC and set Prescaler division factor as 128
     
    }
     
    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);
    }
     
     
     
    March 14, 2015 at 8:07 pm #12691
    Ashutosh Bhatt
    Participant

    where is ur itoa function?

    i dont see any function that converts HEX value available from ADC into decimal and then into ASCII

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

RSS Recent Posts

  • Circuit Problem August 14, 2022
  • Beam Break Sensor August 14, 2022
  • Drill speed controller fault August 14, 2022
  • uc3843 Buck-boost August 14, 2022
  • Right channel distortion on vintage fisher rs-2010 August 13, 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