ATMega16 Microcontroller Digital LM35 LCD Thermometer
ATMega16 Microcontroller Digital LM35 LCD Thermometer
ATMega16 Microcontroller Digital LM35 LCD Thermometer
LCD Thermometer
The
/*
* Digital_Thermometer.c
*
* Author: AVR Tutorials
* Website: www.AVR-Tutorials.com
*
* Written in AVR Studio 5
* Compiler: AVR GNU C Compiler (GCC)
*/
#define LCD_RS_PIN 5
#define LCD_RW_PIN 6
#define LCD_ENABLE_PIN 7
#define SET_HOUR 3
#define SET_MINUTE 4
int main(void)
{
unsigned char i;
LCD_init();
LCD_goto(1,2);
LCD_print("Temperature is");
while(1);
}
LCD_CNTRL_PORT |= (1<<LCD_ENABLE_PIN);
_delay_us(2);
LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);
_delay_us(100);
}
LCD_CNTRL_PORT |= (1<<LCD_ENABLE_PIN);
_delay_us(2);
LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);
_delay_us(100);
}
void LCD_init()
{
LCD_CNTRL_DDR = 0xFF;
LCD_CNTRL_PORT = 0x00;
LCD_DATA_DDR = 0xFF;
LCD_DATA_PORT = 0x00;
_delay_ms(10);
LCD_send_command(0x38);
LCD_send_command(0x0C);
LCD_send_command(0x01);
_delay_ms(10);
LCD_send_command(0x06);
}
/* This function moves the cursor the line y column x on the LCD
module*/
void LCD_goto(unsigned char y, unsigned char x)
{
unsigned char firstAddress[] = {0x80,0xC0,0x94,0xD4};
LCD_send_command(firstAddress[y-1] + x-1);
_delay_ms(10);
}
while(string[i]!=0)
{
LCD_send_data(string[i]);
i++;
}
}
LCD_goto(2,4);
itoa(tempC/10,display,10);
LCD_print(display);
itoa(tempC%10,display,10);
LCD_print(display);
LCD_send_data(0xDF);
LCD_print("C ");
itoa(tempF/10,display,10);
LCD_print(display);
itoa(tempF%10,display,10);
LCD_print(display);
LCD_send_data(0xDF);
LCD_print("F");
_delay_ms(500);
ADCSRA |= 1<<ADSC; // Start Conversion
}
Note: Although this AVR project was designed around the ATMega16 the project could
have utilized another microcontroller such as an ATMega32, etc. The microcontroller
must contain an Analog-to-Digital Converter (ADC) though.
The figure below gives the circuit diagram for the ATmega16 LCD Digital Thermometer