Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
/*--- Initialise A/D converter ---*/
void init_adc(void)
{
ADCON0 = 0x94; /* Right justified result, Vdd as ref */
ADCON1 = 0x20; /* Conversion clock Fosc/32 */
}
/*--- Read A/D conversion ---*/
static uint16_t read_ad(uint8_t channel)
{
uint16_t result = 0;
uint8_t acquisitionTime = 5;
ADCON0 &= 0xe3; /* Clear current channel select */
ADCON0 |= (channel << 2); /* Select channel */
ADON = 1; /* Turn on A/D */
while(acquisitionTime--){ /* Sample channel */
continue;
}
GODONE = 1; /* Start conversion */
while(GODONE){ /* Wait for conversion end */
continue;
}
result = ADRESH;
result <<= 8;
result |= ADRESL;
return result;
}