Owner's manual
AN130
AN130REV2 13
;* Routine - send_byte
;* Input - Byte stored in W register
;* Output - none
;* This subroutine sends a byte, one bit at a time, MSB first, to the ADC
;*****************************************************************************
send_byte MOVWF SERI_DATA ; Move W to SERI_DATA
MOVLW 0x08 ; Set COUNT to 8
MOVWF COUNT ; to trasnsmit each bit individually
bitloop1: RLF SERI_DATA, 1 ; Rotate SERI_DATA to send MSB first
BTFSC STATUS, CARRY ; If bit is low, skip next instruction
BSF PORTA, SDI ; If high, set SDI
BTFSS STATUS, CARRY ; If bit is high, skip next instr.
BCF PORTA, SDI ; If low, clear SDI
BSF PORTA, SCLK ; Toggle SCLK High
BCF PORTA, SCLK ; Toggle SCLK Low
DECFSZ COUNT, 1 ; Go to next bit unless done
goto bitloop1
BCF PORTA, SDI ; Return SDI to low state
RETURN ; Exit Subroutine
;*****************************************************************************
;* Routine - receive_byte
;* Input - none
;* Output - Byte stored in W register
;* This subroutine receives a byte, one bit at a time, MSB first, from the ADC
;*****************************************************************************
receive_byte MOVLW 0x08 ; Set COUNT to 8
MOVWF COUNT ; to receive each bit individually
bitloop2: BTFSC PORTA, SDO ; If Bit is low, skip next instruction
BSF STATUS, CARRY ; Otherwise, set carry bit
BTFSS PORTA, SDO ; If Bit is high, skip next instruction
BCF STATUS, CARRY ; Otherwise, clear carry bit
RLF SERI_DATA, 1 ; Rotate Carry into SERI_DATA, MSB first
BSF PORTA, SCLK ; Toggle SCLK High
BCF PORTA, SCLK ; Toggle SCLK Low
DECFSZ COUNT, 1 ; Go to next bit unless finished
goto bitloop2
MOVF SERI_DATA, 0 ; Put received byte into W
RETURN ; Exit Subroutine
;*****************************************************************************