User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 88 © 2009 Microchip Technology Inc.
EXAMPLE 5-9: INITIALIZE CODE FOR ADC LAB 2
3. Copy/paste the code in Example 5-10 over the Get_Inputs() code from the
previous lab:
//Configure Port:
PORTB = 0;
//Disable pin output driver (See TRIS register)
TRISB4 = 1;
// Configure RB4 as analog pin as analog
ANS10 = 1;
//Configure RC0, RC1, RC2 and RC3 as digital output
PORTC = 0;
TRISC0 = 0;
ANS4 = 0;
//Configure Timer0 as follows:
//Select the FOSC/4 internal instruction clock
//as the clock source for TMR0
T0CS = 0;
//Increment TMR0 value on low-to-high transition
//of the FOSC/4
T0SE = 0;
//Assign the prescaler to TMR0
PSA = 1;
//Configure the prescaler to increment TMR0
//at a rate of 1:16
PS0 = 1;
PS1 = 1;
PS2 = 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;