Here is an example reading the Registers directly... just six simple lines of code...
MyByte var Byte
ADCON1=%00000000
' Set LEFT Justification
' Enable ALL ADC's (using PIC16F87x as example)
ADCON0=%01000001
' Set Fosc/8
' Set ADC Channel 0 (RA0/AN0)
' Enable ADC Module
PauseUS 50
' 50uS Pause to allow sampling Capacitor to charge
ADCON0.1=1
' Start Conversion
While ADCON0.1=1:Wend
' Wait for conversion to complete
MyByte=ADRESH
' Read 8-bit Result
Justification is controlled by bit 7 of ADCON1. Use LEFT justification (ADCON1.7=0) for 8-bit ADC usage (byte result) and you read the result from the ADRESH register (as per the example above). Use RIGHT justification (ADCON1.7=1) for 10-bit ADC usage (word result), then ADRESH becomes the highbyte of the word, and ADRESL becomes the lowbyte... as per the example below (which also switches to RA1/AN1)...
MyWord var Word
ADCON1=%10000000
' Set LEFT Justification
' Enable ALL ADC's (using PIC16F87x as example)
ADCON0=%01001001
' Set Fosc/8
' Set ADC Channel 1 (RA1/AN1)
' Enable ADC Module
PauseUS 50
' 50uS Pause to allow sampling Capacitor to charge
ADCON0.1=1
' Start Conversion
While ADCON0.1=1:Wend
' Wait for conversion to complete
MyWord.Highbyte=ADRESH
MyWord.Lowbyte=ADRESL
' Read 16-bit Result
Braindamagingly simple (every PIC that has ADC's gives explicit step-by-step instructions in it's Datasheet - you gotta read those Datasheets!!).... now you know how simple it is, hands up anyone that can give me a valid reason to continue using ADCIN?
Melanie
Bookmarks