; Fűtésautomatika < PIC16F628A -val 2x 16 digites LCD-re
;      OSC 4MHz -> 1us per cycle
;
;		PORTA0	<17>	Nyomógomb (föl - Yes)
;		PORTA1	<18>	Nyomógomb (le - No)	<ANAL˘G BEMENET>
;		PORTA2	<1>	Nyomógomb (jobbra)	<ANAL˘G BEMENET><fesz.referencia kimenet>
;		PORTA3	<2>	Nyomógomb (balra)
;		PORTA4	<3>	1 vonalas BUS --> DS1820
;		PORTA5	<4>	Nyomógomb - RESET/MCLR
;		PORTA6	<15>	Oszcill˙tor <CLKOUT>
;		PORTA7	<16>	Oszcill˙tor <CLKIN>
;		PORTB0	<6>	 			RB0/INT
;		PORTB1	<7>	Fűtés kimenet
;		PORTB2	<8>	LCD Enable
;		PORTB3	<9>	LCD RS
;		PORTB4	<10>	LCD DB4
;		PORTB5	<11>	LCD DB5
;		PORTB6	<12>	LCD DB6
;		PORTB7	<13>	LCD DB7

	list      p=16f628            ; list directive to define processor
	include <p16f628a.inc>        ; processor specific variable definitions
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _XT_OSC & _MCLRE_ON & _LVP_OFF



LCD_LINE0       EQU     0x80	;0x00            LCD Line Address
LCD_LINE1       EQU     0xC0	;0x40            LCD Line Address
	;LCD-hez
LCDEnable	EQU	2
LCDRS		EQU	3
LCDByte		EQU	0x20
HiByte		EQU	0x21
LoByte		EQU	0x22
LCDTar		EQU	0x23
LCDVez		EQU	0x24
LCDAdd		EQU	0x25
RSbit		EQU	0x26
Gomb_T		EQU	0x27
B_hom		EQU	0x28
K_hom		EQU	0x29
elv_hom		EQU	0x2A
negyed		EQU	0x2F
	;várakozáshoz
d1		EQU	0x2B
d2		EQU	0x2C
d3		EQU	0x2D
d4		EQU	0x2E
;
LCD_TEMP        EQU     0x30           ; lcd subroutines internal use
LCD_DELAY       EQU     0x31           ; Used in DELAYxxx routines
LCD_X_DELAY     EQU     0x32           ; Used in X_DELAYxxx routines
LCD_ASCHEXLO    EQU     0x33           ; lo ascii hex from lcdaschex routine
LCD_ASCHEXHI    EQU     0x34           ; hi ascii hex from lcdaschex routine
LCD_ASCHALF     EQU     0x35           ; 5 or 0 for half Celsius Degrees
LCD_ASCSIGN     EQU     0x36           ; sign, 0 -> '+' 255 '-' else ' '
LCD_ACTDS       EQU     0x37           ; 0->one (no rom), 1->first,2->second
; 
;
; DS 1820 variables
;
DS_BIT          EQU     4              ; porta4 is connected to the ds1820 bus
DS_RWTMP0       EQU     0x40
DS_RWTMP1       EQU     0x41
DS_DLYTMP       EQU     0x42
DS_TMP0         EQU     0x43
DS_TMP1         EQU     0x44
; area for tmp min and max variables
DS_MINTMP       EQU     0x45
DS_MAXTMP       EQU     0x46
DS_SIGNMINTMP   EQU     0x47
DS_SIGNMAXTMP   EQU     0x48
; ds1820 rom
DS_ROM0         EQU     0x50           ; ds1820 1 byte rom family code
DS_ROM1         EQU     0x51           ; ds1820 6 byte rom serial number
DS_ROM2         EQU     0x52           
DS_ROM3         EQU     0x53           
DS_ROM4         EQU     0x54
DS_ROM5         EQU     0x55
DS_ROM6         EQU     0x56
DS_ROM7         EQU     0x57           ; ds1820 1 byte rom crc code
; area for min and max variables
DS_MIN0         EQU     0x58
DS_MAX0         EQU     0x59
DS_SIGNMIN0     EQU     0x5a
DS_SIGNMAX0     EQU     0x5b
DS_MIN1         EQU     0x5c
DS_MAX1         EQU     0x5d
DS_SIGNMIN1     EQU     0x5e
DS_SIGNMAX1     EQU     0x5f
; ds1820 ram
DS_RAM0         EQU     0x60           ; ds1820 ram temperature lsb (temp)
DS_RAM1         EQU     0x61           ; ds1820 ram temperature msb (sign)
DS_RAM2         EQU     0x62           ; ds1820 ram TH user1
DS_RAM3         EQU     0x63           ; ds1820 ram TL user2
DS_RAM4         EQU     0x64           ; ds1820 ram reserved
DS_RAM5         EQU     0x65           ; ds1820 ram reserved
DS_RAM6         EQU     0x66           ; ds1820 ram count remain
DS_RAM7         EQU     0x67           ; ds1820 ram count per celsius
DS_RAM8         EQU     0x68           ; ds1820 ram crc
;
; CONVERSION Variables
;
NumH            EQU     0x6B
NumL            EQU     0x6C
Hund            EQU     0x6D
Tens            EQU     0x6E
Ones            EQU     0x6F



	;matekhez
REGA0		EQU	0x33	;lsb
REGA1		EQU	0x32
REGA2		EQU	0x31
REGA3		EQU	0x30	;msb	dec.'127' f”l”tt a sz m negativ!

REGB0		EQU	0x37	;lsb
REGB1		EQU	0x36
REGB2		EQU	0x35
REGB3		EQU	0x34	;msb	dec.'127' f”l”tt a sz m negativ!

REGC0		EQU	0x3B	;lsb
REGC1		EQU	0x3A
REGC2		EQU	0x39
REGC3		EQU	0x38	;msb	dec.'127' f”l”tt a sz m negativ!

DSIGN		EQU	0x50	;Digit Sign. 0=positive,1=negative
DIGIT1		EQU	0x51	;MSD
DIGIT2		EQU	0x52
DIGIT3		EQU	0x53
DIGIT4		EQU	0x54
DIGIT5		EQU	0x55	;Decimal (BCD) digits
DIGIT6		EQU	0x56
DIGIT7		EQU	0x57
DIGIT8		EQU	0x58
DIGIT9		EQU	0x59
DIGIT10		EQU	0x5A	;LSB
DIGIT11		EQU	0x5B
DIGIT12		EQU	0x5C
DIGIT13		EQU	0x5D
DIGIT14		EQU	0x5E
DIGIT15		EQU	0x5F



DIGIT20		EQU	0x60	;Digit Sign. 0=positive,1=negative
DIGIT21		EQU	0x61	;MSD
DIGIT22		EQU	0x62
DIGIT23		EQU	0x63
DIGIT24		EQU	0x64
DIGIT25		EQU	0x65	;Decimal (BCD) digits
DIGIT26		EQU	0x66
DIGIT27		EQU	0x67
DIGIT28		EQU	0x68
DIGIT29		EQU	0x69
DIGIT30		EQU	0x6A	;LSB
DIGIT31		EQU	0x6B
DIGIT32		EQU	0x6C
DIGIT33		EQU	0x6D
DIGIT34		EQU	0x6E
DIGIT35		EQU	0x6F

MTEMP		EQU	0x3E
MCOUNT		EQU	0x3D
DCOUNT		EQU	0x3C


Konst1H		EQU	0x44	;konstans L
Konst1M		EQU	0x45	;konstans M
Konst1L		EQU	0x46	;konstans H


	;kijelzőszámlálók
KSZ		EQU	0x4A	;Karaktersz.
DSZ		EQU	0x4B	;Digitsz.
PSZ		EQU	0x4C	;Poziciósz.

FSR		EQU	0x04	;pointer to digits
ind		EQU	0x0	;dec. tólcsordulás

	;tárolt számok
T1H		EQU	0x70
p_nap		EQU	0x71
p_ora		EQU	0x72
p_perc	EQU	0x73
p_hom		EQU	0x74
p_sz		EQU	0x75
p_1		EQU	0x76
p_2		EQU	0x77
p_3		EQU	0x78


	; órához
Tcs		EQU	0x79	; túlcsordulás számláló
sec		EQU	0x7A	; másodpercek
perc		EQU	0x7B	; percek
ora		EQU	0x7C	; órák
nap		EQU	0x7D	; napok

	;EEPROM cimzéshez:
EEADAT		EQU	0x3E
EECIM			EQU	0x3F
	;megszakitáshoz:
w_temp        	EQU     0x7F	; variable used for context saving 
status_temp   	EQU     0x7E	;variable used for context saving



	org	0x0000
	GOTO	Indul

	ORG     0x004		; interrupt vector location
	BTFSC	INTCON,INTF	;PORT B0 okozta a megszakit st
	GOTO	RBINT
	btfsc	PIR1,TMR1IF	;TMR1 okozta a megszakit st
	goto	TMRINT
	retfie

TMRINT:
	movwf	w_temp
	movf	STATUS,w	; move status register into W register
	movwf	status_temp	; save off contents of STATUS register

	call	v1
	goto	Ki
;ido:	call	SEC1
;
;;	call	n1	;csak pr˘b hoz!!!!!!!!!
;
;	goto	ido

;SEC1:	btfss	TMR1H,7
;	return
;	bcf	TMR1H,7
;	goto	v1
;v0:	movlw	0xE0		; b'1110 0000'
;	addwf	TMR1H,f
;	return

v1:
	bcf	TMR1L,3
	bsf	TMR1L,4
	bsf	TMR1L,5
	bsf	TMR1L,6
	bsf	TMR1L,7
	bsf	TMR1H,0
	bsf	TMR1H,1		; órakorrekció
	bsf	TMR1H,3

	incf	Tcs,f
	movlw	d'16'		;d'16'-al a szimulátoron jó
	subwf	Tcs,w
	btfss	STATUS,Z
	return
	movlw	0x0
	movwf	Tcs


s1:	incf	sec,f
	movlw	d'60'
	subwf	sec,w
	btfss	STATUS,Z
	return

p1:	incf	perc,f
	movlw	0x0
	movwf	sec
	movlw	d'60'
	subwf	perc,w
	btfss	STATUS,Z
	return

o1:	incf	ora,f
	movlw	0x0
	movwf	perc
	movlw	d'24'
	subwf	ora,w
	btfss	STATUS,Z
	return

