unable to read multiple channel ADC..PLS HELP

sansenan
2008-04-03
2013-03-12
  • sansenan
    sansenan
    2008-04-03

    hello,

    I am using PIC18f4550,and below is the code...The ADC works fine for any single channel..But i am unable to read multiple channels ..

    Pls help. The lower bits of the 2 channels are diplayed on the ports.I only see one channels 
    reading on the PORT.

    Pls help this is urgent...

    void main(void) 

    int adc0,adc1; 
    TRISA = 0xff; // All are inputs 
    TRISB = 0; // All are output
    TRISD = 0;
    count = 0; 

    adc_open(ADC_CHN_0, ADC_FOSC_64,ADC_CFG_08A_0R, ADC_FRM_RJUST|ADC_INT_OFF);

    ADCON2bits.ACQT0 = 1;//(clock derived from A/D RC oscillator)
    ADCON2bits.ACQT1 = 1;
    ADCON2bits.ACQT2 = 1;

    adc_conv(); 

    while(1) 

    if (!ADCON0bits.GO) {

    adc0 = adc_read(); // read value
    }
    adc_setchannel(ADC_CHN_1);
    adc_conv();

    if (!ADCON0bits.GO) {

    adc1 = adc_read(); // read value
    }

    adc_setchannel(ADC_CHN_0);
    adc_conv();

    PORTB = adc1 ;
    PORTD = adc0 ; 

    } // End While

    }