⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spi_mode0.asm

📁 C8051F30X系列软件SPI例子
💻 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -