 LIST P=16F877
 #INCLUDE "P16F877.INC"
 __CONFIG _XT_OSC&_CP_OFF&_WDT_OFF&_LVP_OFF
	CBLOCK	0x20			;memóriaszelet lefoglalása
	T1
	T2
	T3
	ENDC

	ORG	0

START
	BCF	STATUS,RP1			;BANK 2. bit törlés

	BSF	STATUS,RP0			;BANK1

	;PORTA Digitális I/O-vá tétel
	MOVLW	0x06			
	MOVWF	ADCON1			;Mindegyik PORTA digitális

	;TRIS-ek állítása
	MOVLW	B'00011111'
	MOVWF	TRISA			;PORTA bemenet
	MOVLW	B'00000000'
	MOVWF	TRISD			;PORTD kimenet
	BCF		STATUS,RP0		;BANK0-ba lépés
 
LOOP
    BTFSS	PORTA,0
	CALL	Switch1
    GOTO	LOOP
Switch1 
	CALL	DELAY                        ;give switch time to stop bouncin
	BTFSC	PORTA,0  ;check it's still pressed
	RETLW	0x00                     ;return is not
	BTFSS	PORTA,0                ;see if LED1 is already lit
	GOTO	LED1ON
	GOTO	LED1OFF
 
LED1ON
	BSF		PORTD,0   ;turn LED1 on
	CALL	DELAY
	BTFSC	PORTA,0  ;wait until button is released
	RETLW	0x00
	GOTO	LED1ON     
 
LED1OFF
	BCF		PORTD,0  ;turn LED1 on
	CALL	DELAY
	BTFSC	PORTA,0  ;wait until button is released
	RETLW	0x00
	GOTO	LED1OFF          
DELAY
	MOVLW	d'10'			
	MOVWF	T1				;T1-be bekerül a 200
DEL
	MOVLW	d'10'
	MOVWF	T2				;T2-be bekerül a 255
DEL1
	MOVLW	d'5'
	MOVWF	T3				;T3-ba bekerült a 10
DEL2
	NOP

	DECFSZ	T3,f			;Csökkenti a T3-at, addíg, amig nem nulla
	GOTO	DEL2			; mindig visszaugruk a DEL2-re, vagyis a sok NOP-ra
	DECFSZ	T2,f			;Ha már nulla, akkor ugyanez eljátszódik a T2-vel
	GOTO	DEL1
	DECFSZ	T1,f			;Majd a T1-el is
	GOTO	DEL
	RETURN					;Visszatér a DELAY szubrutinból

	 
	END						;Teljes program végét jelentő END