; Preruseni od pinu RB,0
; LED je pripojena na RA,1


	LIST P=16F628A, R=DEC
	INCLUDE<P16F628.INC>

	__CONFIG _PWRTE_ON & _WDT_OFF & _MCLRE_OFF & _BODEN_OFF & _LVP_OFF & _INTRC_OSC_NOCLKOUT

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	LED	PORTA,1


;-----------------------------------------------------------------------------------------------

	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
	MOVLW	B'00000111'	; typ komparatoru (off)
	MOVWF	CMCON
	BSF		STATUS,RP0	; nastaveni In / Out
	MOVLW	B'00000001'	
	MOVWF	TRISA
	MOVLW	B'11111111'
	MOVWF	TRISB
	BCF		STATUS,RP0
	MOVLW	B'10001000'	; povoleni preruseni pouze od RB4-7
	MOVWF	INTCON

	NOP			; vlastni program 
	GOTO	$-1

;-----------------------------------------------------------------     Preruseni
PRERUS	
	BTFSC	PORTB,4
	GOTO	PRER0		; od RB4 test
	GOTO	PRERKON		; nezname = nic

PRER0
	banksel	PORTB
	MOVF	PORTB,W
	BCF		INTCON,RBIF		; smazat priznak
	BTFSS	LED				; zjistit stav LED a zmenit
	GOTO	$+3
	BCF		LED
	GOTO	PRERKON
	BSF		LED
	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

;--------------------------------------------------------

	END