Microcontroller › AVR › Atmega32
- This topic has 2 replies, 3 voices, and was last updated 3 years, 11 months ago by
Saatwik.
Viewing 3 posts - 1 through 3 (of 3 total)
-
AuthorPosts
-
July 5, 2017 at 7:04 am #4673
s.manisrinivas
Participanti 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 i2cI2C_Write(0x90);// write addressI2C_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 bytetemp<<=8;temp|=I2C_Read_NACK(); // get low bytetemp>>=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+1itoa(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 1TWSR=0; //no prescelerTWBR=0x20; // ((F_CPU/F_SCL)-16)/2 -> F_SCL=cca 10000HzTWCR = (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 #14639Faroogh
ParticipantLm35 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 #15020Saatwik
Participantyou 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
-
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.