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 / Atmega32

Atmega32

|

Microcontroller › AVR › Atmega32

  • This topic has 2 replies, 3 voices, and was last updated 6 years, 4 months ago by Saatwik.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • July 5, 2017 at 7:04 am #4673
    s.manisrinivas
    Participant

    i am using lm75 b temperature sensor interface to atmega32 controller .my problem is i sending the address to read i.e. 10010001 (0x91) but the value is displaying in lcd display .

    iam using pull up resistors – 10k 

    cpu freq -16mhz

    code is below

     

    this is main file
     
     
    #define F_CPU 16000000UL    //this must be first line 
     
    #include <avr/io.h>
    #include "i2c.h"
    #include "LCDa.h"
    #include <util/delay.h>
    #include <stdlib.h>
     
     
     
    unsigned int read_temperature(unsigned char LM75_addr);
     
    unsigned int temperature;
     char buffer[14];
     
    unsigned int read_temperature(unsigned char LM75_addr) //function for reading temperature
    {
     
    unsigned int temp;
     
    I2C_Start(); // start i2c
     
    I2C_Write(0x90);// write address
    I2C_Start();
    // I2C_Write(0x01);
    _delay_ms(1);
    I2C_Write(0x00);
    //I2C_Stop();
    _delay_ms(1);
     
    I2C_Write(LM75_addr);
     
     
    temp=I2C_Read_ACK(); //get high byte
    temp<<=8;
    temp|=I2C_Read_NACK(); // get low byte
    temp>>=5;
    I2C_Stop();
     
    return temp; //return temperature coded in second complement
    }
     
     
     
     
     
    int main()
    {
         
     
     _delay_ms(100);
     
        lcd_init();
    Init_I2C();
    lcd_display_on_off(1,1,1);
     
     
    while(1)
    {
    lcd_clear_display();
        temperature = read_temperature(0x91);//0x90+1
        itoa(temperature,buffer,10); 
    lcd_gotoxy(0,0);
    lcd_puts("temp is:");
        lcd_gotoxy(0,1);
    lcd_puts(buffer);
    _delay_ms(200);
    }
       
       
    }
     
    this is i2c routines
     
     
     
    #include <avr/io.h>
    #include "i2c.h"
     
     
    unsigned char I2C_Read_NACK(void)
    {
    TWCR = (1<<TWINT)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
    return TWDR;
    }
    void Init_I2C()
    {
    #define SCL_presceler 1
    TWSR=0;  //no presceler
    TWBR=0x20; //  ((F_CPU/F_SCL)-16)/2 -> F_SCL=cca 10000Hz
    TWCR = (1<<TWEN);
    }
    unsigned char I2C_get_status(void)
    {
    unsigned char  status;
    status = TWSR & 0xF8;
    return status;
    }
    void I2C_Start()
    {
    TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0 );
     
    }
    void I2C_Stop()
    {
    TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);
    }
    void I2C_Write(unsigned char data)
    {
    TWDR = data;
    TWCR = (1<<TWINT)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
    }
     
    unsigned char I2C_Read_ACK(void)
    {
    TWCR = (1<<TWINT)|(1<<TWEA)|(1<<TWEN);
    while ((TWCR & (1<<TWINT)) == 0);
    return TWDR;
    }
     
     
    July 28, 2017 at 6:00 pm #14639
    Faroogh
    Participant

    Lm35 is not 12c device use ADC to read the signal and apply formulas to the adc read value then print it to Lcd

    February 16, 2019 at 6:51 am #15020
    Saatwik
    Participant

    you can get idea from this to get input from sensor just connect the sensor at place of potentiometer. https://www.engineersgarage.com/embedded/avr-microcontroller-projects/adc-circuit

  • 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

  • Raise your hand if your car had one of these: July 8, 2025
  • Tektronix 2235 channel 1 trace unstable July 8, 2025
  • How to make string LEDs? July 8, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz July 8, 2025
  • The Analog Gods Hate Me July 8, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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