n1:	incf	nap,f
	movlw	0x0
	movwf	ora
	movlw	d'8'
	subwf	nap,w
	btfss	STATUS,Z
	return
	movlw	0x1
	movwf	nap
	return

RBINT:
;	movwf	w_temp
;	movf	STATUS,w	; move status register into W register
;	movwf	status_temp	; save off contents of STATUS register
;	BCF	T1CON,0		;TIMER1	le˙llit˙sa
;	movlw	0x0
;	movwf	TMR1L
;	movwf	TMR1H
;	movwf	Tcs
;	incfsz	BeSzL,f
;	goto	Ki
;	incf	BeSzH,f

Ki:	movf    status_temp,w	; retrieve copy of STATUS register
	movwf	STATUS		; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w	; restore pre-isr W register contents
	BSF	T1CON,0		;TIMER1 indul, vagy mehet tov˙bb
	BCF	PIR1,TMR1IF	;jelz<bit t”rl‚se -- HA Timer1 ........
	BCF	INTCON,INTF	;	-- HA RB0 okozta a megszakit st
	retfie			; return from interrupt

Indul:
;	call	lcdprintdsdata
;	movf	NumL,w
;	movwf	B_hom

 clrf    STATUS
 clrf    INTCON
 clrf    PCLATH
 clrf    PORTA
 clrf    PORTB
 bsf     STATUS, RP0
 movlw   b'11101111'
 movwf   TRISA
 movlw   0x1		;port b1 - fűtéskimenet
 movwf   TRISB		;  b2-b7 - LCD vez.
 bsf     OPTION_REG, NOT_RBPU

	bsf	OPTION_REG,PSA       ; enable watchdog
	bsf	OPTION_REG,PS0       ; set prescaler to 1:128 = 2.3 seconds
	bsf	OPTION_REG,PS1
	bsf	OPTION_REG,PS2
	bcf	OPTION_REG,T0CS
 bcf     STATUS, RP0
	movlw	b'00000111'
	movwf	CMCON
 
	BCF	STATUS,IRP	;Bank 0,1
	BSF	STATUS,RP0	;Bank1
	bsf	PIE1,TMR1IE
	BCF	STATUS,RP0	;Bank0
	BSF	INTCON,PEIE
	BSF	INTCON,GIE	; TMR1 megszakit s enged‚lyezve

;	bsf	TMR1H,7
;	bsf	TMR1H,6		;TMR1 innen inditand˘ qvarc 32762Hz!
;	bsf	TMR1H,5

	bsf	T1CON,0		; TMR1 indul


	call    LCDINIT
	call    lcdclear
	goto	Indul1


;
Tabla1:
	addwf   PCL,f           ; Jump to character
	dt	"Orabeállitás?   "
Tabla1_End:
	retlw   0

; Check to ensure table doesn't cross a page boundary.
	if ( (Tabla1 & 0x0FF) >= (Tabla1_End & 0x0FF) )
       MESSG   "Warning - User Definded: Table crosses page boundry in computed jump"
    endif
;
;
Tabla2:
	addwf   PCL,f           ; Jump to character
	dt	"Programozás?    "
Tabla2_End:
	retlw   0
;
; Check to ensure table doesn't cross a page boundary.
	if ( (Tabla2 & 0x0FF) >= (Tabla2_End & 0x0FF) )
       MESSG   "Warning - User Definded: Table crosses page boundry in computed jump"
    endif
;
;
Tabla3:
	addwf   PCL,f           ; Jump to character
	dt	"Futes mehet?    "
Tabla3_End:
	retlw   0
;
; Check to ensure table doesn't cross a page boundary.
	if ( (Tabla3 & 0x0FF) >= (Tabla3_End & 0x0FF) )
       MESSG   "Warning - User Definded: Table crosses page boundry in computed jump"
    endif
;


Indul1:
	movlw	d'20'		;kezdő hömérséklet, amig nincs átirva
	movwf	elv_hom	;programból, vagy gomról

	movlw	0x6	;ha a "nap" nincs 1-7 között
	movwf	PSZ	;órát nullázni kell!
	movf	nap,w
	movwf	DSZ
	decf	DSZ,f
Nap_ell:
	decfsz	DSZ,f
	btfsc	STATUS,Z
	goto	Jo
	goto	To	
To:	decfsz	PSZ,f
	goto	Nap_ell
			;óra alapra !
	movlw	0
	movwf	Tcs
	movwf	sec
	movwf	perc
	movwf	ora	
	movwf	TMR1H
	movwf	TMR1L
	movlw	b'00001011'	;stopper ~előbeállitás
	addwf	TMR1H,f
	movlw	0x7	;1-hétfő.....7-vasárnap
	movwf	nap

Jo:
	call	LONGDLY_100
	call	ORA_KI



ujra:	call	LCDLINE1
	movlw   0               ; Table address of start of message
Orabe_:	movwf   T1H           ; Temp1 holds start of message address
	call    Tabla1
	andlw   0FFh            
	btfsc   STATUS,Z        ; Check if at end of message (zero returned at end)
	goto    Valasz1           
	call    LCDBYTE       ; Display character
	movf    T1H,w         ; Point to next character
	addlw   1
	goto    Orabe_
Valasz1:
	call	Gombok
	btfsc	Gomb_T,0	;"föl/igen"
	goto	nap_be
;	call	Gombok
	btfss	Gomb_T,1	;"le/nem"
	goto	Valasz1

	call	LCDLINE1
	movlw   0
Prog_:	movwf   T1H
	call    Tabla2
	andlw   0FFh
	btfsc   STATUS,Z
	goto    Valasz2
	call    LCDBYTE
	movf    T1H,w
	addlw   1
	goto    Prog_
Valasz2:
	call	Gombok
	btfsc	Gomb_T,0	;"föl/igen"
	goto	F_prog
;	call	Gombok
	btfss	Gomb_T,1	;"le/nem"
	goto	Valasz2

	call	LCDLINE1
	movlw   0
Futes_:	movwf   T1H
	call    Tabla3
	andlw   0FFh
	btfsc   STATUS,Z
	goto    Valasz3
	call    LCDBYTE
	movf    T1H,w
	addlw   1
	goto    Futes_
Valasz3:
	call	Gombok
	btfsc	Gomb_T,0	;"föl/igen"
	goto	Futes
;	call	Gombok
	btfss	Gomb_T,1	;"le/nem"
	goto	Valasz3

	goto	ujra

Futes:	
	call	ORA_KI
	call	LONGDLY_500
	call	Hőmérés		;ds1,ds2 mér; ds1 küldi
	call	LONGDLY_500
	call	ORA_KI
	call	LONGDLY_500
	call	ORA_KI
	call	LONGDLY_500
	call	DS2mér		;ds2 küldi
	call	ORA_KI
	call	LONGDLY_500
	call	ORA_KI
	call	LONGDLY_500
;   elvárt hőmérléklet módositás
Hom_mod:	
	btfss	PORTA,0		;"föl"
	incf	elv_hom,f
	btfss	PORTA,1		;"le"
	decf	elv_hom,f
	movlw	d'28'
	subwf	elv_hom,w
	btfsc	STATUS,C	;ha elv_hom > 27 - e27
	goto	e27
	movlw	d'5'
	subwf	elv_hom,w
	btfss	STATUS,C	;ha elv_hom < 5 - e0
	goto	e0
	goto	e1
e27:	movlw	d'21'
	movwf	elv_hom
	goto	e1
e0:	movlw	d'15'
	movwf	elv_hom
e1:	call	Elv_hom_K
	call	ORA_KI
	call	LONGDLY_500
	call	ORA_KI
	call	LONGDLY_500
	movf	elv_hom,w
	subwf	B_hom,w
	btfsc	STATUS,C
	goto	Futes_Be
	goto	Futes_Ki

Futes_Be:
	bcf	PORTB,1
	goto	Negyed_o
Futes_Ki:
	bsf	PORTB,1
	goto	Negyed_o

;  aktuális programozott hőmérséklet beirás negyedóránként
Negyed_o:
	movlw	d'0'
	subwf	perc,w
	btfsc	STATUS,Z
	goto	Futes_K
	movlw	d'15'
	subwf	perc,w
	btfsc	STATUS,Z
	goto	Futes_K
	movlw	d'30'
	subwf	perc,w
	btfsc	STATUS,Z
	goto	Futes_K
	movlw	d'45'
	subwf	perc,w
	btfsc	STATUS,Z
	goto	Futes_K
	movlw	0x0
	movwf	negyed

	goto	Futes

Futes_K:
	btfsc	negyed,0	;negyedkor csak 1x legyen
	goto	Futes		;hőmérséklet átirás ???
	bsf	negyed,0


negyed_o:
	MOVF	nap,w
	MOVWF	p_nap
	movlw	0x5
	movwf	p_sz
negyed_1:
	call	P_olv

p2perc:				;p_perc -- valos alakra p_2-be
	movlw	0x0
	movwf	p_2
	movf	p_perc,w	;módositott p_perc LCD-re
	movwf	p_3
P2ki:
	rrf	p_3,f
	btfss	STATUS,C
	goto	P2ki1
	movf	p_2,w
	addlw	d'30'
	movwf	p_2
P2ki1:
	rrf	p_3,f
	btfss	STATUS,C
	goto	Hasonlit
	movf	p_2,w
	addlw	d'15'
	movwf	p_2	;p_2 -ben a p_perc-nek megfelelő perc

Hasonlit:
	movf	ora,w
	subwf	p_ora,w
	btfss	STATUS,Z
	goto	negyed_5
	goto	negyed_2	;p_ora = ora
negyed_2:
	movf	perc,w
	subwf	p_2,w
	btfss	STATUS,Z
	goto	negyed_5
	goto	negyed_3	;"p_perc" = perc
negyed_3:
	movf	p_hom,w
	movwf	elv_hom
	goto	Futes
negyed_5:
	decfsz	p_sz,f
	goto	negyed_1
	goto	Futes





nap_be:		;nap,ÓRA,perc,másodperc beállitása
	call	lcdclear
	movlw	d'4'
	call	LCDPOZ
	movlw	'I'
	call	LCDBYTE

	call	ORA_KI
