spi.asm

来自「web51的开发库」· 汇编 代码 · 共 45 行

ASM
45
字号
;#########################;# SPI bus communication #;#########################;.equ	CLK_SPI, 0x91	; P1.1.equ	DQ_SPI,  0x92	; P1.2	.text	.using	0.global	spiout.local	spiouLp, spiouEndspiout:	; Shift out a byte to the SPI, last significant bit first.	; CLK, DQ expected high on entry. Return with CLK high.	; Called with data to send in A.	; Destroys A.	setb	C		; stop markspiouLp:rrc	a		; move bit into CY	jz	spiouEnd	clr	CLK_SPI		; drop clock	mov	DQ_SPI, C	; output bit	nop	setb	CLK_SPI		; raise clock	clr	C	sjmp	spiouLp		; next bitspiouEnd:	ret.global	spiin.local	spiinL	spiin:	; Shift in a byte from the SPI, last significant bit first.	; CLK, DQ expected high on entry. Return with CLK high.	; Returns received data byte in A.	mov	a,#0x80		; stop marker	setb	DQ_SPI		; make SPI Data Line an inputspiinL:	clr	CLK_SPI		; drop clock	nop	mov	c, DQ_SPI	; input bit	setb	CLK_SPI		; raise clock	rrc	a		; move bit into byte	jnc	spiinL		; next bit	ret	;; end

⌨️ 快捷键说明

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