int SUHU;
char temp[8];
float suhu_celcius;
#include <mega16.h>
#include <stdlib.h>
#include <lcd.h>
#include <delay.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input | (ADC_VREF_TYPE & 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;
return ADCW;
}
void main(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: 750.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;
// LCD module initialization
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(“ElectrO-cOntrOl”);
lcd_gotoxy(0,1);
lcd_putsf(“SENSOR SUHU LM35”);
delay_ms(1000);
while (1)
{
lcd_clear( );
SUHU = read_adc(0);
suhu_celcius = (float)SUHU*500/1023;//rumus untuk mengubah kedalam derajat celcius
lcd_gotoxy(0,0);
lcd_putsf(“ElectrO-cOntrOl”);
ftoa(suhu_celcius,1,temp);//mengubah tipe data float ke tipe data array yg akan ditampilkan di LCD
lcd_gotoxy(0,1);
lcd_puts(temp);
lcd_gotoxy(5,1);
lcd_putchar(0xdf);//menampilkan karakter derajat
lcd_putsf(“C”);
delay_ms(500);
};
}
File program CodeVision AVR dan simulasi proteus suhu LM35
Semoga bermanfaat…
Sumber: https://elektro-kontrol.blogspot.co.id/2011/06/aplikasi-pembacaan-suhu-lm35-dengan_27.html