get_AD_value

=get_AD_value= Owner: Michelle

Purpose and Documentation
What is the purpose of this function? Explain what it does, and justify it's place in the program. This section will appear in the Technical Documentation, so try to be complete.

Syntax
unsigned int get_AD_value(void)

Usage
When and how should this function be called? Use examples where necessary.

Input Arguments

 * void. This function takes no arguments.
 * int example. A value that is used by the function.
 * char* string. A string that will be transmitted to the serial transmit.

Output Arguments

 * None. This function does not make changes to any existing values.
 * int* status. The program will modify the non-local value status if it has an error.

Return Value

 * int. When the operation successfully, a 1 is returned. Otherwise, a 0 is returned.

Read

 * PIR1bits.ADIF
 * ADRESH
 * ADRESL

Write

 * ADCON0bits.GO

Operation
Describe in very general terms how the function fulfills it's purpose. This should be reflected in the code.

Code
code format="c" /** * Returns an unsigned 16 bit integer, containing 10 bits of A/D result. The 6 most * significant bits will be 0. * Precondition: The A/D Converter is on and initialised * @return 10 bit A/D result */ unsigned int get_AD_value {   ADCON0bits.GO = 1;    //Start A/D conversion while(PIR1bits.ADIF == 0);   //Wait until ready

unsigned int result = ADRESH << 8;   //Get upper two bits result = result | ADRESL;   //Get lower eight bits

store_samples(result,VSS,VDD); //save this voltage to the buffer (Alex)

return result;               //Result is 10 bits } code