An130 – Cirrus Logic AN130 User Manual
Page 12
AN130
12
AN130REV2
;* Routine - write_register
;* Input - COMMAND, HIGHBYTE, MIDBYTE, LOWBYTE
;* Output - none
;* This subroutine writes to the internal registers of the CS55/2122/23/24/28
;*****************************************************************************
write_register
BCF
PORTA, CS
; Enable ADC
MOVF
COMMAND, 0; Load W with Command byte
CALL
send_byte
; Send command info
MOVF
HIGHBYTE, 0 ; Load W with high byte
CALL
send_byte
; Send high byte first..
MOVF
MIDBYTE, 0 ; Load W with middle byte
CALL
send_byte
; Then the middle byte..
MOVF
LOWBYTE, 0 ; Load W with low byte
CALL
send_byte
; .. and then the low byte last.
BSF
PORTA, CS
; Disable ADC
RETURN
; Exit Subroutine
;*****************************************************************************
;* Routine - read_register
;* Input - COMMAND
;* Output - HIGHBYTE, MIDBYTE, LOWBYTE
;* This subroutine reads from the internal registers of the CS5521/22/23/24/28
;*****************************************************************************
read_register
BCF
PORTA, CS
; Enable ADC
MOVF
COMMAND, 0; Load W with Command Byte
CALL
send_byte
; Send Command info
CALL
receive_byte
; receive High byte first..
MOVWF HIGHBYTE
; Move W to HIGHBYTE
CALL
receive_byte
; and then the middle byte..
MOVWF MIDBYTE
; Move W to MIDBYTE
CALL
receive_byte
; and finally the Low byte.
MOVWF LOWBYTE
; Move W to LOWBYTE
BSF
PORTA, CS
; Disable ADC
RETURN
; Exit Subroutine
;*****************************************************************************