;	movf	nap,w
;	movwf	PSZ
;	decf	PSZ,f	;0-hétfő....6-vasárnap
;	movlw	0x6
;	movwf	DSZ	;0 és hat között lehet csak

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	nap,f
	btfsc	Gomb_T,1	;"le"
	decf	nap,f
	movlw	d'8'
	subwf	nap,w
	btfsc	STATUS,C	;ha nap > 7
	goto	n7
	movlw	d'1'
	subwf	nap,w
	btfss	STATUS,C	;ha nap < 1
	goto	n0
	goto	nap1
n7:	movlw	d'1'
	movwf	nap
	goto	nap1
n0:	movlw	d'7'
	movwf	nap
	goto	nap1
nap1:	btfss	Gomb_T,2	;"jobbra"
	goto	nap_be
	goto	Ora_beal

Ora_beal:		;óra állitás
	call	lcdclear
	movlw	d'9'
	call	LCDPOZ
	movlw	'I'
	call	LCDBYTE

	call	ORA_KI
;	movf	ora,w
;	movwf	PSZ
;	decf	PSZ,f	;0-23 óráig
;	movlw	d'23'
;	movwf	DSZ	;0 és 23 között lehet csak

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	ora,f
	btfsc	Gomb_T,1	;"le"
	decf	ora,f
	movlw	d'24'
	subwf	ora,w
	btfsc	STATUS,C	;ha óra > 23
	goto	o24
	movlw	d'0'
	subwf	ora,w
	btfss	STATUS,C	;ha óra < 0
	goto	o0
	goto	ora1
o24:	movlw	d'0'
	movwf	ora
	goto	ora1
o0:	movlw	d'23'
	movwf	ora
	goto	ora1
ora1:	btfsc	Gomb_T,2	;"jobbra"
	goto	perc_be
	btfsc	Gomb_T,3	;"balra"
	goto	nap_be
	goto	Ora_beal

perc_be:		;perc állitás
	call	lcdclear
	movlw	d'12'
	call	LCDPOZ
	movlw	'I'
	call	LCDBYTE

	call	ORA_KI
;	movf	perc,w
;	movwf	PSZ
;	decf	PSZ,f	;0-59 percig
;	movlw	d'59'
;	movwf	DSZ	;0 és 59 között lehet csak

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	perc,f
	btfsc	Gomb_T,1	;"le"
	decf	perc,f
	movlw	d'60'
	subwf	perc,w
	btfsc	STATUS,C	;ha perc > 59
	goto	p59
	movlw	d'0'
	subwf	perc,w
	btfss	STATUS,C	;ha perc < 0
	goto	p0
	goto	perc1
p59:	movlw	d'0'
	movwf	perc
	goto	perc1
p0:	movlw	d'59'
	movwf	perc
	goto	perc1
perc1:	btfsc	Gomb_T,2	;"jobbra"
	goto	sec_be
	btfsc	Gomb_T,3	;"balra"
	goto	Ora_beal
	goto	perc_be

sec_be:		;másodperc állitás
	call	lcdclear
	movlw	d'15'
	call	LCDPOZ
	movlw	'I'
	call	LCDBYTE

	call	ORA_KI
	movf	sec,w
	movwf	PSZ
	decf	PSZ,f	;0-59 sec-ig
	movlw	d'59'
	movwf	DSZ	;0 és 59 között lehet csak

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	sec,f
	btfsc	Gomb_T,1	;"le"
	decf	sec,f
	movlw	d'60'
	subwf	sec,w
	btfsc	STATUS,C	;ha sec > 59
	goto	s59
	movlw	d'0'
	subwf	sec,w
	btfss	STATUS,C	;ha sec < 0
	goto	s0
	goto	sec1
s59:	movlw	d'0'
	movwf	sec
	goto	sec1
s0:	movlw	d'59'
	movwf	sec
	goto	sec1
sec1:	btfsc	Gomb_T,2	;"jobbra"
	goto	ujra
	btfsc	Gomb_T,3	;"balra"
	goto	perc_be
	goto	sec_be


F_prog:
	call	lcdclear

	movf	nap,w		;próba P_olv -hoz
	movwf	p_nap		;EEPROM-ból 1 sor LCD-re
	movlw	0x1	;ha a p_sz csökkentjük
			; megbolondul!!!!
	movwf	p_sz		;p_sz (1-5) szerinti óra-perc(1/4óra)-hőmérséklet

g_olv:	call	P_olv 		;LCD-re

	movlw	0x4D	;2.sor 13. poz
	call	LCDPOZ
	movlw	'n'
	call	LCDBYTE
	movlw	'a'
	call	LCDBYTE
	movlw	'p'
	call	LCDBYTE

	call	Gombok
;				p_nap léptetése
	btfsc	Gomb_T,0	;"föl/igen"
	incf	p_nap,f
	btfsc	Gomb_T,1	;"le/nem"
	decf	p_nap,f
	movlw	d'8'
	subwf	p_nap,w
	btfsc	STATUS,C	;ha p_nap > 7 
	goto	olv7
	movlw	d'1'
	subwf	p_nap,w
	btfss	STATUS,C	;ha p_nap < 1 
	goto	olv0
	btfsc	Gomb_T,2	;"jobbra"
	goto	g_olv1
	goto	g_olv

olv7:	movlw	0x1
	movwf	p_nap
	goto	g_olv
olv0:	movlw	0x7
	movwf	p_nap
	goto	g_olv

g_olv1:			;p_sz léptetése
	call	P_olv

	movlw	0x4d	;2.sor 13. poz
	call	LCDPOZ
	movlw	'p'
	call	LCDBYTE
	movlw	'r'
	call	LCDBYTE

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	p_sz,f
	btfsc	Gomb_T,1	;"le"
	decf	p_sz,f
	movlw	d'6'
	subwf	p_sz,w
	btfsc	STATUS,C	;ha p_sz > 5 köv.napra
	goto	olv5
	movlw	d'1'
	subwf	p_sz,w
	btfss	STATUS,C	;ha p_sz < 1
	goto	olv1
	goto	g_olv1_1
olv5:	incf	p_nap,f
	movlw	0x1
	movwf	p_sz
	movlw	d'8'
	subwf	p_nap,w
	btfsc	STATUS,C	;ha p_nap > 7
	goto	olv6
	goto	g_olv1_1	
olv6:	movlw	0x1
	movwf	p_nap
	movlw	0x1
	movwf	p_sz
	goto	g_olv
olv1:	movlw	0x5
	movwf	p_sz
	goto	g_olv1_1

g_olv1_1:
	call	P_olv
	call	Gombok
	btfsc	Gomb_T,2	;"jobbra"
	goto	g_olv2
	btfsc	Gomb_T,3	;"balra"
	goto	g_olv
	goto	g_olv1

g_olv2:			;p_ora beállitása
	movlw	0x4D	;2.sor 13. poz
	call	LCDPOZ
	movlw	'o'
	call	LCDBYTE
	movlw	'r'
	call	LCDBYTE
	movlw	'a'
	call	LCDBYTE

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	p_ora,f
	btfsc	Gomb_T,1	;"le"
	decf	p_ora,f
	movlw	d'24'
	subwf	p_ora,w
	btfsc	STATUS,C	;ha ora > 23
	goto	po23
	movlw	d'0'
	subwf	p_ora,w
	btfss	STATUS,C	;ha ora < 0 vége
	goto	po0
	goto	pora1
po23:	movlw	d'0'
	movwf	p_ora
	goto	pora1
po0:	movlw	d'59'
	movwf	p_ora
	goto	pora1
pora1:
	movlw	0x40	;2.sor 1. poz
	call	LCDPOZ
	movf	p_ora,w		;módositott p_ora LCD-re
	movwf	NumL
	clrf	NumH
	call    bin2dec999
	movlw   0x30
	addwf   Tens,W
	call    LCDBYTE
	movlw   0x30
	addwf   Ones,W
	call    LCDBYTE

	btfsc	Gomb_T,2	;"jobbra"
	goto	g_olv3
	goto	g_olv2


g_olv3:			;p_perc beállitása
;	call	P_olv
	movlw	0x4D	;2.sor 13. poz
	call	LCDPOZ
	movlw	'm'
	call	LCDBYTE
	movlw	'i'
	call	LCDBYTE
	movlw	'n'
	call	LCDBYTE

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	p_perc,f
	btfsc	Gomb_T,1	;"le"
	decf	p_perc,f
	movlw	d'4'
	subwf	p_perc,w
	btfsc	STATUS,C	;ha p_perc > 3 (1-15, 2-30, 3-45 )
	goto	pp45
	movlw	d'0'
	subwf	p_perc,w
	btfss	STATUS,C	;ha perc < 0 vége
	goto	pp0
	goto	pperc1
pp45:	movlw	d'0'
	movwf	p_perc
	goto	pperc1
pp0:	movlw	d'3'
	movwf	p_perc
	goto	pperc1
pperc1:
	movlw	0x43	;2.sor 4. poz
	call	LCDPOZ
	movlw	0x0
	movwf	p_2
	movf	p_perc,w	;módositott p_perc LCD-re
	movwf	p_3
P_pki:
	rrf	p_3,f
	btfss	STATUS,C
	goto	P_pki1
	movf	p_2,w
	addlw	d'30'
	movwf	p_2
P_pki1:
	rrf	p_3,f
	btfss	STATUS,C
	goto	P_pki2
	movf	p_2,w
	addlw	d'15'
	movwf	p_2
P_pki2:
	movlw	0x0
	movwf	NumH
	movf	p_2,w
	movwf	NumL
	call	bin2dec999
	movf	Tens,w
	addlw	0x30
	call    LCDBYTE
	movf	Ones,w
	addlw	0x30
	call    LCDBYTE

;	call	Gombok
	btfsc	Gomb_T,2	;"jobbra"
	goto	g_olv4
	btfsc	Gomb_T,3	;"balra"
	goto	g_olv2
	goto	g_olv3


g_olv4:			;p_hom beállitása
;	call	P_olv

	movlw	0x4d	;2.sor 13. poz
	call	LCDPOZ
	movlw	'h'
	call	LCDBYTE
	movlw	'o'
	call	LCDBYTE
	movlw	'm'
	call	LCDBYTE

	call	Gombok
	btfsc	Gomb_T,0	;"föl"
	incf	p_hom,f
	btfsc	Gomb_T,1	;"le"
	decf	p_hom,f
	movlw	d'28'
	subwf	p_hom,w
	btfsc	STATUS,C	;ha p_hom > 27
	goto	h27
	movlw	d'5'
	subwf	p_hom,w
	btfss	STATUS,C	;ha p_hom < 5
	goto	h0
	goto	h1
