sahu
Member
whats wrong with me about multipal adc reading with hi tech (9.82)?
found error as
Code:
void InitADC(unsigned char Channel)
{
ANSEL = 0x10; // Clear Pin selection bits
ANSEL |= Channel; // Select Channel
TRISA = 0x07; // AN0 TO AN 2 input, rest all output
TRISA |= Channel; // Make selected channel pins input
ADCON0 = 0x81; // Turn on the A/D Converter
CMCON = 0x07; // Shut off the Comparator, so that pins are available for ADC
VRCON = 0x00; // Shut off the Voltage Reference for Comparator
}
unsigned int GetADCValue(unsigned char Channel)
{
ADCON0 &= 0xf3; // Clear Channel selection bits
switch(Channel)
{
case ANS0: ADCON0 |= 0x00; break; // Select AN0 pin as ADC input
case ANS1: ADCON0 |= 0x04; break; // Select AN1 pin as ADC input
case ANS2: ADCON0 |= 0x08; break; // Select AN2 pin as ADC input
case ANS3: ADCON0 |= 0x0c; break; // Select AN4 pin as ADC input
default: return 0; //Return error, wrong channel selected
}
__delay_ms(10); // Time for Acqusition capacitor to charge up and show correct value
GO_nDONE = 1; // Enable Go/Done
while(GO_nDONE); //wait for conversion completion
return ((ADRESH<<8)+ADRESL); // Return 10 bit ADC value
}
ADC_Functions.c; 40.10 constant expression required