unsigned int ADCResult=0;
float voltage=0;
void main(void)
{
unsigned char channel=0x00,config1=0x00,config2=0x00,config3=0x00,portconfig=0x00,i=0;
//----- clear adc interrupt and turn off adc if in case was on prerviously---------------
CloseADC();
//-------------------------initialize adc---------------------------------------------------------------
/**** ADC configured for:
* FOSC/2 as conversion clock
* Result is right justified
* Aquisition time of 2 AD
* Channel 1 for sampling
* ADC interrupt on
* ADC reference voltage from VDD & VSS
*/
config1 = ADC_FOSC_2 | ADC_RIGHT_JUST | ADC_2_TAD ;
config2 = ADC_CH0 | ADC_INT_ON | ADC_REF_VDD_VSS ;
portconfig = ADC_15ANA ;
OpenADC(config1,config2,portconfig);
//------------------------------initialize the adc interrupt and enable them-------------------------------------
ADC_INT_ENABLE();
//-----------------------sample and convert-------------------------------- -------------------------
for(i=0;i<16;i++)
{
ConvertADC();
while(BusyADC());
ADCResult += (unsigned int) ReadADC();
}
ADCResult /= 16;
voltage = (ADCResult*5.0)/1024; // convert ADC count into voltage
//-----------------------------------------------------------------------------------------------------------
CloseADC(); //turn off ADC
while(1); //End of program
}