控制工程师论坛

教程与手册

SPI程序

xilinxue
xilinxue

2008-11-04

;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

回帖

评论1

总共 , 当前 /
首页 | 登录 | 注册 | 返回顶部↑
手机版 | 电脑版
版权所有 Copyright(C) 2016 CE China