Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

multypal adc readind with hitech

Status
Not open for further replies.

sahu

Member
whats wrong with me about multipal adc reading with hi tech (9.82)?
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
}
found error as
ADC_Functions.c; 40.10 constant expression required
 
1) What pic chip are you using and 2) why are you still using HiTech... Don't get me wrong, Hitech is a good compiler but it isn't supported anymore... The latest models are available with XC8 If you download it from microchip you can use it in lite mode....
 
Status
Not open for further replies.

Latest threads

Back
Top