Вы находитесь на странице: 1из 21

MICROCONTROLADORES

Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES EN
MICROCONTROLADOR PIC

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTRODUCCION

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES

POSICION DEL VECTOR


DE INTERRUPCION

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES

Lectura de entrada mediante consulta (tecnica Polling) Lectura de entrada mediante interrupcion

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

COMO FUNCIONA UNA INTERRUPCION?

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

FUENTES DE INTERRUPCION EN EL PIC16F84A

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES
(Registro INTCON)

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES
(Registro OPTION)

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCION EXTERNA RB0/INT

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCION EXTERNA RB7:RB4

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES EN C

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCIONES EN C

El compilador C incluye funciones para el manejo de las directivas de interrupcion:

Enable_interrupts (nivel): nivel es una constante definida en un fichero de cabecera


(ejm: 16F87X.h), y genera el codigo necesario para activar las mascaras
correspondientes, afectando los correspondientes vectores de interrupcion (INTCON
entre otros)

Habilitar Interrupcion RB0/INT

Parte del fichero 16F873.h


Habilitar Interrupcion [RB7:RB4]

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCION EXTERIOR POR RB0

Es una interrupcion basica comun en la mayoria de los PIC. Permite generar


una interrupcion tras el cambio de nivel (paso de bajo a alto -falling_edge- o
de alto a bajo – rising_edge-) en la entrada RB0.

La directiva utilizada es INT_EXT y se debe acompanar de las siguientes funciones:

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

TECNICA POLLING
La tecnica polling es el metodo usado para determinar el estado de una
entrada digita en un microcontrolador, y consiste basicamente en estar
“preguntando constantemente” por dicho estado.

ESCLAVIZAR EL SISTEMA EN UNA TAREA DETERMINADA


“Testear el estado de un bit de Entrada”

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
/* *********************** CONTADOR_POLLING.C ************************** Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge
************************************************************************

Descripción: Incrementar la variable CONTADOR mediante testeo periódico del botón de


entrada conectado al pin RA0 (Técnica POLLING).

La variable CONTADOR se visualiza mediante LCD.

Autor: Ing. Ilber Adonayt Ruge R.


Docente Microcontroladores
Universidad Pedagógica y Tecnológica de Colombia 2013
*/

#INCLUDE <16F873A.H>
#FUSES XT,NOWDT,PUT,NOWRT,NOPROTECT,NOLVP
#USE DELAY(CLOCK=4000000)
#INCLUDE <FLEXLCD.C>

INT CONTADOR=0;

VOID MAIN(){ //PROGRAMA PRINCIPAL

LCD_INIT(); //INICIALIZAR LCD

WHILE(TRUE){ //CICLO INFINITO

IF (!INPUT(PIN_A0)) //PREGUNTA SI RAO=0 INCREMENTAR CONTADOR


CONTADOR++; //TECNICA POLLING O TESTEO PERIODICO DE ESTADOS

PRINTF(LCD_PUTC,"\fCONTADOR: %u", CONTADOR);


DELAY_MS(200);
} ESCLAVIZAR EL SISTEMA EN UNA TAREA DETERMINADA
} “Testear el estado de un bit de Entrada”

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

TECNICA POLLING

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCION EXTERNA INT/RB0


La utilización de interrupción por cambio de estado en el PIN_B0
(INT_EXT) libera al programa del testeo periódico de la variable de
entrada, permitiendo al programa principal realizar de manera mas
optima las tareas propias de un programa principal

Libera al programa principal de ocuparse de un testeo


permanente

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
/* ******************* CONTADOR_INT_RB0.C ******************* Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

Descripción: Incrementar la variable CONTADOR utilizando rutina de atención a interrupción por cambio de
estado en el pin RB0. La variable contador se muestra mediante LCD.

Autor: Ing. ILBER ADONAYT RUGE RUGE


Docente Microcontroladores
Universidad Pedagógica y Tecnológica de Colombia 2013
*/

#INCLUDE <16F873A.H>
#FUSES XT,NOWDT,PUT,NOWRT,NOPROTECT,NOLVP
#USE DELAY(CLOCK=4000000)
#INCLUDE <FLEXLCD.H>

INT CONTADOR=0;

#INT_EXT //RUTINA DE ATENCION A INTERRUPCION INT/RB0


EXT_ISR(){ //INCREMENTAR VARIABLE CONTADOR
DELAY_MS(100);
CONTADOR++;
}

VOID MAIN(){ //PROGRAMA PRINCIPAL

LCD_INIT();
SET_TRIS_B(0X01);
Libera al programa principal de ocuparse de un
EXT_INT_EDGE(H_TO_L); //FLANCO ASCENDENTE PARA RB0/INT testeo permanente
ENABLE_INTERRUPTS(INT_EXT); //HABILITAR INTERRUPCION RB0/INT
ENABLE_INTERRUPTS(GLOBAL); //HABILITAR INTERRUPCIONES GLOBALES

WHILE(TRUE){ //CICLO INFINITO

PRINTF(LCD_PUTC,"\fCONTADOR: %u",CONTADOR); //MOSTRAR CONTENIDO DE CONTADOR


DELAY_MS(200);
}
}

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

INTERRUPCION EXTERNA INT/RB0

Fuente: Compilador CCS y simulador Proteus, Alfaomega


MICROCONTROLADORES
Docente: Ing. M.Sc. Ilber Adonayt Ruge Ruge

EJERCICIOS PROPUESTOS PARA MANEJO DE


INTERRUPCIONES EN LEANGUAJE ASM Y
LENGUAJE C
EJERCICIO 1

EJERCICIO 2

EJERCICIO 3: Cada vez que se presiona cualquiera de los pulsadores


conectados en RB4:RB7, se debe visualizar en el modulo LCD la respectiva
tecla presionada . La lectura de los pulsadores se hara mediante
interrupciones.

Nota: Use librería para manejo de LCD


Fuente: Compilador CCS y simulador Proteus, Alfaomega

Вам также может понравиться