I have tried using the following code to turn on an led if a pot is below halfway and off if above it but it is not working. I'm still trying to figure out how the adresh and adresl works. I thought I could just use a decimal value of < 511 of 1023 but that didn't allow it. Can anyone help?
Code:
void main() {
TRISC = 0;
ANSELbits.ANS2 = 1;
CMCON0bits.CM = 0;
ADCON1bits.ADCS = 0b001;
ADCON0bits.ADFM = 1;
ADCON0bits.VCFG = 0;
ADCON0bits.CHS = 0b010;
ADCON0bits.ADON = 1;
for(;;)
{
__delay_us(10);
ADCON0bits.GO = 1;
while(ADCON0bits.nDONE)
;
if (ADRESL > 0b00011111)
PORTCbits.RC2 = 1;
if (ADRESL < 0b00011111)
PORTCbits.RC2 = 0;
}
}