; ...
; Enable writes to code memory.
	mov a, #0ACh	; send first byte of enable code
	call spi_it 	;
	mov a, #053h	; send second byte
	call spi_it 	;
	mov a, #0FFh	; send third byte as dummy
	call spi_it 	;
	mov a, #0FFh	; send fourth byte dummy for receiving 69h
	call spi_it 	;
	cjne A,#069h,enable_error ; received byte is not valid confirm one

; here we are okay to continue
;...
;...

;***************************************************************
spi_it:
; Shift out a byte, most significant bit first.
; Shift in a byte, most significant bit first.
; SCK expected low on entry. Return with SCK low.
; Called with data to send in A.
; Returned with received data byte in A.

	mov r7, #8 	; bit counter
spi_it_loop:
	mov c,MISO 	; input bit
	rlc a 		; move bit into CY
	mov MOSI,c 	; output bit
;
; add delay here with time at least 8 clocks of <u>slave device</u> crystal period
;
	setb SCK 	; raise clock
;
; add delay here with time at least 8 clocks of slave device crystal period
;
	clr SCK 	; drop clock
	djnz r7,spi_it_loop ; next bit
	ret