Daha önce ben yapmıştım test için kullandığım asmleri veriyorum ben 18f452 kullanmıştım 16f877 dede çalışması lazım sadece bank seçimlerini eklemen gerekecek kolay gelsin
MASTER ASM
SERIAL
BSF TRISC,7
BCF TRISC,6
BCF TRISC,5
BSF TRISC,4
BCF TRISC,3
BCF TRISC,2
BCF TRISC,1
BCF TRISC,0
movlw B'00000000' ; SPI, middle of
movwf SSPSTAT ; output time sampling
;BANKSEL SSPCON ; BANK 0
movlw B'00110001' ; Mode 1,1 SPI Master Mode, 1/16
; Tosc bit time
movwf SSPCON1 ; SSP is on
RETURN
SENDCMD
BCF SSPSTAT , BF
MOVFF DATAM , SSPBUF
SC1 BTFSS SSPSTAT , BF
GOTO SC1
RETURN
RESPOND
BCF SSPSTAT , BF
MOVFF DATAM , SSPBUF
SC2 BTFSS SSPSTAT , BF
GOTO SC2
MOVFF SSPBUF , DATAM
RETURN
Send_DT
bcf PORTA,2 ;SS PIN Enable Chip Select Output (low)
;movf DATAM,W ; Get Ctr (Counter Value) in W
movwf SSPBUF ; put in SSPBUF
;BANKSEL SSPSTAT ; BANK 1
Char1
btfss SSPSTAT,BF ; Data transfer complete?
; (Buffer Full?)
goto Char1 ; if not, check again
movf SSPBUF,W
; Read SSPBUF register
bsf PORTA,2
;CALL Chk4Dat
RETURN
Update_Test_Counter
incf DATAM,F ; Increment counter variable
Delay
movlw H'F0' ; Simple Delay loop
movwf Dly1 ; |
movlw H'0F' ; |
movwf Dly0 ; |
DlyLoop
decfsz Dly0,F ; |
goto DlyLoop ; |
decfsz Dly1,F ; |
goto DlyLoop ; |
DoAgain
goto Send_DT
Chk4Dat
MOVF SSPBUF,W
MOVWF PORTD
RETURN
bsf PORTA,2
btfss SSPSTAT,BF ; Indirectly test
goto Chk4Dat ; New data, do a transfer
RXXData
movf SSPBUF,W ; put in SSPBUF into W
movwf PORTD ; Show the results on PORTB
RETURN ; Receive Next Byte
SLAVE ASM
SERIAL
BSF TRISC,7
BCF TRISC,6
BCF TRISC,5
BSF TRISC,4
BSF TRISC,3
BCF TRISC,2
BCF TRISC,1
BCF TRISC,0
movlw B'00000000' ; SPI with middle of
movwf SSPSTAT ; output time sampling
movlw B'00110100' ; Mode 1,1 SPI Slave Mode,
movwf SSPCON1 ; SSP is on
RETURN
SENDCMD
BCF SSPSTAT , BF
MOVFF DATAM , SSPBUF
SC1 BTFSS SSPSTAT , BF
GOTO SC1
RETURN
RESPOND
BCF SSPSTAT , BF
MOVFF DATAM , SSPBUF
SC2 BTFSS SSPSTAT , BF
GOTO SC2
bcf PORTD,0
MOVFF SSPBUF , DATAM
RETURN
Chk4Dat
btfss SSPSTAT,BF ; Indirectly test
goto Chk4Dat ; New data, do a transfer
RX_Data
movf SSPBUF,W ; put in SSPBUF into W
movwf PORTD
movf SSPBUF,W
DoAgain
;CALL Send_DT ; Optional customer code can go here
RETURN ; Receive Next Byte
Send_DT
;CALL RdRS232 ;MOVLW H'22' ; Get Ctr (Counter Value) in W
movwf SSPBUF ; put in SSPBUF
Char1
btfss SSPSTAT,BF ; Data transfer complete?
; (Buffer Full?)
goto Char1 ; if not, check again
movf SSPBUF,W ; Read SSPBUF register
RETURN