spi.inc

来自「汽车无钥进入系统设计,基于PIC单片机16F639,包括电路图和源码」· INC 代码 · 共 98 行

INC
98
字号
	ifndef SPI_INC
#define	SPI_INC

;/*
;	Stores the most significant Byte
;*/
	extern SPI.BufferH
;/*
;	Stores the least significant Byte
;*/
	extern SPI.BufferL
	extern SPI.Read, SPI.Write
	;extern SPI.ShiftOutBuffer, SPI.ShiftInBuffer


;/*
;
;	This macro initialises the SPI module
;
;*/
SPI.Init macro
	banksel TRISC
	movlw	b'11001110'		; Set LFDATA,ALERT, and CS as inputs 
	movwf	TRISC			; 
	banksel	PORTC
	bsf		AFECS			; Take AFE CS Line high
	endm




;
;	This macro shifts data out of the MCU through the SPI-Interface.
;
;
;	@param SPI.BufferH The most significant Byte of the Data
;	@param SPI.BufferL The least significant Byte of the Data
;
;	@example
;	pagesel SPI.BufferH
;	movlw	0xf0
;	movwf	SPI.BufferH
;	movlw	0x0f
;	movwf	SPI.BufferL
;	call	SPI.Write
;	@end-ex
;	@ex-desc This sends 0xf00f over the SPI-Bus
;
;	@status Written
;
;	@stacklevel +1
;
;
;
;SPI.Write macro
;	call	SPI.ShiftOutBuffer
;	endm



;
;	This macro reads two Bytes from the SPI-Bus.
;	Put the Read command and the address in the SPI.BufferH and SPI.BufferL Registers.
;	Then call SPI.Read.
;	Then read the returned values in SPI.BufferH and SPI.BufferL.
;
;
;	@param SPI.BufferH The most significant Byte of the Data
;	@param SPI.BufferL The least significant Byte of the Data
;
;
;	@return SPI.BufferH The most significant Byte of the Data
;	@return SPI.BufferL The least significant Byte of the Data
;
;	@example
;	pagesel SPI.BufferH
;	movlw	0xf0
;	movwf	SPI.BufferH
;	movlw	0x0f
;	movwf	SPI.BufferL
;	call	SPI.Read
;	@end-ex
;	@ex-desc This sends 0xf00f over the SPI-Bus, and reads the answer to SPI.BufferH and SPI.BufferL.
;
;	@status Written
;
;	@stacklevel +1
;
;
;
;SPI.Read macro
;	call	SPI.ShiftOutBuffer
;	call	SPI.ShiftInBuffer
;	endm


	endif

⌨️ 快捷键说明

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