INI_LCD	
	movlw	D'100'		;100 ms 
	movwf	LOOP
	call	WAIT

	movlw	B'00000011'	;1
	movwf	PORTB
	bsf	E
	nop
	bcf	E
	
	movlw	D'10'		;10 ms 
	movwf	LOOP
	call	WAIT
	
	movlw	B'00000011'	;2
	call	Control8Bit
	movlw	B'00000011'	;3
	call 	Control8Bit
	movlw	B'00000010'	;4
	call 	Control8Bit

	movlw	B'00000001'	;cusor home
	call	OutLcdControl
	movlw	B'00101000'	;5 function set, 4-bit  2-dky,  5x7
	call	OutLcdControl
	movlw	B'00001000'	;6 display off
	call	OutLcdControl
	movlw	B'00000110'	;7 entry mode, increment, disable display-shift
	call	OutLcdControl
	movlw	B'00000011'	;8 cursor home, 
	call	OutLcdControl
	movlw	B'00001100'	;9 display on, cursor off, cursor flash off
	call	OutLcdControl
	return

Control8Bit
	movwf	PORTB
	bsf	E
	nop
	bcf	E
	movlw	D'10'
	movwf	LOOP
	call 	WAIT
	return

OutLcdControl ;prkaz
	movwf	STORE
	movlw	D'10'
	movwf	LOOP
	call 	WAIT
	swapf	STORE, w
	andlw	H'0F'
	movwf	PORTB	  	;zpis hornho niebelu	
	bsf	E
	nop
	bcf	E	 	;Disable LcdBus
	movf	STORE, w
	andlw	H'0F'
	movwf	PORTB		;zpis dolnho niebelu
	bsf	E
	nop
	bcf	E		;Disable LcdBus
	return	

WRDATA	;dta
	movwf	STORE
	movlw	D'10'
	movwf	LOOP
	call 	WAIT
	swapf	STORE, w
	andlw	H'0F'
	movwf	PORTB
	bsf	RS
	bsf	E		;Enable LcdBus
	nop
	bcf	E		;Disable LcdBus	
	movf	STORE, w
	andlw	H'0F'
	movwf	PORTB
	bsf	RS
	bsf	E
	nop
	bcf	E		;Disable LcdBus	
	bcf	RS		;
	return
		

WAIT
top     movlw   .100           ; timing adjustment variable (1ms)
        movwf   LOOPA
top2    nop                    ; sit and wait
        nop
        nop
        nop
		nop
        nop
        nop
        decfsz  LOOPA, F      ; inner loops complete?
        goto    top2           ; no, go again
                               ;
        decfsz  LOOP, F       ; outer loops complete?
        goto    top            ; no, go again
        retlw   0              ; yes, return from subWAIT