h27:	movlw	d'18'
	movwf	p_hom
	goto	h1
h0:	movlw	d'18'
	movwf	p_hom
	goto	h1
h1:
	movlw	0x48	;2.sor 9. poz
	call	LCDPOZ
	movf	p_hom,w		;módositott p_hom LCD-re
	movwf	NumL
	clrf	NumH
	call    bin2dec999
	movlw   0x30
	addwf   Tens,W
	call    LCDBYTE
	movlw   0x30
	addwf   Ones,W
	call    LCDBYTE

;	call	Gombok
	btfsc	Gomb_T,2	;"jobbra"
	goto	eget1
	btfsc	Gomb_T,3	;"balra"
	goto	g_olv3
	goto	g_olv4
;
eget1:
	movlw	d'13'
	call	LCDPOZ
	movlw	'e'
	call	LCDBYTE
	movlw	d'14'
	call	LCDPOZ
	movlw	'e'
	call	LCDBYTE
	movlw	d'15'
	call	LCDPOZ
	movlw	'p'
	call	LCDBYTE

	call	P_ir	;EEPROM-ba irás p_nap és p_sz-től függően

	call	P_olv	;EEPROM-ból olvasás p_nap és p_sz-től függően

	GOTO	g_olv	;RESETtel ki!
;		vagy rákérdezni "KISZALJUNK?"
;		"Progr. vege?"




;	EEPROM-ba irás "p_nap" és "p_sz"-től függően (ora+perc és hömérséklet)
P_ir:	movlw	0x0	;induló EE cim
	movwf	p_1
	movf	p_nap,w
	movwf	p_2	;
p_ir0:
	decfsz	p_2,f
	goto	p_ir1
	goto	p_ir2

p_ir1:	movf	p_1,w
	addlw	d'18'
	movwf	p_1
	goto	p_ir0
p_ir2:	movf	p_1,w
	addlw	d'8'
	movwf	p_1	;p_1 a p_nap utáni EE cimre mutat

	movf	p_sz,w
	movwf	p_2
p_ir10:
	decfsz	p_2,f
	goto	p_ir11
	goto	p_ir12

p_ir11:	movf	p_1,w
	addlw	d'2'
	movwf	p_1
	goto	p_ir10
p_ir12:
;	movf	p_1,w
;	addlw	d'8'
;	movwf	p_1	
			;p_1 a p_nap és p_sz szerint EE cimre mutat
	

p_i_ora:
;	movlw	0x0
;	movwf	p_3
;	movf	p_perc,w
	rrf	p_perc,f
	rlf	p_ora,f
	rrf	p_perc,f
	rlf	p_ora,f

	movf	p_1,w
	movwf	EECIM
	movf	p_ora,w
	movwf	EEADAT
	call	EE_IR
	call	LONGDLY_100

p_i_hom:
	incf	p_1,f
	movf	p_1,w
	movwf	EECIM
	movf	p_hom,w
	movwf	EEADAT
	call	EE_IR
	call	LONGDLY_100
	return


;	EEPROM-ban levő adatkiolvasás "p_nap" és "p_sz"-től függően
P_olv:	movlw	0x0
	movwf	KSZ	;karakterszámláló
	movlw	0x50	;LCD 1.sor 1.kar mem. cime
	movwf	FSR	;LCDmemóriacim
	movlw	0x0
	movwf	p_1	;induló EEPROM cim
	movf	p_nap,w
	movwf	p_2
p_olv01:
	decfsz	p_2,f
	goto	p_olv02
	goto	p_olv1
p_olv02:
	movf	p_1,w	;köv. nap EEPROM cime d'18'-al késöbb
	addlw	0x12
	movwf	p_1
	goto	p_olv01

p_olv1:		;nap olvasása
	movf	p_1,w
	call	EE_OLV
	movwf	INDF	; W-> FSR által mutatott cimre
			;EEPROM p_1 cimen levő karakter  -cimen
	incf	FSR,F
	incf	p_1,f
	incf	KSZ,f
	movlw	0x8
	subwf	KSZ,w
	btfss	STATUS,Z
	goto	p_olv1
	goto	p_olv2
p_olv2:			;muutató "p_sz" LCD 1.sor 10. kar.
	movF	p_sz,W	;
	addlw	0x30	;LCD-re "p_sz"-t karakteres formában
	movwf	0x59	;****
	movlw	" "
	movwf	0x58
	movwf	0x5A
	movlw	"("
	movwf	0x5B
	movlw	"1"
	movwf	0x5C
	movlw	"-"
	movwf	0x5D
	movlw	"5"
	movwf	0x5E
	movlw	")"
	movwf	0x5F
		; 1.sor. kész
;	LCD 1. sorába "nap..1-5" egy szám a programozandó--
;
	call	Kiir1


; EEPROM-ban levő adatkiolvasás "P_NAP" és "p_sz"-től függően
;	(p_1 az adott nap utáni EEPROM cimre mutat)
O_ora:	movlw	0x0
	movwf	p_perc
	movf	p_sz,w
	movwf	p_2
	decf	p_2,f
	bcf	STATUS,C
	rlf	p_2,f	; x2
	movf	p_2,w
	addwf	p_1,f
	movf	p_1,w
	call	EE_OLV
	movwf	p_3
	rrf	p_3,f
	rlf	p_perc,f
	rrf	p_3,f
	rlf	p_perc,f	;1->15 perc, 2->30, 3->45
	movf	p_3,w
	movwf	p_ora

O_hom:	incfsz	p_1,f
	movf	p_1,w
	call	EE_OLV
	movwf	p_hom

;	LCD 2. sorába "óra-perc(1/4óra)-hőmérséklet"--hez
P_oraki:
	movlw	0x0
	movwf	NumH
	movf	p_ora,w
	movwf	NumL
	call	bin2dec999
	movf	Tens,w
	addlw	0x30
	movwf	0x60
	movf	Ones,w
	addlw	0x30
	movwf	0x61
	movlw	":"
	movwf	0x62	;óra az LCD memóriában

	movlw	0x0
	movwf	p_2

	movf	p_perc,w
	movwf	p_3
P_percki:
	rrf	p_3,f
	btfss	STATUS,C
	goto	P_percki1
	movf	p_2,w
	addlw	d'30'
	movwf	p_2
P_percki1:
	rrf	p_3,f
	btfss	STATUS,C
	goto	P_percki2
	movf	p_2,w
	addlw	d'15'
	movwf	p_2
P_percki2:
	movlw	0x0
	movwf	NumH
	movf	p_2,w
	movwf	NumL
	call	bin2dec999
	movf	Tens,w
	addlw	0x30
	movwf	0x63
	movf	Ones,w
	addlw	0x30
	movwf	0x64
P_homki:
	movlw	0x0
	movwf	NumH
	movf	p_hom,w
	movwf	NumL
	call	bin2dec999
	movf	Tens,w
	addlw	0x30
	movwf	0x68
	movf	Ones,w
	addlw	0x30
	movwf	0x69
	movlw	d'223'
	movwf	0x6A
	movlw	"C"
	movwf	0x6B

	movlw	0x20
	movwf	65
	movwf	66
	movwf	67
	movwf	6C
	movwf	6D
	movwf	6E
	movwf	6F
	call	Kiir2
	return	;vissza a programozásra





;	EEPROM olvasás (W-ben olvasandó cim--eredmény a W-ben)
EE_OLV:
	BCF	STATUS,RP0	;BANK 0
;	MOVF	EECIM,W		;EECIM(tartalma)-->W
;	MOVWF	EECIM		;W(tart.)-->regiszterbe
	BSF	STATUS,RP0	;BANK 1
	MOVWF	EEADR		;olvasási cim
;	BSF	STATUS,RP0	;BANK 1
	BSF	EECON1,RD	;EEPROM- olvasás
;	BCF	STATUS,RP0	;BANK 0
	MOVF	EEDATA,W
	BCF	STATUS,RP0	;BANK 0
	RETURN

;	EEPROM irás
EE_IR:
	call	INDIT		;óra nem állhat le!

	movf	EECIM,w
	BSF	STATUS,RP0	;BANK 1	
	movwf	EEADR
	BCF	STATUS,RP0	;BANK 0
	movf	EEADAT,w
	BSF	STATUS,RP0	;BANK 1
	MOVWF	EEDATA
	BSF	EECON1,WREN	;irás engedélyezés
	BCF	INTCON,GIE	;megszakitás tilt.
	MOVLW	0x55
	MOVWF	EECON2
	MOVLW	0xAA
	MOVWF	EECON2
	BSF	EECON1,WR	;irás bit beáll.
	BSF	INTCON,GIE
	BCF	STATUS,RP0	;BANK 0
	return










dswriterom0:		;forrasztottl bu
	movlw	0x10
	call	dswrite
	movlw	0x51
	call	dswrite
	movlw	0x48
	call	dswrite
	movlw	0x39
	call	dswrite
	movlw	0x01
	call	dswrite
	movlw	0x08
	call	dswrite
	movlw	0x00
	call	dswrite
	movlw	0x33
	call	dswrite
	return

dswriterom1:		;
	movlw	0x10
	call	dswrite
	movlw	0xB2
	call	dswrite
	movlw	0xAB
	call	dswrite
	movlw	0x15
	call	dswrite
	movlw	0x01
	call	dswrite
	movlw	0x08
	call	dswrite
	movlw	0x00
	call	dswrite
	movlw	0xB5
	call	dswrite
	return


dswriterom2:		;
	movlw	0x10
	call	dswrite
	movlw	0x39
	call	dswrite
	movlw	0x61
	call	dswrite
	movlw	0x15
	call	dswrite
	movlw	0x01
	call	dswrite
	movlw	0x08
	call	dswrite
	movlw	0x00
	call	dswrite
	movlw	0x38
	call	dswrite
	return

;
dssetlow macro
 bcf     PORTA,DS_BIT    ; dq bit ready lo
 bsf     STATUS,RP0
 bcf     TRISA,DS_BIT    ; dq bit now o/p
 bcf     STATUS,RP0
 endm
;
dssethigh macro
;	bsf     PORTA,DS_BIT    ; dq bit ready high
 bsf     STATUS,RP0
 bsf     TRISA,DS_BIT    ; dq bit now i/p
 bcf     STATUS,RP0
 endm
;
pause macro dlyf
 movlw   (dlyf / D'5') - D'1'
 movwf   DS_DLYTMP
 call    dly5n
 endm
