;*****************************************************************************
;place this section before the main code
SENDREG EQU 0x20 ;declare send buffer
BITCOUNT EQU 0x21 ;declare bit counter
;change the port/bit assignment to the pins you will be using to interface
;with the 74HC595
#define SDO PORTB,RB0
#define SCK PORTB,RB1
#define LAT PORTB,RB2
;*****************************************************************************
;Do this in main code to use this routine -
movlw <DATA> ;load W with data to be sent
call 595Write ;send data
;or if sending data that is stored in a register, do this -
movfw <ADDRESS> ;load W with data to be sent
call 595Write ;send data
;*****************************************************************************
;Place this with your subroutines
595Write movwf SENDREG ;load send buffer
movlw 8 ;init bit counter to 8 bits
movwf BITCOUNT
TXLoop bsf SDO ;assume MSB = 1
btfss SENDREG,7 ;MSB = 1?
bcf SDO ;no, send 0
bsf SCK ;strobe shift clock
bcf SCK
rlf SENDREG,F ;shift bits
decfsz BITCOUNT,F ;decrement bit counter
goto TXLoop ;keep sending until BITCOUNT = 0
bsf LAT ;all bits sent, strobe latch
bcf LAT
return ;done