;
; Program pro PIC16F84, externí krystal 10MHz
; Fcpu = 10MHz/4 = 2,5MHz; Tcy = 1/2,5MHz = 0,4us
;
; Tla?ítka na PORTB(4..7),aktivní v log.0,PULL-UP odpory na Ucc
; LED na PORTB(0..3) aktivní v log.0, p?es odpory na Ucc
; P?i stisku TLx se rozsvítí LEDx, op?tovný stisk zhasne LEDx
;
;****************************************************************
    LIST P = PIC16F84A
	include	"P16F84A.INC"
	__config _CP_OFF & _WDTE_OFF & _FOSC_HS & _PWRTE_ON
;*******************************************************************
;			Definice prom?nných
;*****************************************************************
s_W     equ	20h
s_STAT	equ	21h

stav    equ 22h

#define	LED1	PORTB,0
#define	LED2	PORTB,1
#define	LED3	PORTB,2
#define	LED4	PORTB,3

#define	TL1	PORTB,4
#define	TL2	PORTB,5
#define	TL3	PORTB,6
#define	TL4	PORTB,7
;***********************************************************************
        org	000h                ;adresa po RESETu
        goto	Start

        org	004h                ;adresa Interrupt
        goto	Interrupt
;***********************************************************************
;       Interrupt
;***********************************************************************
Interrupt
        movwf	s_W
		swapf	STATUS,W
		movwf	s_STAT

		bcf	INTCON,RBIF         ;smazání p?íznaku RBIF

        btfsc   stav,0          ;test p?íznaku stisku TL
        goto    Int_end         ;stav = 1(TLx bylo stisnuto)
                                ;stav = 0
Test_TL1
		btfss	TL1				;test TL1
		call	Tlac1           ;TL1 = 0
                                ;TL1 = 1
Test_TL2
		btfss	TL2             ;test TL2
		call	Tlac2           ;TL2 = 0
                                ;TL2 = 1
Test_TL3
		btfss	TL3             ;test TL3
		call	Tlac3           ;TL3 = 0
                                ;TL3 = 1
Test_TL4
		btfss	TL4             ;test TL4
		call	Tlac4           ;TL4 = 0
                                ;TL4 = 1
Int_end
        movf    PORTB,W         ;obsah PORTB -> W;
        andlw   b'11110000'     ;W = (W and 240),test bit? (4..7)
        xorlw   b'11110000'     ;W = 240,Z = 1; W <> 240,Z = 0
        btfsc   STATUS,Z        ;test bitu Z
        bcf stav,0              ;Z = 1 nestiskuto ?ádné TL, nastav bit0 = 0
                                ;Z = 0 stisknuto TLx
		swapf	s_STAT,W
		movwf	STATUS
		swapf	s_W,F
		swapf	s_W,W

        retfie                  ;návrat z p?eru?ení
;***********************************************************************
Tlac1
        btfsc	TL1             ;op?tovný test TL1 pro potla?ení zákmit?
        return                  ;TL1 = 1
                                ;TL1 = 0
        movf    PORTB,W         ;na?tení stavu PORTB -> W
        xorlw   b'00000001'     ;W = (W ex-or 1)
        movwf   PORTB           ;W -> PORTB
        bsf stav,0              ;nastavení p?íznaku stisku TL1, bit0 = 1
        return

Tlac2
        btfsc	TL2
        return

        movf    PORTB,W
        xorlw   b'00000010'
        movwf   PORTB
        bsf stav,0
        return

Tlac3
        btfsc	TL3
        return

        movf    PORTB,W
        xorlw   b'00000100'
        movwf   PORTB
        bsf stav,0
        return

Tlac4
        btfsc	TL4
        return

        movf    PORTB,W
        xorlw   b'00001000'
        movwf   PORTB
        bsf stav,0
        return
;***********************************************************************
;       Hlavní program
;***********************************************************************
Start
        bsf STATUS,RP0          ;Bank1
        movlw   B'11110000'     ;nastavení PORTB(0..3)-OUT;(4..7)-IN
        movwf   06h             ;PORTB
        bcf STATUS,RP0          ;Bank0

        movlw   B'11111111'
        movwf   PORTB

		bcf	INTCON,RBIF         ;smazání p?íznaku RBIF
		bsf	INTCON,RBIE         ;povolení p?eru?ení pro zm?nu na RB4..RB7
		bsf	INTCON,GIE          ;povolení v?ech p?eru?ení

Opak
        goto Opak               ;nekone?ná smy?ka
;***********************************************************************
        end                     ;konec programu