;
dly5n  
 nop
 nop
 decfsz  DS_DLYTMP,F
 goto    dly5n
 return
;
INDIT:
;	btfsc	TMR1H,7
	btfsc	Tcs,3	;EEPROM irás csak akkor, ha
	goto	INDIT	; megszakitás elött befejezhető
	return
;
dsread 
	call	INDIT	;?kell ez?
 movlw   D'8'
 movwf   DS_RWTMP0
dsrxlp
 dssetlow
	nop
	nop
 dssethigh
 nop
 nop
 movf    PORTA,W
 andlw   1 << DS_BIT	;B'00010000'
 addlw   0xFF
 rrf     DS_RWTMP1,F	;rrf - eredeti!
 pause   D'70' 
 decfsz  DS_RWTMP0,F
 goto    dsrxlp
 movf    DS_RWTMP1,W
 return
;
dswrite
	call	INDIT
 movwf   DS_RWTMP1       ; data to tx
 movlw   D'8'
 movwf   DS_RWTMP0       ; loop counter
dstxlp
 dssetlow
	nop
	nop
	nop
 rrf     DS_RWTMP1,F	;rrf - eredeti
	bsf	STATUS,RP0	;Bank1
 btfsc   STATUS,C
	bsf	TRISA,DS_BIT
	bcf	STATUS,RP0	;Bank0
 pause   D'70'
 dssethigh
 nop
 nop
 decfsz  DS_RWTMP0,F
 goto    dstxlp
 return
;
dsreset
	call	INDIT
 dssethigh
 dssetlow
 pause   D'600'
 dssethigh
 pause   D'100'           ;wait 67us for response bit
 nop
 nop
 movf    PORTA,W
 andlw   1 << DS_BIT
 movwf   DS_TMP0         ;save w
 pause   D'400'
 movf    DS_TMP0,W       ;restore stored w for return value
 return

dsreadrom
 call    dsreset
 movlw   0x33                ; read rom command
 call    dswrite
 movlw   0x08                ; set counter to 8
 movwf   DS_TMP0
 movlw   DS_ROM0             ; indirect addressing
 movwf   FSR                 ; put first byte (DS_ROM0) into FSR
dsreadromloop
 call    dsread
 movwf   INDF                ; store read byte into INDF pointers target
;	call	LCDBYTE
 incf    FSR,F               ; increment FSR (now DS_ROM0 + n)
 decfsz  DS_TMP0,F
 goto dsreadromloop
 return
;

DS_FF:		;v rj mig FF-t‹l elt‚r‹ j”n
	call	dsread
	addlw	0x1
	btfsc	STATUS,Z
	goto	DS_FF
	return

DS_RAM_O:
	call	dsread
	movwf	DS_RAM0	;1. byte TL fogad sa
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM1	;2. byte TH fog.
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM2	;3. b jt fog.
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM3	;4. b jt fog.
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM4	;5. b jt fog.
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM5	;6. b jt fog.
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM6	;7. b jt fog.
;	addlw	0x30
;	call	LCDBYTE

	call	dsread
	movwf	DS_RAM7	;8. b jt fog.
;	addlw	0x30
;	call	LCDBYTE


	call	dsread
	movwf	DS_RAM7	;9. b jt fog. CRC?
;	addlw	0x30
;	call	LCDBYTE
;	movlw	' '
;	call	LCDBYTE
 	return









ROM_OLV:
	movlw	0x33	; ROM olv.
	call	dswrite
p00:
	movlw	b'10000100'
	call	LCDVEZ
 goto p01
	call	dsread
	movwf	DS_TMP0
	addlw	0x30
	call	LCDBYTE
	movf	DS_TMP0,w
	addlw	0x1
	btfsc	STATUS,Z	;v r mig csak "FF" olvashat˘
	goto	p00

;	movf	DS_TMP0,w
p01:	call	dsread
	movwf	DS_ROM0	;family kod fogad sa
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM1	;serial number 1. b jt fog.
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM2	;serial number 2. b jt fog.
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM3	;serial number 3. b jt fog.
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM4	;serial number 4. b jt fog.
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM5	;serial number 5. b jt fog.
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM6	;serial number 6. b jt fog.
	addlw	0x30
	call	LCDBYTE

	call	dsread
	movwf	DS_ROM7	; CRC b jt fog.
	addlw	0x30
	call	LCDBYTE
	movlw	' '
	call	LCDBYTE
 
	call	dsreset

	movlw	LCD_LINE1
	call	LCDVEZ
	clrwdt

	call    lcdprintrom

	call	LONGDLY_500
	goto	ROM_OLV




Kilep:
Hőmérés:
	call	dsreset
	movlw	0xCC	;SKIP ROM
	call	dswrite
;	call	dswriterom0
	movlw	0x44	; Convert T
	call	dswrite
;	call	LONGDLY_500
	call	DS_FF		;valamelyik kell

DS1mér:
	call	dsreset
	movlw	0x55	; ROM azonosit˘
	call	dswrite	
	call	dswriterom0
	movlw	0xBE
	call	dswrite
	call	DS_RAM_O	;9 byte olv. DS_RAM-ba
	call	dsreset
	movlw	d'0'
	call	LCDPOZ
	movlw	'B'
	call	LCDBYTE
	movlw	'e'
	call	LCDBYTE
	movlw	'n'
	call	LCDBYTE
	movlw	't'
	call	LCDBYTE
	movlw	'i'
	call	LCDBYTE
	movlw	':'
	call	LCDBYTE
	movlw	' '
	call	LCDBYTE
	call	lcdprintdsdata
	movf	NumL,w
	movwf	B_hom
	movlw ' '
	call	LCDBYTE
	movlw ' '
	call	LCDBYTE
;	call LONGDLY_500
;	call	ORA_KI
;	call LONGDLY_500
;	call	ORA_KI
	return

DS2mér:
	call	dsreset
	movlw	0x55	; ROM azonosit˘
	call	dswrite	
	call	dswriterom1
	movlw	0xBE
	call	dswrite
	call	DS_RAM_O	;9 byte olv. DS_RAM-ba
	call	dsreset
	movlw	d'0'
	call	LCDPOZ
	movlw	'K'
	call	LCDBYTE
	movlw	'i'
	call	LCDBYTE
	movlw	'n'
	call	LCDBYTE
	movlw	't'
	call	LCDBYTE
	movlw	'i'
	call	LCDBYTE
	movlw	':'
	call	LCDBYTE
	movlw	' '
	call	LCDBYTE
	call	lcdprintdsdata
	movf	NumL,w
	movwf	K_hom
	movlw	' '
	call	LCDBYTE
	movlw	' '
	call	LCDBYTE
;	call LONGDLY_500
;	call	ORA_KI
;	call LONGDLY_500
;	call	ORA_KI
	return

Elv_hom_K:
	movlw	d'0'
	call	LCDPOZ
	movlw	'E'
	call	LCDBYTE
	movlw	'l'
	call	LCDBYTE
	movlw	'v'
	call	LCDBYTE
	movlw	'á'
	call	LCDBYTE
	movlw	'r'
	call	LCDBYTE
	movlw	't'
	call	LCDBYTE
	movlw	':'
	call	LCDBYTE
	movlw	' '
	call	LCDBYTE
	movlw	'+'
	call    LCDBYTE
	movf    elv_hom,w
	movwf   NumL
	clrf	NumH
;	bcf     STATUS,C            ; clear carry, to avoid rrf problems
	call    bin2dec999
	movlw   0x30
	addwf   Tens,W
	call    LCDBYTE
	movlw   0x30
	addwf   Ones,W
	call    LCDBYTE
	movlw   ' '
	call    LCDBYTE
	call    lcdprintcelsius
	movlw	' '
	call	LCDBYTE
;	call LONGDLY_500
;	call	ORA_KI
;	call LONGDLY_500
;	call 	ORA_KI
	return



ORA_KI:

	call	Napkiir2
	movf	sec,W
	movwf	REGA0
	call	bin2dec
	movf	DIGIT10,W
	ADDLW	0x30
	movwf	DIGIT35
	movf	DIGIT9,W
	ADDLW	0x30
	movwf	DIGIT34

	movlw	':'
	movwf	DIGIT33

	movf	perc,W
	movwf	REGA0
	call	bin2dec
	movf	DIGIT10,W
	ADDLW	0x30
	movwf	DIGIT32
	movf	DIGIT9,W
	ADDLW	0x30
	movwf	DIGIT31

	movlw	':'
	movwf	DIGIT30

	movf	ora,W
	movwf	REGA0
	call	bin2dec
	movf	DIGIT10,W
	ADDLW	0x30
	movwf	DIGIT29
	movf	DIGIT9,W
	ADDLW	0x30
	movwf	DIGIT28

kiir2:
	call	LCDLINE2
	movlw	0x60		;m˙sodik sor els< karakter regisztercime
	movwf	DSZ
	movlw	0x40		;az els< kar. cime az LCD-n
	movwf	KSZ
	movlw	0x10		;16 karaktert irunk ki
	movwf	PSZ
	call	KAR_KI
;	call LONGDLY_500
;	call LONGDLY_500
;	call LONGDLY_500
;	call LONGDLY_500
	return
;
Napkiir1:
	movlw	0x0
	movwf	KSZ
	movlw	0x0	;LCD 1.sor 1.karakter cime
	movwf	FSR
	movlw	0x0	;induló EEPROM cim
	movwf	p_1
	movf	nap,w
	movwf	p_2
	goto	napo1
Napkiir2:
	movlw	0x0
	movwf	KSZ
	movlw	0x60	;LCD 2.sor 1.karakter cime
	movwf	FSR
	movlw	0x0	;induló EEPROM cim
	movwf	p_1
	movf	nap,w
	movwf	p_2
napo1:	decfsz	p_2,f
	goto	napo2
	goto	nap_o1
napo2:	movf	p_1,w	;köv. nap EEPROM cime d'18'-al késöbb
	addlw	0x12
	movwf	p_1
	goto	napo1
nap_o1:		;nap olvasása
	movf	p_1,w
	call	EE_OLV
	movwf	INDF	; W-> FSR által mutatott cimre
	incf	FSR,F
	incf	p_1,f
	incf	KSZ,f
	movlw	0x8
	subwf	KSZ,w
	btfss	STATUS,Z
	goto	nap_o1
	return




