sarah.sanchez
Junior Member level 2

hi,
i am currently working on a project using PIC18F4520 in MikroC. it has to read the LM35s connected to each of the 6 ADC channels (AN0-AN5). also, we wanted to display those values in the LCD. please see code below. but the output in the LCD shows the same value for all of the ADC channels even if the LM35 is exposed to different temperatures.
unsigned short temp_h1, temp_h2, temp_h3, temp_c1, temp_c2, temp_c3;
char hot1[5], hot2[5], hot3[4], cold1[4], cold2[4], cold3[4];
void main() {
ADCON1 = 0x00;
ADCON2 = 0xAA;
TRISA = 0xFF;
TRISE = 0x01;
TRISD = 0x00;
Lcd_Init(&PORTD);
Delay_ms(200);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
while(1) {
temp_h1 = ADC_Read(0);
temp_h2 = ADC_Read(1);
temp_h3 = ADC_Read(2);
temp_c1 = ADC_Read(3);
temp_c2 = ADC_Read(4);
temp_c3 = ADC_Read(5); //RE0
tempdiff1 = temp_h1 - temp_c1;
tempdiff2 = temp_h2 - temp_c2;
tempdiff3 = temp_h3 - temp_c3;
EEPROM_Write(0x00, temp_h1);
EEPROM_Write(0x02, temp_h2);
EEPROM_Write(0x04, temp_h3);
EEPROM_Write(0x06, temp_c1);
EEPROM_Write(0x08, temp_c2);
EEPROM_Write(0x0A, temp_c3);
ShortToStr(EEPROM_Read(0x00), hot1);
ShortToStr(EEPROM_Read(0x02), hot2);
ShortToStr(EEPROM_Read(0x04), hot3);
ShortToStr(EEPROM_Read(0x06), cold1);
ShortToStr(EEPROM_Read(0x08), cold2);
ShortToStr(EEPROM_Read(0x0A), cold3);
Lcd_Out(1,1,"h1=");
Lcd_Out(1,5,hot1);
Lcd_Out(2,1,"h2=");
Lcd_Out(2,5,hot2);
Lcd_Out(2,1,"h3=");
Lcd_Out(2,4,hot3);
Delay_ms(3000);
Lcd_Out(1,1,"c1=");
Lcd_Out(1,4,cold1);
Lcd_Out(1,9,"c2=");
Lcd_Out(1,12,cold2);
Lcd_Out(2,1,"c3=");
Lcd_Out(2,4,cold3);
}
}
i am currently working on a project using PIC18F4520 in MikroC. it has to read the LM35s connected to each of the 6 ADC channels (AN0-AN5). also, we wanted to display those values in the LCD. please see code below. but the output in the LCD shows the same value for all of the ADC channels even if the LM35 is exposed to different temperatures.
unsigned short temp_h1, temp_h2, temp_h3, temp_c1, temp_c2, temp_c3;
char hot1[5], hot2[5], hot3[4], cold1[4], cold2[4], cold3[4];
void main() {
ADCON1 = 0x00;
ADCON2 = 0xAA;
TRISA = 0xFF;
TRISE = 0x01;
TRISD = 0x00;
Lcd_Init(&PORTD);
Delay_ms(200);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
while(1) {
temp_h1 = ADC_Read(0);
temp_h2 = ADC_Read(1);
temp_h3 = ADC_Read(2);
temp_c1 = ADC_Read(3);
temp_c2 = ADC_Read(4);
temp_c3 = ADC_Read(5); //RE0
tempdiff1 = temp_h1 - temp_c1;
tempdiff2 = temp_h2 - temp_c2;
tempdiff3 = temp_h3 - temp_c3;
EEPROM_Write(0x00, temp_h1);
EEPROM_Write(0x02, temp_h2);
EEPROM_Write(0x04, temp_h3);
EEPROM_Write(0x06, temp_c1);
EEPROM_Write(0x08, temp_c2);
EEPROM_Write(0x0A, temp_c3);
ShortToStr(EEPROM_Read(0x00), hot1);
ShortToStr(EEPROM_Read(0x02), hot2);
ShortToStr(EEPROM_Read(0x04), hot3);
ShortToStr(EEPROM_Read(0x06), cold1);
ShortToStr(EEPROM_Read(0x08), cold2);
ShortToStr(EEPROM_Read(0x0A), cold3);
Lcd_Out(1,1,"h1=");
Lcd_Out(1,5,hot1);
Lcd_Out(2,1,"h2=");
Lcd_Out(2,5,hot2);
Lcd_Out(2,1,"h3=");
Lcd_Out(2,4,hot3);
Delay_ms(3000);
Lcd_Out(1,1,"c1=");
Lcd_Out(1,4,cold1);
Lcd_Out(1,9,"c2=");
Lcd_Out(1,12,cold2);
Lcd_Out(2,1,"c3=");
Lcd_Out(2,4,cold3);
}
}