This is an example procedure for using the ADC to perform an Analog-to-Digital Conversion:
0
, software must wait the required
acquisition time(2).0
), the device will wake from Sleep, but will not enter an
Interrupt Service Routine. /*This code block configures the ADC
for polling, VDD and VSS references,
ADCRC oscillator.
Conversion start & polling for completion
are included.
*/
void main()
{
initializeSystem(); //System Initialize
//Setup ADC
ADCON0bits.FM = 1; //Right justify
ADCON0bits.CS = 1; //ADCRC Clock
ADPCH = 0x00; //RA0 is positive input
TRISAbits.TRISA0 = 1; //Set RA0 to input
ANSELAbits.ANSELA0 = 1; //Set RA0 to analog
ADACQ = 32; //Set acquitisition time
ADCON0bits.ON = 1; //Turn ADC On
while (1)
{
ADCON0bits.GO = 1; //Start conversion
while (ADCON0bits.GO); //Wait for conversion done
resultHigh = ADRESH; //Read result
resultLow = ADRESL; //Read result
}
}