;Atalakit:
;	call	bin2dec		;rega-->decimálissá
;	call	KAR_AT



Kiir1:
	call	LCDLINE1
	movlw	0x50		;els< sor els< karakter regisztercime
	movwf	DSZ
	movlw	0x0		;az els< kar. cime az LCD-n
	movwf	KSZ
	movlw	0x10		;16 karaktert irunk ki
	movwf	PSZ
	call	KAR_KI
	return
Kiir2:
	call	LCDLINE2
	movlw	0x60		;m˙sodik sor els< karakter regisztercime
	movwf	DSZ
	movlw	0x40		;az els< kar. cime az LCD-n
	movwf	KSZ
	movlw	0x10		;16 karaktert irunk ki
	movwf	PSZ
	call	KAR_KI
	return


;(rutinok:)

KAR_KI:	movf	KSZ,W		;PSZ sz˙mu karakter az LCD-re
	call	LCDPOZ
	movf	DSZ,W
	movwf	FSR		;fsr-ben a DSZ-digitsz˙ml˙lô
hz1	movlw	0x30		;ha "0" ...
	xorwf	ind,W
	btfss	STATUS,Z
	goto	hz2
	movlw	0x20		;els< "0"-k helyett space
	movwf	LCDByte
	call	LCDBYTE
	incf	FSR,f
	decfsz	PSZ,f
	goto	hz1
	goto	hz2
hz2	movf	ind,W
	movwf	LCDByte
	call	LCDBYTE
	incf	FSR,f
	decfsz	PSZ,f
	goto	hz2
hz3	RETURN


KAR_AT:				;DEC.-karakterr'
	movf	DSIGN,W
	ADDLW	0x30
	MOVWF	DSIGN
	movf	DIGIT1,W
	ADDLW	0x30
	MOVWF	DIGIT1
	movf	DIGIT2,W
	ADDLW	0x30
	MOVWF	DIGIT2
	movf	DIGIT3,W
	ADDLW	0x30
	MOVWF	DIGIT3
	movf	DIGIT4,W
	ADDLW	0x30
	MOVWF	DIGIT4
	movf	DIGIT5,W
	ADDLW	0x30
	MOVWF	DIGIT5
	movf	DIGIT6,W
	ADDLW	0x30
	MOVWF	DIGIT6
	movf	DIGIT7,W
	ADDLW	0x30
	MOVWF	DIGIT7
	movf	DIGIT8,W
	ADDLW	0x30
	MOVWF	DIGIT8
	movf	DIGIT9,W
	ADDLW	0x30
	MOVWF	DIGIT9
	movf	DIGIT10,W
	ADDLW	0x30
	MOVWF	DIGIT10
	RETURN


;	*	*	*	*	*	*	*	*	*	*	*	*
;		32 bites matek !!!

;	CALL	add		;REGA.=REGA.+REGB. (30-33 ill. 40-43)
;	CALL	subtract	;REGA.=REGA.-REGB. 
;	CALL	multiply	;REGA.=REGA.*REGB. 
; 	CALL	divide		;REGA.=REGA./REGB. 
;	CALL	round
;	CALL	sqrt		;REGA.=n'gyzetgy<k (REGA.)
;	CALL	bin2dec		;eredm'ny 50-5A -ig (REGA. ˙talakit˙sa decimťliss˙ --> LCD )
;	movlw	0x0A		;alakitandô KARAKTEREK sz˙ma->W
;	call	dec2bin		;Digit1-t<l->regA-ba
;


      ;*** 32 BIT SIGNED SUTRACT ***
      ;REGA - REGB -> REGA
      ;Return carry set if overflow
subtract:
      	call	negateb		;Negate REGB
      	skpnc
      	return			;Overflow

      ;*** 32 BIT SIGNED ADD ***
      ;REGA + REGB -> REGA
      ;Return carry set if overflow

add:	movf	REGA3,w		;Compare signs
      	xorwf	REGB3,w
      	movwf	MTEMP

      	call	addba		;Add REGB to REGA

      	clrc			;Check signs
      	movf	REGB3,w		;If signs are same
      	xorwf	REGA3,w		;so must result sign
      	btfss	MTEMP,7		;else overflow
      	addlw	0x80
      	return

      ;*** 32 BIT SIGNED MULTIPLY ***
      ;REGA * REGB -> REGA
      ;Return carry set if overflow

multiply:
      	clrf	MTEMP		;Reset sign flag
      	call	absa		;Make REGA positive
      	skpc
      	call	absb		;Make REGB positive
      	skpnc
      	return			;Overflow

      	call	movac		;Move REGA to REGC
      	call	clra		;Clear product

      	movlw	D'31'		;Loop counter
      	movwf	MCOUNT

muloop:	call	slac		;Shift left product and multiplicand
      	
      	rlf	REGC3,w		;Test MSB of multiplicand
      	skpnc			;If multiplicand bit is a 1 then
      	call	addba		;add multiplier to product

      	skpc			;Check for overflow
      	rlf	REGA3,w
      	skpnc
      	return

      	decfsz	MCOUNT,f	;Next
      	goto	muloop

      	btfsc	MTEMP,0		;Check result sign
      	call	negatea		;Negative
      	return


      ;*** 32 BIT SIGNED DIVIDE ***
      ;REGA / REGB -> REGA
      ;Remainder in REGC
      ;Return carry set if overflow or division by zero

divide:	clrf	MTEMP		;Reset sign flag
      	movf	REGB0,w		;Trap division by zero
      	iorwf	REGB1,w
      	iorwf	REGB2,w
      	iorwf	REGB3,w
      	sublw	0
      	skpc
      	call	absa		;Make dividend (REGA) positive
      	skpc
      	call	absb		;Make divisor (REGB) positive
      	skpnc
      	return			;Overflow

      	clrf	REGC0		;Clear remainder
      	clrf	REGC1
      	clrf	REGC2
      	clrf	REGC3
      	call	slac		;Purge sign bit

      	movlw	D'31'		;Loop counter
      	movwf	MCOUNT

dvloop:	call	slac		;Shift dividend (REGA) msb into remainder (REGC)

      	movf	REGB3,w		;Test if remainder (REGC) >= divisor (REGB)
      	subwf	REGC3,w
      	skpz
      	goto	dtstgt
      	movf	REGB2,w
      	subwf	REGC2,w
      	skpz
      	goto	dtstgt
      	movf	REGB1,w
      	subwf	REGC1,w
      	skpz
      	goto	dtstgt
      	movf	REGB0,w
      	subwf	REGC0,w
dtstgt:	skpc			;Carry set if remainder >= divisor
      	goto	dremlt

      	movf	REGB0,w		;Subtract divisor (REGB) from remainder (REGC)
      	subwf	REGC0,f
      	movf	REGB1,w
      	skpc
      	incfsz	REGB1,w
      	subwf	REGC1,f
      	movf	REGB2,w
      	skpc
      	incfsz	REGB2,w
      	subwf	REGC2,f
      	movf	REGB3,w
      	skpc
      	incfsz	REGB3,w
      	subwf	REGC3,f
      	clrc
      	bsf	REGA0,0		;Set quotient bit

dremlt:	decfsz	MCOUNT,f	;Next
      	goto	dvloop

      	btfsc	MTEMP,0		;Check result sign
      	call	negatea		;Negative
      	return

      ;*** ROUND RESULT OF DIVISION TO NEAREST INTEGER ***

round:	clrf	MTEMP		;Reset sign flag
      	call	absa		;Make positive
      	clrc
      	call	slc		;Multiply remainder by 2
      	movf	REGB3,w		;Test if remainder (REGC) >= divisor (REGB)
      	subwf	REGC3,w
      	skpz
      	goto	rtstgt
      	movf	REGB2,w
      	subwf	REGC2,w
      	skpz
      	goto	dtstgt
      	movf	REGB1,w
      	subwf	REGC1,w
      	skpz
      	goto	rtstgt
      	movf	REGB0,w
      	subwf	REGC0,w
rtstgt:	skpc			;Carry set if remainder >= divisor
      	goto	rremlt
      	incfsz	REGA0,f		;Add 1 to quotient
      	goto	rremlt
      	incfsz	REGA1,f
      	goto	rremlt
      	incfsz	REGA2,f
      	goto	rremlt
      	incf	REGA3,f
      	skpnz
      	return			;Overflow,return carry set
rremlt:	btfsc	MTEMP,0		;Restore sign
      	call	negatea
      	return


      ;*** 32 BIT SQUARE ROOT ***
      ;sqrt(REGA) -> REGA
      ;Return carry set if negative

sqrt:		rlf	REGA3,w		;Trap negative values
      	skpnc
      	return

      	call	movac		;Move REGA to REGC
      	call	clrba		;Clear remainder (REGB) and root (REGA)

      	movlw	D'16'		;Loop counter
      	movwf	MCOUNT

sqloop:	rlf	REGC0,f		;Shift two msb's
      	rlf	REGC1,f		;into remainder
      	rlf	REGC2,f
      	rlf	REGC3,f
      	rlf	REGB0,f
      	rlf	REGB1,f
      	rlf	REGB2,f
      	rlf	REGC0,f
      	rlf	REGC1,f
      	rlf	REGC2,f
      	rlf	REGC3,f
      	rlf	REGB0,f
      	rlf	REGB1,f
      	rlf	REGB2,f

      	setc			;Add 1 to root
      	rlf	REGA0,f		;Align root
      	rlf	REGA1,f
      	rlf	REGA2,f

      	movf	REGA2,w		;Test if remdr (REGB) >= root (REGA)
      	subwf	REGB2,w
      	skpz
      	goto	ststgt
      	movf	REGA1,w
      	subwf	REGB1,w
      	skpz
      	goto	ststgt
      	movf	REGA0,w
      	subwf	REGB0,w
ststgt:	skpc			;Carry set if remdr >= root
      	goto	sremlt

      	movf	REGA0,w		;Subtract root (REGA) from remdr (REGB)
      	subwf	REGB0,f
      	movf	REGA1,w
      	skpc
      	incfsz	REGA1,w
      	subwf	REGB1,f
      	movf	REGA2,w
      	skpc
      	incfsz	REGA2,w
      	subwf	REGB2,f
      	bsf	REGA0,1		;Set current root bit

