www.pudn.com > spi.rar > SPI_MODE0.ASM
;----------------------------------------------------------------------------- ; Copyright (C) 2001 CYGNAL INTEGRATED PRODUCTS, INC. ; All rights reserved. ; ; FILE NAME : SPI_MODE0.ASM ; DATE : 14 DEC 01 ; TARGET MCU : C8051F30x ; DESCRIPTION : This is a function which implements a master SPI port on ; the C8051F30x series of devices. The function can ; be called from a C program with the following function ; prototype: ; ; extern char SPI_Transfer (char); ; ; NOTES : Timing is as follows (Mode 0 SPI): ; Parameter SYSCLKs ; MOSI valid to SCK rising 2 ; SCK rising to MISO Latch 2 ; SCK falling to MOSI valid 5 ; SCK high time 5 ; SCK low time 7 ; ;----------------------------------------------------------------------------- NAME SPI_MODE0 ?PR?_SPI_Transfer?SPI_MODE0 SEGMENT CODE PUBLIC _SPI_Transfer $include (c8051f300.inc) ; Include regsiter definition file. $include (SPI_defs.h) ; Include sbit definitions for SPI RSEG ?PR?_SPI_Transfer?SPI_MODE0 _SPI_Transfer: USING 0 MOV A, R7 ; Store passed variable in A MOV R7, #08H ; Load R7 to count bits RLC A ; Rotate MSB into Carry Bit SPI_Loop: MOV MOSI, C ; Move bit out to MOSI SETB SCK ; Clock High MOV C, MISO ; Move MISO into Carry Bit RLC A ; Rotate Carry Bit into A CLR SCK ; Clock Low DJNZ R7, SPI_Loop ; Loop for another bit until finished MOV R7, A ; Store return value in R7 ?C0001: RET ; Return from routine END ; END OF FILE