User manual

Table Of Contents
Analog-to-Digital Converter Peripheral Labs
© 2009 Microchip Technology Inc. DS41369A-page 81
EXAMPLE 5-3: INITIALIZE CODE FOR COMPARATOR LAB 1
4. Copy/paste the code in Example 5-4 into the Get_Inputs() section labeled:
//ADD GET INPUTS CODE HERE
//Configure Port:
//Disable pin output driver (See TRIS register)
TRISB4 = 1;
// Configure pin as analog
ANS10 = 1;
//Configure RC0, RC1, RC2 and RC3 as digital output
PORTC = 0;
TRISC0 = 0;
TRISC1 = 0;
TRISC2 = 0;
TRISC3 = 0;
ANS4 = 0;
ANS5 = 0;
ANS6 = 0;
ANS7 = 0;
//Configure the ADC module:
//Select ADC conversion clock Frc
ADCS0 = 1;
ADCS1 = 1;
ADCS2 = 1;
//Configure voltage reference using VDD
VCFG = 0;
//Select ADC input channel Pin 13 (RB4/AN10)
CHS0 = 0;
CHS1 = 1;
CHS2 = 0;
CHS3 = 1;
//Select result format left justified
ADFM = 0;
//Turn on ADC module
ADON = 1;