
;
;
;
GetSpiChar:		;Output 110 then clock in 8 bits plus 1 extra bit
	setb	CS	;Chip select high
	setb	SDI	;First bit sent to VDIP1 a "1" for 'READ'
	nop
	nop
	setb	SCLK	;clock in the 1st '1' bit
	nop
	nop
	clr	SCLK
	nop
	nop
	setb	SCLK	;clock in the 2nd '1' bit
	nop
	nop
	clr	SCLK
	clr	SDI	;'0' means read "Data" and '1' means reads "Status"
	nop
	nop
	setb	SCLK	;clock in the '0' bit
	nop
	nop
	clr	SCLK
;
;	Now clock in 8 bits plus 9th bit (to see if old or new data)
;
	mov	r0,#8	;bit counter
;
GCa:	mov	c,SDO	;read the data bit
	setb	SCLK
	nop
	rlc	a	;Most significant bit first
	clr	SCLK
	djnz	r0,GCa
	mov	c,SDO	;move 9th bit into C. 1=Old data, 0=New data
;
	clr	CS
	nop
	setb	SCLK
	nop
	nop
	clr	SCLK
	ret
;
;
;
SendSpiChar:		;Output '100' then clock out 8 bits of data
SCc:	push	acc
	setb	CS	;Chip select high
	setb	SDI	;First bit sent to VDIP1 a "1" for 'READ'
	nop
	setb	SCLK	;clock in the 1st '1' bit
	nop
	nop
	clr	SCLK
	clr	SDI
	nop
	setb	SCLK	;clock in a '0' bit
	nop
	nop
	clr	SCLK
	nop
	nop
	setb	SCLK	;clock in the '0' bit
;
;	Now clock out 8 bits of data
;
	mov	r0,#8	;bit counter
SCf:	clr	SCLK
	rlc	a
	mov	SDI,c	;write the data bit
	setb	SCLK
	djnz	r0,SCf
;
	clr	SCLK
	nop
	mov	c,SDO	;check if write was accepted or not
	setb	SCLK
	pop	acc
	clr	SCLK
	clr	CS
	nop
	jc	SCc	;write again if VDIP1 not ready	
	nop
	setb	SCLK
	nop
	nop
	clr	SCLK
	ret
;
;
;
