; programme autorisant 2 interruptions du port B
; sur les pattes PB4 et PB5
#include <p16F84.inc>
compt_1 equ 0C
compt_2 equ 0D
compt_3 equ 0E
compt_4 equ 0F
ORG 0x00 ; processor reset vector
goto main
inter org 0x04 ; sous-programme d'interruption
btfsc INTCON,0 ; test du drapeau d'interruption de port B
goto declench
goto fin
declench: btfsc PORTB,4 ; test pour savoir si l'interruption
vient de PB4
goto jaune
btfsc PORTB,5 ; ou PB5
goto vert
goto fin
jaune: clrf PORTB ; interruption PB4
call wait2
movlw B'00000001'
movwf PORTB
call wait
movlw B'00000000'
movwf PORTB
call wait
movlw B'00000001'
movwf PORTB
call wait
movlw B'00000000'
movwf PORTB
call wait2
movlw B'00000001'
movwf PORTB
call wait
movlw B'00000000'
movwf PORTB
goto fin
vert: clrf PORTB ; interruption PB5
call wait2
movlw B'00000010'
movwf PORTB
call wait
movlw B'00000000'
movwf PORTB
call wait
movlw B'00000010'
movwf PORTB
call wait
movlw B'00000000'
movwf PORTB
call wait2
movlw B'00000010'
movwf PORTB
call wait
movlw B'00000000'
movwf PORTB
goto fin
fin: bcf INTCON,0
retfie
; programme principal
main: bcf STATUS,5 ;banque 0
clrf PORTB
bsf STATUS,5 ;banque 1
movlw B'00110000' ; PB4 et PB5 en entrée
movwf TRISB
bcf STATUS,5 ;banque 0
movlw B'00000000'
movwf INTCON
bsf INTCON,3 ;autorise les interruptions de PORT B
bsf INTCON,7 ; autorise les interruptions
bcf PORTB,1
bsf PORTB,0
call wait
bcf PORTB,0
bsf PORTB,1
call wait
goto main
final: nop ; boucle sans fin d'attente d'interruption
goto final
wait: nop ; sous-programme de tempo
decfsz compt_1,1
goto wait
movlw 020
movwf compt_1
decfsz compt_2,1
goto wait
movlw 020
movwf compt_1
movlw 020
movwf compt_2
return
wait2: nop ; sous-programme de tempo
decfsz compt_3,1
goto wait2
movlw 050
movwf compt_3
decfsz compt_4,1
goto wait2
movlw 050
movwf compt_3
movlw 050
movwf compt_4
return
sleep
END ; directive 'end of program'