Owner's manual
AN130
AN130REV2 11
;* Routine - convert
;* Input - none
;* Output - 24-bit Conversion Results in memory locations HIGHBYTE, MIDBYTE
;* and LOWBYTE.
;* The Algorithm itself will only perform a single
;* conversion using Setup 1. For multiple continuous
;* conversions, or for conversions using other setups, the routine
;* must be modified. (see the CS5521/22/23/24/28 data sheet for more info)
;*****************************************************************************
convert MOVLW 0x0B ; Command to read Configuration Reg.
MOVWF COMMAND ; Set Command Byte
CALL read_register ; Read Config. Register Information
MOVLW 0xF8 ; Load mask info into W
ANDWF HIGHBYTE, 1; Mask MC, LP, and RC to 0
MOVLW 0x03 ; Command to write Configuration Reg.
MOVWF COMMAND ; Set Command Byte
CALL write_register ; Write Config. Register with new info
; *** Receive Conversion Data ***
BCF PORTA, CS ; Enable ADC
MOVLW 0X80 ; Command for conversion using Setup 1
CALL send_byte ; send command byte
poll_sdo2: BTFSC PORTA, SDO; Wait until SDO falls to indicate
goto poll_sdo2 ; conversion completion
MOVLW 0X00 ; Command to start data output
CALL send_byte ; send command
CALL receive_byte ; Receive data...
MOVWF HIGHBYTE ; High Byte 1st..
CALL receive_byte
MOVWF MIDBYTE ; then the Middle Byte..
CALL receive_byte
MOVWF LOWBYTE ; and finally the Low Byte.
BSF PORTA, CS ; Disable ADC
RETURN ; Exit to "main"
;*****************************************************************************