User manual

Table Of Contents
Analog-to-Digital Converter Peripheral Labs
© 2009 Microchip Technology Inc. DS41369A-page 79
FIGURE 5-3: MAIN() SOFTWARE CONTROL LOOP FLOWCHART FOR
COMPARATOR LAB 1
Following the Get_Inputs(), the 10-bit ADC result is now in the ADRESH:ADRESL
registers. The Decide() assigns the ADC result value, shifted four bit positions to the
right, to the LED_Output variable.
Finally, the Do_Outputs() assigns the contents of LED_Output to the PORTC
register that will light the LEDs connected to RC0, RC1, RC2 and RC3 accordingly.
5.2.3.3 PROCEDURE
Using the Project Wizard, create a new project called ADC_Lab1.mcp. Once com-
pleted, open the ADC_Lab1.c source file in MPLAB and make the following changes:
1. Copy/paste the code in Example 5-1 into the top of the main firmware source file
under the heading labeled:
//----------------DATA MEMORY---------------
EXAMPLE 5-1: GLOBAL VARIABLES USED IN LAB 1
2. Copy/paste the code in Example 5-2 into the top of the main firmware source file
under the heading labeled:
//----------------SUPPORT ROUTINES---------------
Get_Inputs()
Delay_1mS()
Start conversion by setting
GO/DONE
bit
Gives ADC capacitor time to charge
NO
GO/DONE = 1
?
YES
END
Wait for ADC to complete
unsigned char LED_Output = 0;//assigned to PORTC to light
//connected LEDs