#define channel_1 0 /* AN0 */
#define channel_2 1 /* AN1 */
#define channel_3 2 /* AN2 */
/*
Example:
result = AdcRead(channel_1);
*/
unsigned int AdcRead(unsigned char channel)
{
unsigned int result;
unsigned char sample_time = 5U;
ADCON1 = 0x80U; /* 10 bit Right justified result, Vdd as +ref, Vss -ref */
ADCON0 = 0x81U; /* Conversion clock Fosc/32 */
ADCON0 |= (unsigned char)(channel << 2U); /* Select channel */
while(sample_time--){
;
}
GODONE = 1U; /* Start conversion */
while(GODONE){
;
}
result = ADRESH;
result <<= 8U;
result |= ADRESL;
return result;
}
/* A to d Function */