Try wiring a potentiometer and Voltmeter to the ADC input to verify that your code is working correctly.
void read_senzor(){
delay_ms(20);
ADCON0= 00011001
ADCON0 = 00011101;
while(ADCON0.GO==1);
temp_res = ADC_Read(3); // Get 10-bit results of AD conversion
}
Why are you writing to ADCON0 with two different values?
Also, after changing which ADC pin is being read you need the delay to allow the ADC sampling cap to charge.
What does the function ADC_Read() do? Is it working correctly?
Here is the C code I use. It doesn't use any compiler's built-in functions.
ADC_init() set up the ADC with the defines
GetADC(channel) selects the ADC channel and returns the result
#define adcon0_mask 0x81 // Fosc/32, ch0, ADON
#define adcon1_init_lr 0x84 // RA0,1,3 = AD input, RA2,5, RE0,1,2 = Digital input
// right justify AD result
//---------------------------------------------------------------
void ADselect( unsigned char a) {
const char SelectAD[5] = {
0x81,
0x89,
0x91,
0x99,
0xa1
};
ADCON0 = SelectAD[a];
return;
}
//---------------------------------------------------------------
// Get data from AD
// Fosc/32 = 1.536 MHz, Tad = 6.5104 usec
// conversion = 12 Tad = 78.125 usec
// 2Tad = 13.02 usec
unsigned int GetADC( unsigned char c) {
ADselect( c);
DelayUs ( 10);
GODONE = 1;
AD_wait:
if ( GODONE == 1)
goto AD_wait;
return (ADRESH<<8 & ADRESL);
}
//---------------------------------------------------------------
// 8 bits in ADRESH
void ADC_init(void) {
ADCON0 = adcon0_mask;
ADCON1 = adcon1_init_lr;
}