
; LED je pripojena na RA,1-4


	LIST P=16F627, R=DEC
W_save	equ	20h	; zaloha pri preruseni
Sta_sav	equ	21h	; zaloha pri preruseni
PCL_sav	equ	22h	; zaloha pri preruseni
FSR_sav	equ	23h	; zaloha pri preruseni

#DEFINE	LED1	PORTB,0
#DEFINE	LED2	PORTB,1
#DEFINE	LED3	PORTB,2
#DEFINE	LED4	PORTB,3
;-----------------------------------------------------------------------------------------------

	org	00h
	goto	INIT

	org	04h		; ulozeni hlavnich registru
	movwf	W_save		; W
	movf	STATUS,W
	clrf	STATUS		; Banka 0
	movwf	Sta_sav		; STATUS
	movf	PCLATH,w
	movwf	PCL_sav		; PCLATH
	movf	FSR,w
	movwf	FSR_sav		; FSR
	GOTO	PRERUS

;************************************************************************************************
;************************************************************************************************
;************************************************************************************************


INIT	BSF	STATUS,RP0	; nastaveni In / Out
	MOVLW	B'11111111'
	MOVWF	TRISA
	MOVLW	B'11110000'
	MOVWF	TRISB
	BCF	STATUS,RP0
	MOVLW	B'10001000'	; povoleni preruseni pouze od RB0
	MOVWF	INTCON

	NOP			; vlastni program !
	GOTO	$-1

;-----------------------------------------------------------------     Preruseni

PRERUS	MOVF	portb,w		; vycistit port 
	BCF	INTCON,rbif	; smazat priznak

	BTFSC	PORTB,7
	CALL	ONLED1
	BTFSC	PORTB,6
	CALL	ONLED2
	BTFSC	PORTB,5
	CALL	ONLED3
	BTFSC	PORTB,4
	CALL	ONLED4

	
	GOTO	PRERKON


PRERKON	MOVLW	B'10001000'	; povoleni zpet pozadovanych preruseni
	MOVWF	INTCON
	clrf	STATUS		; Banka 0	obnoveni ulozenych registru
	movf	FSR_sav,w	; FSR
	movwf	FSR
	movf	PCL_sav,w	; PCLATH
	movwf	PCLATH
	movf	Sta_sav,w	; Status
	movwf	STATUS
	swapf	W_save,f	; W
	swapf	W_save,w
	retfie



ONLED1	BTFSS	LED1		; zjistit stal LED a zmenit
	GOTO	$+3
	BCF	LED1
	RETURN
	BSF	LED1
	RETURN

ONLED2	BTFSS	LED2		; zjistit stal LED a zmenit
	GOTO	$+3
	BCF	LED2
	RETURN
	BSF	LED2
	RETURN

ONLED3	BTFSS	LED3		; zjistit stal LED a zmenit
	GOTO	$+3
	BCF	LED3
	RETURN
	BSF	LED3
	RETURN

ONLED4	BTFSS	LED4		; zjistit stal LED a zmenit
	GOTO	$+3
	BCF	LED4
	RETURN
	BSF	LED4
	RETURN

;--------------------------------------------------------

	END