Retour Page PIC

; programme autorisant une interuption sur le port B
; déclenchant le clignotement d'une LED

#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 ; interruption du port B

btfsc INTCON,0
goto declench
goto fin

declench: movlw B'00000001' ; allume
movwf PORTB
call wait

movlw B'00000000' ; éteint
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

fin: bcf INTCON,0 ; met à 0 le drapeau d'interruption PORT B
retfie


; programme principal

main: bcf STATUS,5 ;banque 0
clrf PORTB
bsf STATUS,5 ;banque 1
movlw B'00010000' ;met B4 en entrée
movwf TRISB

bcf STATUS,5 ;banque 0
bsf PORTB,1
call wait
movlw B'00000000' ; raz du registre d'interruption
movwf INTCON
bsf INTCON,3 ; autorise l'interruption du port B
bsf INTCON,7 ; autorise les interruptions

final: nop ; boucle sans fin d'attente des interruptions
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



END ; directive 'end of program'