User manual

Table Of Contents
Analog-to-Digital Converter Peripheral Labs
© 2009 Microchip Technology Inc. DS41369A-page 89
EXAMPLE 5-10: GET_INPUTS() CODE FOR ADC LAB 2
4. Copy/paste the code in Example 5-11 over the Decide() code from the previ-
ous lab:
EXAMPLE 5-11: DECIDE() CODE FOR ADC LAB 2
5. Copy/paste the code in Example 5-12 over the Do_Outputs() code from the
previous lab:
EXAMPLE 5-12: D0_OUTPUTS() CODE FOR ADC LAB 2
6. Copy/paste the code in Example 5-13 into the Timing() section labeled:
//ADD TIMING CODE HERE
EXAMPLE 5-13: TIMING() CODE FOR ADC LAB 2
unsigned char counter = 2;
//Give ADC hold capacitor time to charge
//This works out to approximately 8uS
while(--counter > 0);
//Start conversion by setting the GO/DONE bit.
GODONE = 1;
//Wait for ADC conversion to complete
//Polling the GO/DONE bit
// 0 = ADC completed
// 1 = ADC in progress
while(GODONE == 1);
//Shift the ADRESH result to the left
//by three bit positions and assign to
//TMR0_preload
TMR0_preload = ADRESH<<3;
//XOR the toggle value with 1
toggle ^= 1;
//Assign the toggle value to RC0 pin
RC0 = toggle;
//Clear the T0IF
T0IF = 0;
//Subtract the TMR0_preload value from 255 and
//then use to preload TMR0
TMR0 = 255 – TMR0_preload;
//Sit here and wait for TMR0 to overflow while (T0IF == 0);