*DO NOT START ANOTHER THREAD ON THE SAME TOPIC. MODERATOR*
I want to make a quad thermometer. It will have four LM35 sensors mounted in four different places of a refrigeration system (Compressor, Condenser, Evaporator and Room Temperature.) Each sensor would have ~1 metre of shielded wire. Sensors will feed the individual inputs to different pins of Port A of an ATMega16 and display all the results on a single 20x4 LCD screen.
I'm trying to multiplex two LM35 sensors at first and test the code. If it's successful I'll go from there.
I know the code I've written is wrong in many ways, but am I going the right way? Please guide me. Also, my knowledge of C is too rusty.
Compiling this code gives me the following errors:
1. 'tempD' undeclared (first use in this function)
2. expected declaration specifiers or '...' before '*' token
#include <avr/io.h> // special function registers #include <stdio.h> // sprintf() #define F_CPU 16000000 // 16 MHz clock set #include <util/delay.h> // _delay_xx() #include "lcd.h" // Fleury LCD library int main(void) { char display[80], degree = 0xDF; // special character for degree symbol int tempC, tempD ADCSRA = (1<<ADEN)|(7 << ADPS0); // Enable, div128, ADC clock at 125 KHz ADMUX = (3 << REFS0)|(1<<ADLAR)|(0<<MUX0); // VREF=2.56V, 8-bit, channel #0 is on PA0 pin lcd_init(LCD_DISP_ON); lcd_puts("Compressor"); // only print this once while (1) { ADCSRA |= (1<<ADSC); // Start Conversion while (ADCSRA & (1<<ADSC)); // wait for completion tempC = ADCH; // 10mV per C. full-scale is 2.56V i.e. 256C sprintf(display, "%3d%cC", tempC, degree); lcd_gotoxy(2, 1); // 2nd column, 1st line lcd_puts(display); // string is all printed in one go _delay_ms(500); ADCSRA|=(1<<ADIF); // Clearing ADC. return(ADC); } void Wait() { uint8_t i; for(i=0;i<100;i++) _delay_loop_2(0); } ADCSRA = (1<<ADEN)|(7 << ADPS0); // Enable, div128, ADC clock at 125 KHz ADMUX = (3 << REFS0)|(1<<ADLAR)|(1<<MUX0); // VREF=2.56V, 8-bit, channel #1 is on PA1 pin lcd_puts("Condenser"); while (1) { ADCSRA |= (1<<ADSC); // Start Conversion while (ADCSRA & (1<<ADSC)); // wait for completion tempD = ADCH; // 10mV per C. full-scale is 2.56V i.e. 256C sprintf(display, "%3d%cC", tempD, degree); lcd_gotoxy(2, 2); // 2nd column, 2nd line lcd_puts(display); // string is all printed in one go _delay_ms(500); ADCSRA|=(1<<ADIF); // Clearing ADC. return(ADC); } { uint8_t i; for(i=0;i<100;i++) _delay_loop_2(0); } }