Function ReadADC(ch As uByte) ' Note: TRIS And ADCON1 must already be set ' Reads RIGHT JUSTIFIED data ' Requires the following #defines ' #DEFINE ADC_CLOCK ' #DEFINE ADC_DELAY ( this is the sampling delay in usescs) ' Larry Bradley November 25, 2003 movf ch,W ' channel (0 to 7) into WREG #ifdef ADCON2 ' Enhanced ADC, as in the 18F1320 rlcf WREG, F ' Shift channel into proper position rlcf WREG, F andlw 0x1C ' Mask iorlw 1 ' Turn On ADC movwf ADCON0 ' Set up To start sampling movf ADCON2, W ' Set up clock source iorlw 0x80 ' Right justified iorlw ADC_CLOCK ' OR in the clock bits movwf ADCON2 #else ' Compatible ADC, as in 18F452 rlcf WREG, F ' Shift channel into proper position rlcf WREG, F rlcf WREG, F andlw 0x38 ' Mask channel bits iorlw ((( ADC_CLOCK ) & 3) << 6) | 1 ' Set up low 2 bits of clock source And turn On ADC movwf ADCON0 ' Set up To start sampling movf ADCON1,W iorlw ((( ADC_CLOCK ) & 4) << 4) ' Set up high bit of clock source iorlw 0x80 ' Right justified movwf ADCON1 #endif #If ADC_DELAY <> 0 Call pauseus( ADC_DELAY ) ' Wait for a while for input to settle #endif bsf GO ' Start conversion loop: btfsc GO ' Wait For conversion To complete bra loop End Function ADRES