Académique Documents
Professionnel Documents
Culture Documents
MICROPROCESADORES
Interrupciones
Fuentes de Interrupciones para el PIC16F874/877
MICROPROCESADORES
Interrupciones
Fuentes de Interrupciones para el PIC16F874/877
MICROPROCESADORES
Interrupciones
Como se atiende una Interrupcin
PILA
Dir_04
Programa
Principal
Dir_01
Dir_02
Dir_03
Dir_04
Dir_05
Dir_SUMA
Dir_07
Dir_08
Dir_09
BSF
03,5
BCF
03,6
MOVF 3F,0
CALL SUMA
GOTO 000h
BCF
03,5
BSF
03,6
ADDWF 5A,1
RETURN
Sub-Rut
Interrupcin
RETFIE
MICROPROCESADORES
Interrupciones
Fuentes de Interrupciones a estudiar
Interrupcin externa a
travs del pin RB0/INT
MICROPROCESADORES
Interrupciones
IOCEP
IOCEN
IOCEF
IOCAP
IOCAN
IOCAF
IOCBP
IOCBN
IOCBF
Interrupcin por
cambio de nivel
IOCCP
IOCCN
IOCCF
MICROPROCESADORES
Interrupciones
Registros del rea SFR que se utilizan con las Interrupciones
INTCON
OPTION_REG
PIE1
PIR1
PIE2
PIR2
PIE3
PIR3
PIE4
PIR4
ICOxx
Interrupciones
Banco 0
000h
Banco 1
080h
Registros de Nucleo
00Bh
08Bh
Registros de Nucleo
Banco 7
380h
38Bh
Registros de Ncleo
00Ch
PORTA
08Ch
TRISA
38Ch
00Dh
PORTB
08Dh
TRISB
38Dh
INLVLB
00Eh
PORTC
08Eh
TRISC
38Eh
INLVLC
00Fh
PORTD
08Fh
TRISD
38Fh
INLVLD
010h
PORTE
090h
TRISE
390h
INLVLE
011h
PIR1
091h
PIE1
391h
IOCAP
012h
PIR2
092h
PIE2
392h
IOCAN
013h
PIR3
093h
PIE3
393h
IOCAF
014h
PIR4
094h
PIE4
394h
IOCBP
015h
TMR0
095h
OPTION_REG
395h
IOCBN
016h
TMR1L
096h
PCON
396h
IOCBF
017h
TMR1H
097h
WDTCON
397h
IOCCP
018h
T1CON
098h
OSCTUNE
398h
IOCCN
019h
T1GCON
099h
OSCCON
399h
IOCCF
01Ah
TMR2
09Ah
OSCSTAT
39Ah
01Bh
PR2
09Bh
ADRESL
39Bh
01Ch
T2CON
09Ch
ADRESH
39Ch
01Dh
09Dh
ADCON0
39Dh
IOCEP
01Eh
09Eh
ADCON1
39Eh
IOCEN
01Fh
09Fh
ADCON2
39Fh
IOCEF
020h
0A0h
Registros de proposito general
80 Bytes
3A0h
Registros de proposito
general 80 bytes
Registros de proposito
general 80 Bytes
06Fh
0EFh
3EFh
070h
0F0h
3F0h
INLVLA
3FFh
MICROPROCESADORES
Interrupciones
00H
0BH
0CH
1FH
Registros de funciones
especiales 20 bytes mximo
20H
INDF0
INDF1
PCL
STATUS
FSR0L
FSR0H
FSR1L
FSR1H
BSR
WREG
PCLATH
INTCON
6FH
70H
RAM comn (16 bytes)
7FH
MICROPROCESADORES
Interrupciones
REGISTRO DE CONTROL DE INTERRUPCION: INTCON
Bit 7
GIE
Bit 0
PEIE
TMR0IE
INTE
IOCIE
TMR0IF
INTF
IOCIF
MICROPROCESADORES
Interrupciones
REGISTRO DE CONTROL DE INTERRUPCION: INTCON
Bit 7
GIE
Bit 0
PEIE
TMR0IE
INTE
IOCIE
TMR0IF
INTF
IOCIF
MICROPROCESADORES
Interrupciones
REGISTRO OPCION : OPTION_REG
Bit 7
WPUEN
Bit 0
INTEDG
TMR0CS
TMR0SE
PSA
PS<2,0>
1: Flanco Ascendente.
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 1: PIE1
Bit 7
TMR1GIE
Bit 0
ADIE
RCIE
TXIE
SSP1IE
CCP1IE
TMR2IE
TMR1IE
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 1: PIE1
Bit 7
TMR1GIE
Bit 0
ADIE
RCIE
TXIE
SSP1IE
CCP1IE
TMR2IE
TMR1IE
SSP1IE: Bit de habilitacin de interrupcin por transferencia en el puerto serial sncrono (MSSP)
1 = Habilita la interrupcin por transferencia en el puerto serial sncrono (MSSP)
0 = Deshabilita la interrupcin por transferencia en el puerto serial sncrono (MSSP)
CCP1IE: Bit de habilitacin de interrupcin del CCP1
1 = Habilita la interrupcin del CCP1
0 = Deshabilita la interrupcin del CCP1
TMR2IE: Bit de habilitacin de interrupcin al igualarse TMR2 con PR2
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 2: PIE2
Bit 7
OSFIE
Bit 0
C2IE
C1IE
EEIE
BCL1IE
C4IE
C3IE
CCP2IE
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 2: PIE2
Bit 7
OSFIE
Bit 0
C2IE
C1IE
EEIE
BCL1IE
C4IE
C3IE
CCP2IE
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 3: PIE3
Bit 7
Bit 0
CCP3IE
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 4: PIE4
Bit 7
Bit 0
PSMC3TIE
PSMC2TIE
PSMC1TIE
PSMC3SIE
PSMC2SIE
PSMC1SIE
MICROPROCESADORES
Interrupciones
REGISTRO DE HABILITACION DE INTERRUPCION DE PERIFERICOS 4: PIE4
Bit 7
Bit 0
PSMC3TIE
PSMC2TIE
PSMC1TIE
PSMC3SIE
PSMC2SIE
PSMC1SIE
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 1: PIR1
Bit 7
TMR1GIF
Bit 0
ADIF
RCIF
TXIF
SSP1IF
CCP1IF
TMR2IF
TMR1IF
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 1: PIR1
Bit 7
TMR1GIF
Bit 0
ADIF
RCIF
TXIF
SSP1IF
CCP1IF
TMR2IF
TMR1IF
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 2: PIR2
Bit 7
OSFIF
Bit 0
C2IF
C1IF
EEIF
BCL1IF
C4IF
C3IF
CCP2IF
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 2: PIR2
Bit 7
OSFIF
Bit 0
C2IF
C1IF
EEIF
BCL1IF
C4IF
C3IF
CCP2IF
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 3: PIR3
Bit 7
Bit 0
CCP3IF
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 4: PIR4
Bit 7
Bit 0
PSMC3TIF
PSMC2TIF
PSMC1TIF
PSMC3SIF
PSMC2SIF
PSMC1SIF
MICROPROCESADORES
Interrupciones
REGISTRO DE SOLICITUD DE INTERRUPCION DE PERIFERICOS 4: PIR4
Bit 7
Bit 0
PSMC3TIF
PSMC2TIF
PSMC1TIF
PSMC3SIF
PSMC2SIF
PSMC1SIF
MICROPROCESADORES
Interrupciones
REGISTRO DE INTERRUPCION POR CAMBIO, FLANCO DE SUBIDA: IOCxP
Bit 7
IOCxP7
Bit 0
IOCxP6
IOCxP5
IOCxP4
IOCxP3
IOCxP2
IOCxP1
IOCxP0
IOCxP <7:0>: Bits de habilitacin individual para interrupcin por cambio de nivel por flanco de subida (1)
1 = interrupcin por cambio de nivel por flanco de subida es habilitado en el pin asociado y el indicador de
interrupcin respectivo se seteara tras la deteccin de un flanco positivo
0 = interrupcin por cambio de nivel por flanco de subida es deshabilitado para el pin asociado.
IOCxN7
Bit 0
IOCxN6
IOCxN5
IOCxN4
IOCxN3
IOCxN2
IOCxN1
IOCxN0
IOCxN <7:0>: Bits de habilitacin individual para interrupcin por cambio de nivel por flanco de bajada (1)
1 = interrupcin por cambio de nivel por flanco de bajada es habilitado en el pin asociado y el indicador de
interrupcin arespectivo se seteara tras la deteccin de un flanco negativo
0 = interrupcin por cambio de nivel por flanco de bajada es deshabilitado para el pin asociado.
UNEXPO Pto. Ordaz.
MICROPROCESADORES
Interrupciones
REGISTRO BANDERA DE INTERRUPCION POR CAMBIO: IOCxF
Bit 7
IOCxF7
Bit 0
IOCxF6
IOCxF5
IOCxF4
IOCxF3
IOCxF2
IOCxF1
IOCxF0
Nota 1: Para el registro IOCEF , el bit 3 (IOCEF3) es el nico bit implementado en el Registro
MICROPROCESADORES
Interrupciones
Lgica de interrupcin
MICROPROCESADORES
Interrupciones
Vector de Interrupcin
Es la direccin donde debe colocarse la primera
instruccin de la Sub-Rutina de atencin de
interrupcin
El vector de Interrupcin para el PIC16F87X es:
Dir. 0004
MICROPROCESADORES
Interrupciones
Como se atiende una Interrupcin con el PIC
PILA
Dir_SUMA
Programa
Principal
Dir_01
Dir_02
Dir_03
Dir_04
Dir_05
Dir_SUMA
Dir_07
Dir_08
Dir_09
BSF
03,5
BCF
03,6
MOVF 3F,0
CALL SUMA
GOTO 000h
BCF
03,5
BSF
03,6
ADDWF 5A,1
RETURN
Sub-Rut
Interrupcin
0004
RETFIE
MICROPROCESADORES
Interrupciones
Prioridades en la interrupciones
MICROPROCESADORES
Interrupciones
1er Caso: se atiende primero INT
Dir 0004
INTF=1
SI
INTF0
ORG
BTFSC
GOTO
BTFSC
GOTO
RETFIE
0004
INTCON,INTF
Sub_Rut_INT
INTCON,IOCIF
Sub_Rut_RB
Sub_Rut_INT
NO
IOCIF=1
SI
IOCIF0
Sub_Rut_RB
NO
RETFIE
MICROPROCESADORES
Interrupciones
2do Caso: se atiende primero IOCIF
Dir 0004
IOCIF=1
SI
IOCIF0
ORG
BTFSC
GOTO
BTFSC
GOTO
RETFIE
0004
INTCON,IOCIF
Sub_Rut_RB
INTCON,INTF
Sub_Rut_INT
Sub_Rut_RB
NO
INTF=1
SI
INTF0
Sub_Rut_INT
NO
RETFIE
MICROPROCESADORES
Interrupciones
OPERACIN GENERAL DE INTERRUPCION
Las interrupciones estn deshabilitadas despus de cualquier reset del
dispositivo. Ellos se habilitan mediante la configuracin de los siguientes bits:
Bit de habilitacin general GIE del registro INTCON
Bit de habilitacin individual en los registros PIE1, PIE2, PIE3, PIE4 o
INTCON.
Bit de habilitacin de perifricos PEIE en el registro INTCON (si la interrupcin
del evento est contenido en el Registros PIE1, PIE2, PIE3 o PIE4 ) Los
registros INTCON, PIR1, PIR2, PIR3 o PIR4 graban la solicitud de interrupcin.
El bit de la bandera de interrupcin se setea, sin importar el estado de la GIE,
PEIE y la habilitacin individual de la interrupcin.
Los siguientes eventos ocurren cuando un evento de interrupcin ocurre
mientras el bit GIE esta seteado:
Pre-busqueda de instruccin se vaca
Bit GIE se borra
Contador de Programa actual (PC) con la direccin de retorno se graba en la
pila
Registros crticos se guardan automticamente en los registros de sombra
PC se carga con el vector de interrupcin 0004h
UNEXPO Pto. Ordaz.
MICROPROCESADORES
Interrupciones
El firmware dentro de la rutina de servicio de interrupcin (ISR) debe
determinar el origen de la interrupcin encuestando los bits de las banderas
de interrupcin individuales. Los bits de la bandera de interrupcin deben ser
limpiado antes de salir del ISR para evitar repetir la interrupcin. Debido a que
el bit GIE est desactivado, cualquier interrupcin que se produce durante la
ejecucin de la ISR se grabar a travs de su indicador de interrupcin, pero
no har que el procesador redirija al vector de interrupcin.
La instruccin RETFIE hace salir del ISR y recupera de la pila la direccin
anterior, restaura los registros crticos de los registros sombra y restaura el bit
GIE.
MICROPROCESADORES
Interrupciones
Al entrar en una interrupcin, la direccin de retorno PC es guardado en la
pila. Adems, los siguientes registros se guardan automticamente en los
registros de la sombra:
Registro W
Registro STATUS (a excepcin de TO y PD)
Registro BSR
Registros FSR
Registro PCLATH
Al salir de la rutina de servicio de interrupcin, estas registros se restauran
automticamente. Cualquier modificacin en estos registros durante el ISR se
perdern. Si modificaciones a cualquiera de estos registros se desean, el
correspondiente registro sombra debe ser modificado y el valor se restablece
al salir de la ISR. La registros de sombra estn disponibles en el Banco 31
son lectura y escritura. Dependiendo de la aplicacin del usuario, tambin
pueden ser salvado otros registros.
MICROPROCESADORES
Interrupciones
Registros Sombra
Banco 31
F80h
F8Ch
Registros de Nucleo
F8Bh
F8Ch
Ver tabla
FEFh
FF0h
FFFh
STATUS_SOMBRA
WREG_SOMBRA
BSR_SOMBRA
PCLATH_SOMBRA
FSR0L_SOMBRA
FSR0H_SOMBRA
FSR1L_SOMBRA
FSR1H_SOMBRA
STKPTR
TOSL
TOSH
MICROPROCESADORES
Interrupciones
MICROPROCESADORES
Interrupciones
ORG 0x00
GOTO inicio
ORG 0x04
GOTO ISR
inicio
sueo
ORG 0X05
BANKSEL TRISB
MOVLW 0x01
MOVWF TRISB
BANKSEL OPTION_REG
BCF OPTION_REG,6
BSF INTCON,GIE
BSF INTCON,INTE
BANKSEL PORTB
CLRF PORTB
SLEEP
GOTO sueo
; configurando puertos
; carga w con 0000 0001
; RB0/INT es entrada
; seleccionamos flanco descendente
;-------Habilitacin de interrupciones------; habilitamos todas las interrupciones
; que sean interrupciones externas
; limpio el puerto B
; Lazo principal
MICROPROCESADORES
Interrupciones
Sub-rutina de Interrupcin sencilla
;-------------Rutina de servicio de interrupciones------------ISR
off_led
BTFSC PORTB,0
GOTO ISR
BTFSC PORTB,1
GOTO off_led
BSF PORTB,1
BCF INTCON,INTF
RETFIE
BCF PORTB,1
BCF INTCON,INTF
RETFIE
END
MICROPROCESADORES
Interrupciones
MICROPROCESADORES
Interrupciones
MICROPROCESADORES
Interrupciones
ORG 0X00
GOTO INICIO
ORG 0X04
CALL RUT_INT
BCF INTCON,INTF
BCF INTCON,IOCIF
RETFIE
ORG 0X500
RUT_INT
BTFSC INTCON,INTF
CALL SUB_RUT_INT
BTFSC INTCON,IOCIF
CALL SUB_RUT_IOC
RETURN
SUB_RUT_INT
MOVLW b'11000000' ;
BANKSEL PORTD
MOVWF PORTD
RETURN
UNEXPO Pto. Ordaz.
NUMERO 0
MICROPROCESADORES
Interrupciones
SUB_RUT_IOC
BANKSEL IOCBF
BTFSC IOCBF,IOCBF4
CALL NUM_4
BTFSC IOCBF,IOCBF5
CALL NUM_5
BTFSS IOCBF,IOCBF6
CALL NUM_6
BTFSS IOCBF,IOCBF7
CALL NUM_7
RETURN
;FUE RB4?
;FUE RB7?
NUM_4
BANKSEL PORTD
MOVLW b'10011001'
MOVWF PORTD
RETURN
NUM_5
BANKSEL PORTD
MOVLW b'10010010'
MOVWF PORTD
RETURN
NUM_6
BANKSEL PORTD
MOVLW b'10000010'
MOVWF PORTD
RETURN
MICROPROCESADORES
Interrupciones
NUM_7
BANKSEL PORTD
MOVLW b'11111000'
MOVWF PORTD
RETURN
;-------------------------------------------------------------------------ORG 0X09
INICIO
BANKSEL 0
BSF INTCON,GIE
BSF INTCON,INTE
RB0/INT
BSF INTCON,IOCIE
BANKSEL OPTION_REG
BCF OPTION_REG,7
BSF OPTION_REG,INTEDG
BANKSEL IOCBP
MOVLW 0xF0
MOVWF IOCBP
BANKSEL WPUB
MOVLW 0xF0
MOVWF WPUB
BANKSEL TRISB
MOVLW 0XF1
MOVWF TRISB
MOVLW 0X00
MOVWF TRISD
BANKSEL 0
MICROPROCESADORES
Interrupciones
MOVLW 0xF1
MOVWF ANSELB
MOVLW 1
MOVWF ANSELD
LETRA_P
MOVLW b'10001100'
MOVWF PORTD
;MUESTRA P EN EL
DISPLAY
CICLO
BTFSC PORTB,RB0
GOTO CICLO
BTFSC PORTB,RB4
GOTO CICLO
BTFSC PORTB,RB5
GOTO CICLO
BTFSC PORTB,RB6
GOTO CICLO
BTFSC PORTB,RB7
GOTO CICLO
GOTO LETRA_P
END
;RB0=0?
;RB4=0?
;RB5=0?
;RB6=0?
;RB7=0?
MICROPROCESADORES