English
Language : 

PIC32MX440F256H-80I Datasheet, PDF (517/646 Pages) Microchip Technology – 64/100-Pin General Purpose and USB 32-Bit Flash Microcontrollers
PIC32MX3XX/4XX
EXAMPLE 22-5: ADC INITIALIZATION CODE EXAMPLE
void __ISR(_ADC_VECTOR, ipl7) ADC_HANDLER(void)
{
// interrupt handler
unsigned long int result;
result = ADC1BUF0;
IFS1CLR = 2;
}
// read the result
// Clear ADC conversion interrupt flag
int main(void)
{
AD1PCFG = ~(1 << 5);
// Configure RB5 as an analog input
AD1CON1 = (7 << 5) | 4;
//Configure sample clock source and Trigger mode
// integer format, automatic conversion trigger,
// automatic start of sampling, No operation in IDLE mode.
AD1CON2 = 0x0000;
// Configure ADC voltage reference
// and buffer fill modes.
// VREF from AVDD and AVSS,Inputs are not scanned,
// Interrupt every sample
AD1CON3 = (31 << 8) | 0xFF;
// Configure ADC conversion clock
// sample for 31 TAD, TAD = Tpb / 512
AD1CHS = 5 << 16;
// Configure input channels,
// CH0+ input is AN0. CHO- input is VREFL (AVss)
AD1CSSL = 0x0000;
// No inputs are scanned.
// Note: Contents of AD1CSSL are ignored when CSCNA = 0
IPC6CLR = 0x1F << 24;
// clear the ADC interrupt priority bits
IPC6SET = (0x07 << 26) | (1 << 24);
// Configure ADC interrupt priority bits
// priority = 3, sub-priority = 1
INTEnableSystemMultiVectoredInt(); // enable system interrupts
IFS1CLR = 2;
// Clear ADC conversion interrupt
IEC1SET = 2;
// Enable ADC conversion interrupt
AD1CON1SET = 0x8000;
// Turn on the ADC module
while(1) {}
}
// main
© 2008 Microchip Technology Inc.
Preliminary
DS61143E-page 515