Bluestar88
Member level 3
- Joined
- Oct 17, 2014
- Messages
- 59
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- Activity points
- 447
I wanna measure the temperature of room. For this order I used a LM35 and Atmega32. But my circuit doesn't work correctly.It displays 499.5 C on it's LCD...Please help me...My code is here...
and my hardware is simple. I connected pin 10, 30 to VCC and 11, 31 to GND. Pin 40 to sensor. and PORT D to LCD....Please help me..I really confused...
- - - Updated - - -
It is such as a case that ADC doesnot work.....Please help me...
- - - Updated - - -
It is such as a case that ADC doesnot work.....Please help me...
Code:
/****************************************************************
Title : Thermometer with LM35
Micro Contoroler : ATMega32
Clock frequency : 1.000000 MHz
Compiler : Code Vision AVR
****************************************************************/
#include <mega32.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h>
typedef unsigned char byte;
flash byte char0[8]={
0b10000111,
0b10000101,
0b10000111,
0b10000000,
0b10000000,
0b10000000,
0b10000000,
0b10000000
};
void Configuration_LCD(void);
void define_char(byte flash *pc,byte);
void Configuration_ADC(void);
void Display_LCD_Start(void);
float Read_adc(unsigned char);
float Convert(float);
void Display_LCD_1(float);
void Display_LCD_2(unsigned int);
float Input_mV=0;
float Temp=0;
void main(void){
Configuration_ADC();
Configuration_LCD();
define_char(char0,0);
Display_LCD_Start();
while (1){
Input_mV=Read_adc(0);
Temp=Convert(Input_mV);
Display_LCD_1(Temp);
Display_LCD_2(Input_mV);
delay_ms(300);
};
}
//********************************************************
void Configuration_LCD(void){
lcd_init(16); lcd_clear();
}
//********************************************************
void define_char(byte flash *pc,byte char_code){
byte i,a;
a=(char_code<<3) | 0x40;
for (i=0; i<8; i++) lcd_write_byte(a++,*pc++);
}
//********************************************************
void Configuration_ADC(void){
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=0x40 & 0xff;
ADCSRA=0x83;
}
//********************************************************
void Display_LCD_Start(void){
lcd_clear();
lcd_gotoxy(0,0); lcd_putsf("LM35");
lcd_gotoxy(0,1); lcd_putsf("Test");
delay_ms(2000); lcd_clear(); delay_ms(200);
}
//********************************************************
float Read_adc(unsigned char adc_input){
float x=0;
ADMUX=adc_input | (0x40 & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
x=ADCW; x= x*4.8828125;
return x;
}
//********************************************************
float Convert(float x){
x=x/10;
return x;
}
//********************************************************
void Display_LCD_1(float x){
char buffer[16];
lcd_gotoxy(0,0);
lcd_putsf("Temp: ");
ftoa(x,1,buffer); lcd_puts(buffer);
lcd_putsf(" ");
lcd_putchar(0);
lcd_putsf("C");
}
//********************************************************
void Display_LCD_2(unsigned int x){
char buffer[16];
lcd_gotoxy(0,1);
lcd_putsf("Input: ");
ftoa(x,1,buffer); lcd_puts(buffer);
lcd_putsf(" mV");
}
and my hardware is simple. I connected pin 10, 30 to VCC and 11, 31 to GND. Pin 40 to sensor. and PORT D to LCD....Please help me..I really confused...
- - - Updated - - -
It is such as a case that ADC doesnot work.....Please help me...
- - - Updated - - -
It is such as a case that ADC doesnot work.....Please help me...