An88 – Cirrus Logic AN88 User Manual

Page 11

Advertising
background image

AN88

AN88Rev2

11

;*************************************************************************************
;* Routine - send_spi
;* Input - Byte to be transmitted is placed in W
;* Output - None
;* This subroutine sends a byte to the ADC.
;*************************************************************************************
send_spi: MOVWF

SPDR

; Move W to SPDR

MOVLW

0x08

; Set COUNT to count to 8

MOVWF

COUNT

; to transmit byte out SPI

BCF

PORTA,SCLK

; Clear SCLK

wait0

; Send Bit
RLF

SPDR,1

; Rotate SPDR, send MSB 1st

BTFSC

STATUS,CARRY_BIT ; If bit low skip next instruct.

BSF

PORTA,SDI

; Set SDI

BTFSS

STATUS,CARRY_BIT ; If bit high, skip next instruct.

BCF

PORTA,SDI

; Clear SDI

BSF

PORTA,SCLK

; Toggle Clock

BCF

PORTA,SCLK

DECFSZ

COUNT,1

; Loop until byte is transmitted

goto

wait0

BCF

PORTA,SDI

; Return Pin low

RETURN

; Exit Subroutine

;*************************************************************************************
;* Routine - receive_spi
;* Input - none
;* Output - Byte received is placed in W
;* This subroutine receives a byte from the ADC.
;*************************************************************************************
receive_spi:

MOVLW

0x08

; Set COUNT to count to 8

MOVWF

COUNT

; to transmit byte out SPI

BCF

PORTA,SCLK

; Clear SCLK

wait1:

; Receive bit
BTFSC

PORTA,SDO

; If bit low skip next instruct.

BSF

STATUS,CARRY_BIT ; Set SDI

BTFSS

PORTA,SDO

; If bit high, skip next instruct.

BCF

STATUS,CARRY_BIT ; Clear SDI

RLF

SPDR,1

; Rotate SPDR, Receive MSB 1st

BSF

PORTA,SCLK

; Toggle Clock

BCF

PORTA,SCLK

DECFSZ

COUNT,1

; Loop until byte is transmitted

goto

wait1

MOVF

SPDR,0

; Put byte attained in W

RETURN

; Exit Subroutine

Advertising