;int.asm
;		Teste de rotina de interrupçao
;		Interrupçao acionada via pino RB0
;		Rotina de interrupção incrementa um contador
;		Deve ser testado com a opçao "animate"
;		Celio G. 06 Junho 2002
;********************************************************

	list      p=16F877          ; list directive to define processor

w		EQU	0
f		EQU	1
STATUS	equ 0x03
FSR		EQU   0x04
INDF	EQU   0x00
INTCON	equ 0x0b
PORTB	equ 0x06
INTCBITS equ 0x90	; set GIE,INTE clear PEIE,T0IE, RBIE, T0IF,INTF,RBIF
	cblock 20h
	ctint,ct,save_w,save_status
	endc

	org 0000
	movlw INTCBITS	
	movwf INTCON	;habilita interrupcoes em RB0
	goto init
	org 0004		; rotina de interrupçao
	movwf save_w	; salva W
	movf  STATUS,w	; le STATUS reg
	movwf save_status	;salva
	incf ctint,f	;incrementa contador de interrupcoes
	bcf	INTCON,1	; zera flag INTF para reconhecer interrupcao
	movf save_status,w ;
	movwf STATUS	; restore STATUS reg
	swapf save_w,f	; nao mude nenhum bit de STATUS!
	swapf save_w,w	; mas restaure W!
	retfie			; retorna, habilitando interrupcoes
init:
	clrf ctint		; zera contadores
	clrf ct

again:
	sleep			; modo power down, aguarda interrupcao
	incf ct,f		; apos servico da interrupcao, incrementa ct
	goto again
	END

