Try this,
Code:
int ADC_Val;
unsigned int getADCvalue(unsigned char channel){
if(channel>7)
return 0;
ADCON0=channel<<2|1; //select channel and ADC on
ADCON1=0b11110000; //right justify, RC osc
ANSELA=0b0001000; //RA4=analogue
ANSELC=0b0000100; //RC3=analogue
__delay_ms(1); //Time for Acqusition capacitor to charge up and show correct value
GO_nDONE = 1; //Enable Go/Done
while(GO_nDONE); //wait for conversion completion
return ((ADRESH<<8)+ADRESL); //Return 10 bit ADC value
}
void main(){
OPTION_REGbits.nWPUEN = 1;
TRISCbits.TRISC3 = 1;
TRISAbits.TRISA0 = 0;
RA0=0;
while(1){
ADC_Val = getADCvalue(7); //read channel 7 = RC3
ADC_Val = getADCvalue(3); //read channel 3 = RA4
if(ADC_Val<500){
RA0=0;
}else{
RA0=1;
}
}
}
Note, I pass the channel number to getADCvalue - AN7 is not 7.
Obviously, keep your config etc.
Set breakpoints to see what is in ADC_Val.
Mike.