Hi guys.
Wanted to program a simple ADC, and I remember using the code before, but now it doesn't seem to work.
I have hooked up a pot to RA4, and wanted it to just pull RA2 high or low, depending on the threshold.
The ADC doesn't seem to be running, so I'm a little confused as to what part of the code that's not working. Everything else on the PIC is working like it should.
unsigned int ADC;
void main(void) {
TRISA = 0b00010000; //RA4 input
ANSELA = 0b00010000; //RA4 analog
ODCONA = 0b00000000; //No open-drain
OSCCON = 0b11110000; //32MHz internal
ADCON0 = 0b00001101; //Set pin R4 AN3, Enable ADC
ADCON1 = 0b10000000; //Right justified, Fosc/2, VDD as ref+
while(1)
{
GO_nDONE = 1; //Initiate ADC
while(GO_nDONE); //Wait for ADC
ADC = (ADRESH << 8 | ADRESL); //Gather result in 1 integer
if (ADC >= 100) { //If voltage is high, set RA2 high
RA2 = 1;
}
if (ADC <= 100) { //If voltage is low, set RA2 low
RA2 = 0;
}
}
return;
}
Hope you can help.