Usually its easier to use a wrapper function to read the adc....
I use this
Then you can pass the channel you want to read and then get the correct reading in return..
Setup the ADC like this
Then just put this in your main
I use this
C:
int ReadADC(unsigned char ch)
{
int ret = 0;
ADCON0 = 0b10000001 + (ch<<3); // set channel to read
delayMs(5);
GODONE = 1; // start conversion
while(GODONE); // wait for conversion
ret = (ADRESH & 0x3) << 8; // get
ret += ADRESL; // result
return ret;
}
Then you can pass the channel you want to read and then get the correct reading in return..
Setup the ADC like this
C:
void InitADC()
{ // Set ADCON0 & 1
ADCON0 = 0b10000001; // FOSC/4
ADCON1 = 0b10000101; // Right justified
}
C:
int number;
InitADC();
while(1)
{
number = ReadADC(0);