cs_pin		bit	P1.0
clk_pin		bit	P1.1
sdi_pin		bit	P1.2

temp		equ	20h

		org	0000h
;========================================================================
vfd_init:	
		setb	cs_pin			; STB_HI;
		call	delay200ms		; _delay_ms(200)

		;Set number of Grid output used
		clr	cs_pin			; STB_LO:
		call	delay_tcsh		; delay_tcsh
		mov	temp, #11100000B	; 
		call	data_shout		; 
		mov	temp, #15		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		setb	cs_pin			; STB_HI;			;
		call	delay_tcsh		; delay_tcsh

		;Set dim level
		clr	cs_pin			; STB_LO:
		call	delay_tcsh		; delay_tcsh
		mov	temp, #11100100B	; 
		call	data_shout		; 
		mov	temp, #128		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		setb	cs_pin			; STB_HI;			;
		call	delay_tcsh		; delay_tcsh

		;Display ON
		clr	cs_pin			; STB_LO:
		call	delay_tcsh		; delay_tcsh
		mov	temp, #11101000B	; 
		call	data_shout		; 
		mov	temp, #0		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		setb	cs_pin			; STB_HI;			;
		call	delay_tcsh		; delay_tcsh

		;Set pos
		clr	cs_pin			; STB_LO:
		call	delay_tcsh		; delay_tcsh
		mov	temp, #20h	; 
		call	data_shout		; 
		
		mov	temp, #'T'		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		
		mov	temp, #'E'		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		
		mov	temp, #'S'		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		
		mov	temp, #'T'		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		
		setb	cs_pin			; STB_HI;			;
		call	delay_tcsh		; delay_tcsh

		;Display ON
		clr	cs_pin			; STB_LO:
		call	delay_tcsh		; delay_tcsh
		mov	temp, #11101000B	; 
		call	data_shout		; 
		mov	temp, #0		; 
		call	data_shout		; 
		call	delay_tcsh		; delay_tcsh
		nop
		setb	cs_pin			; STB_HI;			;
		call	delay_tcsh		; delay_tcsh
		

		orl	PCON, #001h		; Good night sweet prince
		jmp	$			; if insomnia

;========================================================================
data_shout:	
		mov	A, temp			; data to p
		mov	R6, #008h		; loop counter
shloop:		
		nop
		clr	clk_pin 		 ; clk (P1.1) low
		rrc	A			; 1 pos shift A right
		mov	sdi_pin, C		; Carry flag to data out
		nop
		setb	clk_pin			; clk (P1.1) high
		djnz	R6, shloop		; Decrement counter and jump back
		ret				; exit subroutine
		
;========================================================================
delay_tcsh:	nop				; 16uS@4.000 mhz
		ret
		
;========================================================================
delay200ms:	mov 	030h, #082h		; 200ms@4.000 mhz
		mov	031h, #0ABh
next:		djnz	031h, $
		djnz	030h, next
		ret

		end