I was recently asked for a college project with a temperature sensor. It was easy for simulating it on proteus and everything was alright. Then I tried to make it hardware but nothing is happening. The lcd works but no data actually appears on my lcd although the lcd is working fine with my arduino.
I'm using a 4 MHz Crystal oscillator with 2 X 22pf capcitors connected with 12 and 13 pins of atmega16.
Here's my code:
sbit LCD_RS at PORTC2_bit;
sbit LCD_EN at PORTD6_bit;
sbit LCD_D4 at PORTC4_bit;
sbit LCD_D5 at PORTC5_bit;
sbit LCD_D6 at PORTC6_bit;
sbit LCD_D7 at PORTC7_bit;
sbit LCD_RS_Direction at DDC2_bit;
sbit LCD_EN_Direction at DDD6_bit;
sbit LCD_D4_Direction at DDC4_bit;
sbit LCD_D5_Direction at DDC5_bit;
sbit LCD_D6_Direction at DDC6_bit;
sbit LCD_D7_Direction at DDC7_bit;
const unsigned short VREF = 5.00;
unsigned int temp_res = 0;
float temp;
char txt[15];
void main() {
DDA7_bit = 0; // Configure PA7 pin as input
ADC_Init(); // Initialize ADC
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "Temperature :");
Lcd_Chr(2,8,223); // Different LCD displays have different
// char code for degree
Lcd_Chr(2,9,'C'); // Display "C" for Celsius
temp_res = 0;
do {
temp_res = ADC_Get_Sample(7); // Get 10-bit results of AD conversion
temp = (temp_res * VREF)/10.240; // Calculate temperature in Celsius
// change Vref constant according
// to the power supply voltage
FloatToStr(temp, txt); // Convert temperature to string
txt[4] = 0;
Lcd_Out(2,3,txt); // Write string in second row
Delay_ms(1000);
} while(1);
}