sremlt:	bcf	REGA0,0		;Clear test bit
      	decfsz	MCOUNT,f	;Next
      	goto	sqloop

      	clrc
      	rrf	REGA2,f		;Adjust root alignment
      	rrf	REGA1,f
      	rrf	REGA0,f
      	return


      ;*** 32 BIT SIGNED BINARY TO DECIMAL ***
      ;REGA -> DIGITS 1 (MSD) TO 10 (LSD) & DSIGN
      ;DSIGN = 0 if REGA is positive, 1 if negative
      ;Return carry set if overflow
      ;Uses FSR register

bin2dec:	clrf	MTEMP		;Reset sign flag
      	call	absa		;Make REGA positive
      	skpnc
      	return			;Overflow

      	call	clrdig		;Clear all digits

      	movlw	D'32'		;Loop counter
      	movwf	MCOUNT

b2dloop:	rlf	REGA0,f		;Shift msb into carry
      	rlf	REGA1,f
      	rlf	REGA2,f
      	rlf	REGA3,f

      	movlw	DIGIT10
      	movwf	FSR		;Pointer to digits
      	movlw	D'10'		;10 digits to do
      	movwf	DCOUNT

adjlp:	rlf	INDF,f		;Shift digit and carry 1 bit left
      	movlw	D'10'
      	subwf	INDF,w		;Check and adjust for decimal overflow
      	skpnc
      	movwf	INDF

      	decf	FSR,f		;Next digit
      	decfsz	DCOUNT,f
      	goto	adjlp

      	decfsz	MCOUNT,f	;Next bit
      	goto	b2dloop

      	btfsc	MTEMP,0		;Check sign
      	bsf	DSIGN,0		;Negative
      	clrc
      	return


      ;*** 32 BIT SIGNED DECIMAL TO BINARY ***
      ;Decimal DIGIT1 thro DIGIT(X) & DSIGN -> REGA
      ;Set DSIGN = 0 for positive, DSIGN = 1 for negative values
      ;Most significant digit in DIGIT1
      ;Enter this routine with digit count in w register
      ;Return carry set if overflow
      ;Uses FSR register

dec2bin:	movwf	MTEMP		;Save digit count

      	movlw	D'32'		;Outer bit loop counter
      	movwf	MCOUNT

d2blp1:	movlw	DIGIT1-1	;Set up pointer to MSD
      	movwf	FSR
      	movf	MTEMP,w		;Inner digit loop counter
      	movwf	DCOUNT

      	movlw	D'10'
      	clrc			;Bring in '0' bit into MSD

d2blp2:	incf	FSR,f
      	skpnc
      	addwf	INDF,f		;Add 10 if '1' bit from prev digit
           	rrf	INDF,f		;Shift out LSB of digit

      	decfsz	DCOUNT,f	;Next L.S. Digit
      	goto	d2blp2

      	rrf	REGA3,f		;Shift in carry from digits
      	rrf	REGA2,f
      	rrf	REGA1,f
      	rrf	REGA0,f

      	decfsz	MCOUNT,f	;Next bit
      	goto	d2blp1

      	movf	INDF,w		;Check for overflow
      	addlw	0xFF
      	skpc
      	rlf	REGA3,w
      	skpnc
      	return

      	btfsc	DSIGN,0		;Check result sign
      	call	negatea		;Negative
      	return


      ;UTILITY ROUTINES


      ;Add REGB to REGA (Unsigned)
      ;Used by add, multiply,

addba:	movf	REGB0,w		;Add lo byte
      	addwf	REGA0,f

      	movf	REGB1,w		;Add mid-lo byte
      	skpnc			;No carry_in, so just add
      	incfsz	REGB1,w		;Add carry_in to REGB
      	addwf	REGA1,f		;Add and propagate carry_out

      	movf	REGB2,w		;Add mid-hi byte
      	skpnc
      	incfsz	REGB2,w
      	addwf	REGA2,f

      	movf	REGB3,w		;Add hi byte
      	skpnc
      	incfsz	REGB3,w
      	addwf	REGA3,f
      	return


      ;Move REGA to REGC
      ;Used by multiply, sqrt

movac:	movf	REGA0,w
      	movwf	REGC0
      	movf	REGA1,w
      	movwf	REGC1
      	movf	REGA2,w
      	movwf	REGC2
      	movf	REGA3,w
      	movwf	REGC3
      	return


      ;Clear REGB and REGA
      ;Used by sqrt

clrba:	clrf	REGB0
      	clrf	REGB1
      	clrf	REGB2
      	clrf	REGB3

      ;Clear REGA
      ;Used by multiply, sqrt

clra:		clrf	REGA0
      	clrf	REGA1
      	clrf	REGA2
      	clrf	REGA3
      	return


      ;Check sign of REGA and convert negative to positive
      ;Used by multiply, divide, bin2dec, round

absa:		rlf	REGA3,w
      	skpc
      	return			;Positive

      ;Negate REGA
      ;Used by absa, multiply, divide, bin2dec, dec2bin, round

negatea:	movf	REGA3,w		;Save sign in w
      	andlw	0x80

      	comf	REGA0,f		;2's complement
      	comf	REGA1,f
      	comf	REGA2,f
      	comf	REGA3,f
      	incfsz	REGA0,f
      	goto	nega1
      	incfsz	REGA1,f
      	goto	nega1
      	incfsz	REGA2,f
      	goto	nega1
      	incf	REGA3,f

nega1:     	incf	MTEMP,f		;flip sign flag
      	addwf	REGA3,w		;Return carry set if -2147483648
      	return


      ;Check sign of REGB and convert negative to positive
      ;Used by multiply, divide

absb:		rlf	REGB3,w
      	skpc
      	return			;Positive

      ;Negate REGB
      ;Used by absb, subtract, multiply, divide

negateb:	movf	REGB3,w		;Save sign in w
      	andlw	0x80

      	comf	REGB0,f		;2's complement
      	comf	REGB1,f
      	comf	REGB2,f
      	comf	REGB3,f
      	incfsz	REGB0,f
      	goto	negb1
      	incfsz	REGB1,f
      	goto	negb1
      	incfsz	REGB2,f
      	goto	negb1
      	incf	REGB3,f

negb1:     	incf	MTEMP,f		;flip sign flag
      	addwf	REGB3,w		;Return carry set if -2147483648
      	return


      ;Shift left REGA and REGC
      ;Used by multiply, divide, round

slac:		rlf	REGA0,f
      	rlf	REGA1,f
      	rlf	REGA2,f
      	rlf	REGA3,f
slc:		rlf	REGC0,f
      	rlf	REGC1,f
      	rlf	REGC2,f
      	rlf	REGC3,f
      	return


      ;Set all digits to 0
      ;Used by bin2dec

clrdig:	clrf	DSIGN
      	clrf	DIGIT1
      	clrf	DIGIT2
      	clrf	DIGIT3
      	clrf	DIGIT4
      	clrf	DIGIT5
      	clrf	DIGIT6
      	clrf	DIGIT7
      	clrf	DIGIT8
      	clrf	DIGIT9
      	clrf	DIGIT10
      	return



lcdaschex
 movwf   LCD_TEMP
 swapf   LCD_TEMP,W
 andlw   B'00001111'
 addlw   -0x0a
 btfsc   STATUS,C
 addlw   0x07
 addlw   0x3a
 movwf   LCD_ASCHEXHI
 movf    LCD_TEMP,W
 andlw   B'00001111'
 addlw   -0x0a
 btfsc   STATUS,C
 addlw   0x07
 addlw   0x3a
 movwf   LCD_ASCHEXLO
 return
;
lcdprintdsdata
 call    lcdascsign          ; calculate the sign from DS_SIGN
 movf    LCD_ASCSIGN,W
 call    LCDBYTE

 movf    DS_RAM0,W
 movwf   NumL
 movlw   '5'
 movwf   LCD_ASCHALF         ; insert asc '5' into aschalf
 movlw   0x01
 andwf   NumL,W
 btfss   STATUS,Z
 goto    skipit
 movlw   '0'
 movwf   LCD_ASCHALF         ; insert asc '0' into aschalf
skipit

 bcf     STATUS,C            ; clear carry, to avoid rrf problems
 rrf     NumL,F              ; divide ds1820 temp through 2
 clrf    NumH
 call    bin2dec999
 movlw   0x30
 addwf   Tens,W
 call    LCDBYTE
 movlw   0x30
 addwf   Ones,W
 call    LCDBYTE
 movlw   '.'
 call    LCDBYTE
 movf    LCD_ASCHALF,W
 call    LCDBYTE
 call    lcdprintcelsius
 return
;
lcdprintcelsius			;*********C fok kiˇr s ********
 movlw   'C'
 call    LCDBYTE
 movlw   B'11011111'
 call    LCDBYTE
 return
;
;
lcdascsign
 movf    DS_RAM1,W
 btfss   STATUS,Z
 goto    lcdascsignminus			;*********PLUSSZ JEL**
 movlw   '+'
 movwf   LCD_ASCSIGN
 return
lcdascsignminus					;***MINUSZ JEL****
 movlw   '-'
 movwf   LCD_ASCSIGN
 return

bin2dec999
 movf    NumH,W
 addlw   D'241'
 addwf   NumH,W
 movwf   Hund      ;b_2 = 2a_2 - 15
 addwf   Hund,W
 addwf   Hund,W
 addlw   D'253'
 movwf   Tens
 swapf   NumL,W
 andlw   0x0f
 addwf   Tens,F
 addwf   Tens,F   ;b_1 = 6a_2 + 2a_1 - 48
 addwf   NumH,W
 sublw   D'251'
 movwf   Ones
 addwf   Ones,F
 addwf   Ones,F
 addwf   Ones,F
 movf    NumL,W
 andlw   0x0f
 addwf   Ones,F   ;b_0 = a_0 - 4(a_2 + a_1) - 20
 movlw   D'10'
bin2dec999a                  ; 9 cycles max
 addwf   Ones,F
 decf    Tens,F
 btfss   STATUS,C
 goto    bin2dec999a
bin2dec999b                  ; 6 cycles max
 addwf   Tens,F
 decf    Hund,F
 btfss   STATUS,C
 goto    bin2dec999b
bin2dec999c                  ; 3 cycles max
 addwf   Hund,F
 btfss   STATUS,C
 goto    bin2dec999c
 return
;

;
lcdprintram:
	movlw   0x08                ; set counter to 8
	 movwf   DS_TMP0
	 movlw   DS_RAM0             ; indirect addressing 
	 movwf   FSR                 ; put first byte (DS_ROM0) into FSR
