
Code:
unsigned int read_adc(unsigned char adc_input){
ADMUX=adc_inputADC_VREF_TYPE; //Set channel for input
ADCSRA=( (1<<ADEN)  (1<<ADSC)  (1<<ADIE)  (1<<ADPS1)  (1<<ADPS2)
);//start conversion
while(!(ADCSRA & 0x10)); //Wait for conversion to complete
ADCSRA=0x10;
return ADCW;
}
Salem this is something i found at the website you gave me. This is the conversion part right?


Salem > so sorry to bother you always, but I've been hearing alot of the Vref thingy. But i don't really understand what is it about.
They gave me an example.
Supposing, at a temperature of 30 deg C, it gives an output of 3V (this is just an example, check the datasheet of LM35 for exact figures). You have set a Vref+ at 5V and Vref at 0V. Then if you do the AD conversion correctly, your ADC will read:
3 volt
 x 0x3FF ~= 0x265
5 volt
I'm somewhere there, but not fully.
Thanks in advance, greatly appreiciated.

It's just simple linear interpolation
0V is read by the ADC as 0x000
5V is read by the ADC as 0x3FF
You then need another set of interpolation limits (assuming the relationship is linear), which turns say 3V into 30°C

woah, hmm it's getting weird.
What i heard from my friend is Vref is generated using a potentiometer. Using that you can "substitude" it for the sensor.
How do you determine that 3V is 30 celsius?. Or do i assume a imaginary figure and work from there on?.

> How do you determine that 3V is 30 celsius?.
I thought you knew that already, with "check the datasheet of LM35 for exact figures".
We really need a circuit diagram of some sort to visualise how all these Vref's relate to one another.
A potentiometer is good, since you can just turn it to generate varying input at the ADC, and from that generate a changing display.
For the moment, just try displaying the hex value of the ADC result on your LCD, then worry about all the conversions later.

i think i got alot of reading to do.
thanks Salem, i'll do whatever i can before i comeback here agaiin.
the code i pasted youi before, some other forummers said it was for another PIC18 controller.
thanks

I've been reading alot this few days, but suddenly something struck me.
>For the moment, just try displaying the hex value of the ADC result on your LCD, then worry about all the conversions later.
If I plugged the sensor into the ADC port, it will display the hex values on the LCD? I mean after programming.
I don't know whether the sensor is working or not lol. Cause it's like no where to show even hex values.