		list	p=16f877
		#include <p16f877.inc>		  ; processor specific variable definitions
;PORTB0 - LCD_D7
;PORTB1 - LCD_D6
;PORTB2 - LCD_D5
;PORTB3 - LCD_D4

;PORTB4 - LCD_E
;PORTB5 - LCD_CD

	cblock	0x020
CIM:		2
Index
temp
temp1
	endc

	cblock	0x070
W_SAVE
STATUS_SAVE
PCLATH_SAVE
	endc

	org	0x0
	goto	Kiir

	org	0x04
Interrupt:
	movwf	W_SAVE
	movf	STATUS,w
	movwf	STATUS_SAVE
	movf	PCLATH,w
	movwf	PCLATH_SAVE

;.....

	movf	PCLATH_SAVE,w
	movwf	PCLATH
	movf	STATUS_SAVE,w
	movwf	STATUS
	swapf	W_SAVE,f
	swapf	W_SAVE,w
	retfie


Init:

;.....



Kiir:
    movlw	high(Szoveg2)
	movwf	CIM+1
	movlw	low(Szoveg2)
	movwf	CIM
	call	SzovegToLcd
     
SzovegToLcd:
	clrf	Index
Loop:
	call	GetNextChar
	movwf	temp
	movlw	high(Loop)
	movwf	PCLATH
	movf	temp,w			; 0x00 kódú karakter a végjel
	btfsc	STATUS,Z  		; vége
	return
	call	CharToLcd
	incf	Index,f
	goto	Loop
     
GetNextChar:
	movf	CIM+1,w
	movwf	PCLATH
	movf	CIM,w
	addwf	Index,w
	btfsc	STATUS,C	; Laphatár ellenőrzése
	incf	PCLATH,f
	movwf	PCL			; Nem kell return, hiszen a szövegelemek retlw utasítások

PrepareToLcd:			; Cy		temp		temp1
	clrf	temp1		; x			HGFEDCBA	00000000
	bsf		temp1,3		; x			HGFEDCBA	00001000
P_loop:					; Loop #0							  Loop #1							  Loop #2							  Loop #3
	rrf		temp,f		; A			xHGFEDCB	00001000	; B			0xHGFEDC	0001000A	; C			00xHGFED	001000AB	; D			000xHGFE	01000ABC
	rlf		temp1,f		; 0			xHGFEDCB	0001000A	; 0			0xHGFEDC	001000AB	; 0			00xHGFED	01000ABC	; 0			000xHGFE	1000ABCD
	btfss	temp1,7
	goto	P_loop
	movf	temp1,w
	return

CharToLcd:
	movwf	temp
	swapf	temp,f
	call	PrepareToLcd
	xorwf	PORTB,w
	andlw	0x0F
	xorwf	PORTB,f
	call	Enable
	call	PrepareToLcd
	xorwf	PORTB,w
	andlw	0x0F
	xorwf	PORTB,f

Enable:
	bsf		PORTB,4
	nop
	nop
	bcf		PORTB,4
	return

	org 0x1800

Szoveg1:  DT "Szoveg1",0
Szoveg2:  DT "Szoveg 2",0
Szoveg3:  DT "Valami más",0
Szoveg4:  DT "Stb",0
	end