lcdprintramloop:
	 movf    INDF,W              ; load INDF pointers target into w
	 call    lcdaschex           ; call hex->ascii conversion
	 movf    LCD_ASCHEXHI,W
	 call    LCDBYTE
	 movf    LCD_ASCHEXLO,W
	 call    LCDBYTE 
	 incf    FSR,F               ; increment FSR (now DS_ROM0 + n)
	 decfsz  DS_TMP0,F
	 goto    lcdprintramloop
	 return
;
;
lcdprintrom
 movlw   0x08                ; set counter to 8
 movwf   DS_TMP0
 movlw   DS_ROM0             ; indirect addressing 
 movwf   FSR                 ; put first byte (DS_ROM0) into FSR
lcdprintromloop
 movf    INDF,W              ; load INDF pointers target into w
 call    lcdaschex           ; call hex->ascii conversion
 movf    LCD_ASCHEXHI,W
 call    LCDBYTE
 movf    LCD_ASCHEXLO,W
 call    LCDBYTE 
 incf    FSR,F               ; increment FSR (now DS_ROM0 + n)
 decfsz  DS_TMP0,F
 goto    lcdprintromloop
 return


;
Gombok:
	call	LONGDLY_500
;port_a.sti-hez
	nop
	nop	;Zero--"fel"
	nop	;Zero--"le"
	nop	;Zero--"jobbra"
	nop	;Zero--"balra"
	movf	PORTA,w
	movwf	Gomb_T
	movlw	0x0F
	xorwf	Gomb_T,f
	movlw	0x0
	addwf	Gomb_T,w
	btfsc	STATUS,Z	;nem volt gombnyomás
	goto	Gombok
	return


;
lcdclear
	movlw   0x01
	movwf	LCDVez
	call    LCDVEZ
	call	LONGDLY_100
	return
;


;	*	*	*	*	*	*	*	*	*	*	*	*	*


; LCD: DISPLAYTECH 162B ~ HD44780		file:PIC_LCD4.ASM
; LCD vez'rl's:
;	RS -- RB3
;	R/-W -- GND!!!
;	E ----- RB2
;LCD adatok:
;	D4 ---- RB4
;	D5 ---- RB5
;	D6 ---- RB6
;	D7 ---- RB7

;To use this code, firstly set the relevent TRIS bits, then initialise the LCD: 
;	CALL LONGDLY
;	CALL LCDFUN 	; sets the LCD's function to 4 bit, 2 line, 5x7 font
;       CALL LONGDLY 	
;       CALL LCDDISP ; Turns on the display and cursor
;       CALL LONGDLY
;	CALL LCDENT 	; sets auto increment right after write (like a typewriter)
;       CALL LCDCLR
  
;You know the LCD is initialized when iot is totally blank. If you get the one row solid black and the other clear, the LCD has not been initialised properly. 
;Now, there are 2 ways to write to the LCD. Firstly, you can use the LCDChar method. This is nice because it automatcally word wraps the text, and prevents you writing to non- visible memory. For instance: 
;	movlw "A"
;	movwf LCDByte
;	CALL LCDCHAR
  
;To write different commands to the LCD, such as different function select bytes, set the relevent RS bit, put the data in LCDByte, then call LCDBYTE. This is only for the LCD gurus! 
;To change the address, call LCDVEZ eg to go to address 3, 
;	movlw 3
;	movwf LCDadd
;	CALL LCDVEZ 
;To clear the LCD, 
;	CALL LCDCLR. 
;To 'backspace',
;	CALL LCDBACKSPACE
;If you need a hand, email me @ a.borowski@student.qut.edu.au
;or visit my website at http://www.alborowski.tk 

;    forr˙snak felhaszn˙lva --> ALAKITVA !!!!!!

LCDINIT:
	BCF	STATUS,RP0	;Bank1
	CLRF	PORTB
	BSF STATUS,RP0
;	MOVLW	b'00000011'	;RB2-RB7 LCD
;	MOVWF	TRISB
	BCF	STATUS,RP0	;Bank0
	CALL	LONGDLY_100
	MOVLW	b'00110100'	;FUNKCIO 8 bites interface
	MOVWF	PORTB
	CALL	SHORTDLY
	BCF PORTB,LCDEnable
	CALL	SHORTDLY
	BSF PORTB,LCDEnable
	CALL	SHORTDLY
	BCF PORTB,LCDEnable
	CALL	SHORTDLY
	BSF PORTB,LCDEnable
	CALL	SHORTDLY
	BCF PORTB,LCDEnable
	CALL	SHORTDLY
	BSF PORTB,LCDEnable
	CALL	SHORTDLY
	NOP
	MOVLW	b'00100100'	;FUNKCIO 4 bites interface
	MOVWF	PORTB
	CALL	SHORTDLY
	BCF PORTB,LCDEnable
	CALL	SHORTDLY
	BSF PORTB,LCDEnable
	CALL	SHORTDLY
	MOVLW	b'00101000'	;2 SOROS norm l FONT
	MOVWF	LCDByte
	CALL	LCDBYTE
	MOVLW	b'00001100'	;Display ON, Cursor OFF, Blink OFF
	MOVWF	LCDByte
	CALL	LCDBYTE
	MOVLW	b'00000110'	;Entry môd: Cursor increment, Display shift No
	MOVWF	LCDByte
	CALL	LCDBYTE
	MOVLW	b'10000001'	;Set DD RAM, '01'
	MOVWF	LCDByte
	CALL	LCDBYTE
	BCF	PORTB,LCDRS	;Vez'rl's k"vetkezik	
	MOVLW	b'00000001'	;Dislpay Clear
	MOVWF	LCDByte
	CALL	LCDBYTE
	BSF	PORTB,LCDRS	;Vez'rl's v'ge, karakter k"vetkezik
	CALL	SHORTDLY
	RETURN


LCDVEZ ; makes LCDVez the current LCD Address
	nop
	BCF PORTB,LCDRS
; !
	movf	LCDVez,W	;vez'rl<byte	LCDVez->W
; !
	movwf LCDByte
	CALL LCDBYTE
;	call	LONGDLY_1
	bsf PORTB,LCDRS
	RETURN

LCDLINE1:	; here we must go to the new line
	movlw b'00000000'	;0h
	movwf LCDVez
	bsf	LCDVez,0x7
	CALL LCDVEZ
	RETURN

LCDLINE2:	; here we must go to the new line
	movlw b'01000000'	;40h
	movwf LCDVez
	bsf	LCDVez,0x7
	CALL LCDVEZ
	RETURN

LCDPOZ:		;MOVLW	h'x' -els< sorba xx=0-F=d'0-15'
		;MOVLW	h'xx' -m sodik sorba xx=40-4F
	movwf LCDVez
	bsf	LCDVez,0x7
	nop
	BCF PORTB,LCDRS
	movf	LCDVez,W	;vez'rl<byte	LCDVez->W
	movwf LCDByte
	CALL LCDBYTE
	bsf PORTB,LCDRS
	RETURN

LCDBYTE:	; sends a byte to the LCD, in 4bit fashion
      	; responsible for breaking up the byte to send into high and low nibbles
		; and dumps them to LCD
	
		;NOT responsible for the status of the LCDRS line, nor the major delays

		; IN: LCDByte  - distructive OUT: hiByte, loByte
		;RS-t át kell engedni'''+ a nem használt RB0,RB1-et
	
; !!!
	movwf LCDByte	;W-ben lev" adat-karakter let rol sa

	MOVF	PORTB,W	; RSbit letárolása
	MOVWF	RSbit	
	MOVLW	b'00001011'	;maszk RS-hez és RB0,RB1-hez
	ANDWF	RSbit,f	;vez'rl's-> RSbit=0, karakter-> RSbit=1

	clrf HiByte 	; clears the vars, to prevent bugs
	clrf LoByte

	MOVF LCDByte,W	; Karakter a W-be
	MOVWF HiByte
	MOVWF LoByte
	rlf LoByte, 1
	rlf LoByte, 1
	rlf LoByte, 1
	rlf LoByte, 1
	MOVLW 0xF0		; W=b'11110000'
	ANDWF LoByte,f
	MOVLW 0xF0		; W=b'11110000'
	ANDWF HiByte,f	; 
	MOVF	HiByte,W	; W-ben A HiByte
	IORWF	RSbit,W
	MOVWF	LCDTar
	BSF	LCDTar,LCDEnable
	MOVF	LCDTar,W
	MOVWF PORTB
	CALL	SHORTDLY
	BCF PORTB,LCDEnable
	CALL	SHORTDLY
	BSF PORTB,LCDEnable
	CALL	SHORTDLY
	NOP
	MOVF LoByte,W	; W-ben A LoByte
	IORWF	RSbit,W
	MOVWF	LCDTar
	BSF	LCDTar,LCDEnable
	MOVF	LCDTar,W
	MOVWF PORTB
	CALL	SHORTDLY
	BCF PORTB,LCDEnable
	CALL	SHORTDLY
	BSF PORTB,LCDEnable
	NOP
	RETURN	

SHORTDLY:	; around 100us
		;100 cycles
	movlw	0x21
	movwf	d1
SHORTDLY_0:
	decfsz	d1, f
	goto	SHORTDLY_0
			;4 cycles (including call)
	RETURN

LONGDLY_500:	; 0,5sec delay
	call	LONGDLY_100
	call	LONGDLY_100
	call	LONGDLY_100
	call	LONGDLY_100
	call	LONGDLY_100
	return

LONGDLY_1:	; 1msec delay
		; * 998 * cycles
	movlw	0xC7
	movwf	d1
	movlw	0x01
	movwf	d2
	goto	LONGDLY_0
LONGDLY_100:
;	return		;csak teszthez!!!!
	; 0,1sec delay
		; * 999998 * cycles
	movlw	0x1F
	movwf	d1
	movlw	0x4F
	movwf	d2
LONGDLY_0:
	decfsz	d1, f
	goto	$+2
	decfsz	d2, f
	goto	LONGDLY_0
				;2 cycles
	goto	$+1
	nop
	RETURN			;4 cycles (including call)


	org 0x2100		;EEPROM  "alap"

	dt" Hetfo   &0?V"
	dt"  Kedd   &0?V"
	dt"Szerda   &0?V"
	dt"Csutort. &0?V"
	dt"Pentek   &0?V"
	dt"Szombat  &0?V"
	dt"Vasárnap &0?V"


	end
