;---------------------------------------------------------------------------
; egy kis semmiseg 2x16-os LCD modulra karaktert kiirni 4x4-es keymatrixrol
;---------------------------------------------------------------------------
;
	list 	p=16f877a
	ERRORLEVEL-302
	#include	<p16f877a.inc>
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _LVP_OFF
		org	0x00
;
;---------------------------------------------------------------------------
;	PORB =>	4X4 KEYMATRIX:				PORTC => 2X16 caracters LCD modul
;		RB0	<=>	"M" (horizontal)			RC0 <= no connection
;		RB1	<=>	"L" (horizontal)			RC1 <= no connection
;		RB2	<=>	"K" (horizontal)			RC2 => "RS" (register select)
;		RB3	<=>	"J" (horizontal)			RC3 => "E"  (register select)
;		RB4	<=>	"E" (vertical)				RC4 => "D4"
;		RB5	<=>	"F" (vertical)				RC5 => "D4"
;		RB6	<=>	"G" (vertical)				RC6 => "D4"
;		RB7	<=>	"H" (vertical)				RC7 => "D4"
;---------------------------------------------------------------------------
;
;datacourse				
    bsf     STATUS,RP0      ;bank 1
    bcf     STATUS,RP1
	movlw b'00000110'
	movwf ADCON1			;E port digitalisa' konfiguralasa
;	movlw	b'11111111'
;	movwf	TRISA		
	movlw	b'11110000'
	movwf	TRISB
	movlw	b'00000011'
	movwf	TRISC
;	movlw	b'00000000'
;	movwf	TRISD
;	movlw	b'00000000'
;	movwf	TRISE
	bcf		OPTION_REG,7	;RBPU bittel felhuzoellenallas be
	bcf     STATUS,RP0      ;bank 0
;
;	regiszterek
cblock	0x20
timer1
timer2
temp1
temp2
	endc
MAIN
	clrf	PORTC
	clrf	PORTC
	clrf	timer1
	clrf	timer2
	clrf	temp1
	clrf	temp2	
	movlw	b'00101000'
	movwf	temp1		;2x4 bitbe rakja
	call	LCDOUTI
	movlw	b'00001111'
	movwf	temp1
	call	LCDOUTI
	movlw	b'00000001'
	movwf	temp1
	call	LCDOUTI	
	movlw	'K'
	movwf	temp1
	call	LCDOUTC
	movlw	'o'
	movwf	temp1
	call	LCDOUTC
	movlw	's'
	movwf	temp1
	call	LCDOUTC
	movlw	'z'
	movwf	temp1
	call	LCDOUTC
	movlw	b'00100000'
	movwf	temp1
	call	LCDOUTC
	movlw	'a'
	movwf	temp1
	call	LCDOUTC
	movlw	b'00100000'
	movwf	temp1
	call	LCDOUTC
	movlw	'p'
	movwf	temp1
	call	LCDOUTC
	movlw	'o'
	movwf	temp1
	call	LCDOUTC
	movlw	'n'
	movwf	temp1
	call	LCDOUTC
	movlw	't'
	movwf	temp1
	call	LCDOUTC
	movlw	'o'
	movwf	temp1
	call	LCDOUTC
	movlw	't'
	movwf	temp1
	call	LCDOUTC
	movlw	'!'
	movwf	temp1
	call	LCDOUTC
VEGE
	goto 	VEGE
LCDOUTC
	bsf		PORTC,3	;E
	bsf		PORTC,2	;RS
	movf	temp1,0
	movwf	temp2
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bsf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T1
	bcf		PORTC,3
	call	T1
	bsf		PORTC,3	;E
	bsf		PORTC,2	;RS
	movf	temp1,0
	movwf	temp2
	swapf	temp2,1
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bsf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T1
	bcf		PORTC,3
	call	T1
	bsf		PORTC,3		
	return
;
LCDOUTI
	bsf		PORTC,3	;E
	bcf		PORTC,2	;RS
	movf	temp1,0
	movwf	temp2
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bcf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T1
	bcf		PORTC,3
	call	T1
	bsf		PORTC,3	;E
	bcf		PORTC,2	;RS
	movf	temp1,0
	movwf	temp2
	swapf	temp2,1
	movlw	b'11110000'
	andwf	temp2,1
	bsf		temp2,3
	bcf		temp2,2
	movf	temp2,0
	movwf	PORTC
	call	T1
	bcf		PORTC,3
	call	T1
	bsf		PORTC,3		
	return
;
T1
	movlw	d'20'	; dec.7-8 ~1,7mS
	movwf	timer1
REV1
	decfsz	timer1,1
	goto 	T1A
	return
T1A
	movlw	d'255'	; dec.255 ~255uS
	movwf	timer2
REV2
	nop
	nop
	nop
	nop
	decfsz	timer2,1
	goto	REV2
	goto	REV1
	end
