double Bandgap_Voltage,VDD_Voltage;
void ADC_Bypass (void) // The first three times convert should be
bypass
{
unsigned char ozc;
for (ozc=0;ozc<0x03;ozc++)
{
clr_ADCF;
set_ADCS;
while(ADCF == 0);
}
}
void main (void)
{
double bgvalue;
READ_BANDGAP();
Enable_ADC_BandGap;
ADC_Bypass();
clr_ADCF;
set_ADCS;
while(ADCF == 0);
bgvalue = (ADCRH<<4) + ADCRL;
VDD_Voltage = (0xFFF/bgvalue)*Bandgap_Voltage;
printf ("\n Bandgap voltage = %e", Bandgap_Voltage);
printf ("\n VDD voltage = %e", VDD_Voltage);
while(1);
}
|