Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
start
movwf buffer
movlw 0x08
movwf counter ; counts the 8 bits
bcf TX ; set TX low
call BItdelay ; delay to get a 9600 bit rate
TXLoop
rrf buffer ,f ;send one bit
btfss STATUS ,C ;
bcf TX ;
btfsc STATUS ,C ;
bsf TX ;
call BItdelay ;
decfsz counter,f ;test if all done
goto TXLoop ;
bsf TX ;
call BItdelay ;
return
BItdelay ; timing delay
movlw 0x17
movwf Count
Wait
nop
decfsz Count ,f
goto Wait
return
END ; directive 'end of program'
;*****************************************************************************
;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