be80be
Well-Known Member
Here you can use this if you want to see how it works better
I didn't change all of these Tx <- '110010011' it is the binary (movlw b'00001111' ;fulls the buffer)
Code:
LIST p=16F877a ;tell assembler what chip we are using
include "P16f877a.inc" ;include the defaults for the chip
ERRORLEVEL 0, -302 ;suppress bank selection messages
__config 0x399A ;sets the configuration settings (oscillator type etc.)
cblock 0x20 ;start of general purpose registers
d1
d2
Tx
CountSPI
endc
#define data PORTC,1
#define clock PORTC,0
HC164 macro var,var1
Local SendLoop
movlw .8 ;8 bits to send out
movwf var1 ; counter to count out the bits
SendLoop:
rlf var,f ;rotate var left one place
btfss STATUS,C ; is carry a 1
bcf data ; if not set data to 0
btfsc STATUS,C ; is carry a 0
bsf data ;if not set data to 1
bsf clock ; generate a clock
nop ;two nop for clock delay
nop
bcf clock
decfsz var1,f ;has eight bit been sent
goto SendLoop ; if not go back and keep loading till done
endm
org 0x0000
; include "HC164.INC"
Start
movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)
banksel TRISC
movlw B'00000000'
movwf TRISC
banksel TRISD
movlw B'00000000'
movwf TRISD
banksel PORTC
clrf PORTC
banksel PORTD
clrf PORTD
main
call send0
call Delay
call send1
call Delay
call send2
call Delay
call send3
call Delay
call send4
call Delay
call send5
call Delay
call send6
call Delay
goto main
send0
movlw b'00111111'
movwf PORTD
movlw b'00000111' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
send1
movlw b'01011111'
movwf PORTD
movlw b'10111000' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
send2
movlw b'00101111'
movwf PORTD
movlw b'01110001' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
send3
movlw b'01110111'
movwf PORTD
movlw b'11100001' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
send4
movlw b'01111011'
movwf PORTD
movlw b'11000011' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
send5
movlw b'01111101'
movwf PORTD
movlw b'10000111' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
send6
movlw b'01111110'
movwf PORTD
movlw b'00001111' ;fulls the buffer
movwf Tx ; Tx <- '110010011'
HC164 Tx,CountSPI ;lets the macro send the data
return
Delay ;49993 cycles
movlw 0x0E
movwf d1
movlw 0x28
movwf d2
Delay_0
decfsz d1, f
goto $+2
decfsz d2, f
goto Delay_0
;3 cycles
goto $+1
nop
;4 cycles (including call)
return
end
Last edited: