User manual

Table Of Contents
PICDEM
TM
Lab Development Board User’s Guide
DS41369A-page 82 © 2009 Microchip Technology Inc.
EXAMPLE 5-4: GET_INPUTS() CODE FOR ADC LAB 1
5. Copy/paste the code in Example 5-5 into the Decide() section labeled:
//ADD DECIDE CODE HERE
EXAMPLE 5-5: DECIDE() CODE FOR ADC LAB 1
6. Copy/paste the code in Example 5-6 into the Do_Outputs() section labeled:
//ADD DO OUTPUTS CODE HERE
EXAMPLE 5-6: D0_OUTPUTS() CODE FOR ADC LAB 1
7. Copy/paste the code in Example 5-7 into the main() section labeled:
//ADD MAIN CODE HERE
EXAMPLE 5-7: MAIN() CODE FOR ADC LAB 1
8. Compile the project. There should be no errors.
//Perform an ADC of potentiometer connected to pin 13
//Wait the required acquisition time
Delay_1mS();
//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);
//Assign the upper 4 bits of ADRESH to the lower 4 bits
//of LED_Output
LED_Output = ADRESH >> 4; //Shifts the bits in ADRESL 4 bits
//to the right
//Assign contents of LED_Output to PORTC to light the connected
//LEDs
PORTC = LED_Output;
Initialize(); //Initialize the relevant registers
while(1)
{
Get_Inputs();
Decide();
Do_Outputs();
}