Техническая Спецификация для Microchip Technology DM183037

Скачать
Страница из 696
PIC18F97J94 FAMILY
DS30575A-page 476
 2012 Microchip Technology Inc.
EXAMPLE 22-3:
A/D INITIALIZATION CODE EXAMPLE
ADCON1H = 0x22;         // Configure sample clock source
ADCON1L = 0x00;         // and conversion trigger mode.
                        // Unsigned Fraction format (FORM<1:0>=10),
                        // Manual conversion trigger (SSRC<3:0>=0000),
                        // Manual start of sampling (ASAM=0),
                        // No operation in Idle mode (ADSIDL=1),
                        // S/H in Sample (SAMP = 1)
ADCON2H = 0;            // Configure A/D voltage reference
ADCON2L = 0;            // and buffer fill modes.
                        // Vr+ and Vr- from AVdd and AVss(PVCFG<1:0>=00, NVCFG=0),
                        // Inputs are not scanned,
                        // Interrupt after every sample
ADCON3H = 0;            // Configure sample time = 1Tad,
ADCON3L = 0;            // A/D conversion clock as Tcy
ADCHS0H = 0;            // Configure input channels,
ADCHS0L = 0;            // S/H+ input is AN0,
                        // S/H- input is Vr- (AVss). 
ADCSS0L = 0;            // No inputs are scanned. 
ADCSS0H = 0;            // No inputs are scanned. 
PIR1bits.ADIF = 0;      // Clear A/D conversion interrupt.
// Configure A/D interrupt priority bits (ADIP) here, if
// required. Default priority level is high.
PIE1bits.ADIE = 1;      // Enable A/D conversion interrupt
ADCON1Hbits.ADON = 1;   // Turn on A/D 
ADCON1Lbits.SAMP = 1;   // Start sampling the input
Delay();                // Ensure the correct sampling time has elapsed
                        // before starting conversion. 
ADCON1Lbits.SAMP = 0;   // End A/D sampling and start conversion
// Example code for A/D ISR:
#pragma interrupt _ADC1Interrupt
void _ADC1Interrupt(void)
{
    PIR1bits.ADIF = 0;