;Name : SPIBUS
;Author : TongLin
;Description : This file implement all spi bus function (write and read)
;Creation date : 2005-7-2 14:08
;Revision : 1.00
;Compiler : Keil A51 7.01
NAME SPIBUS
;The following defined spi bus address
SPIBUS_SO EQU 91H
SPIBUS_SI EQU 92H
SPIBUS_SCK EQU 93H
?PR?SPIBUS SEGMENT CODE
PUBLIC SPI_WRITE
PUBLIC SPI_READ
RSEG ?PR?SPIBUS
USING 0
;implement spi bus write function
;input data: r7 is want to writting data
;use register: r7 and acc
;c procedure prototype: void spi_write( unsigned char wdata)
SPI_WRITE: MOV A,R7
MOV R7,#08H
SPI_WRITE1: RLC A
MOV SPIBUS_SI,C
SETB SPIBUS_SCK
CLR SPIBUS_SCK
DJNZ R7,SPI_WRITE1
RET
;implement spi bus read function
;input data: none
;use register: r7 and acc
;c procedure prototype: unsigned char spi_write( void )
SPI_READ: MOV R7,#08H
SPI_READ1: MOV C,SPIBUS_SO
RLC A
SETB SPIBUS_SCK
CLR SPIBUS_SCK
DJNZ R7,SPI_READ1
MOV R7,A
RET
END