Vous êtes sur la page 1sur 6

INSTITUTO POLITÉCNICO

NACIONAL
Escuela Superior de Ingeniería Mecánica y
Eléctrica “ESIME”

MICROPROCESADORES

PRACTICA 4. INTERRUPCION

Profesor: Agustín Vázquez Zarate


Objetivo:

Programar una interrupción de forma automática con el PIC 18F4550 , asiéndolo visible al
apretar un push botón conectado a un DIODO LED

Introducción:

Una interrupción es un evento que hace que el microcontrolador deje de ejecutar la tarea
que está realizando para atender dicho acontecimiento y luego regrese y continue la tarea
que estaba realizando antes de que se presentara la interrupción. El pic 16F628 (y el
16F628A) tiene 10 fuentes de interrupción, si las interrupciones están habilitadas cada vez
que una de estos acontecimientos se presente el pic dejará de ejecutar el programa para ir
a atender la interrupción y al termino de la misma continuará ejecutando el programa donde
lo había dejado. Las fuentes de interrupción son:

 Interrupción externa RB0/INT


 Interrupción por cambio lógico en el puerto B (pines RB7 a RB4)
 Interrupción por desborde del timer 0 (TMR0)
 Interrupción por desborde del timer 1 (TMR1)
 Interrupción por comparación exitosa exitosa en TMR2
 Interrupción del comparador
 Interrupción del transmisor del USART
 Interrupción del receptor del USART
 Interrupción del módulo CCP
 Interrupción del EEPROM
Aunque el pic cuenta con 10 fuentes distintas de interrupción solamentetiene un vector de
interrupción por lo que si se habilitan varias interrupciones al momento de presentarse
cualquiera de ellas el programa saltara a la misma rutina de interrupcion y es
responsabilidad del programador crear una rutina que identifique la fuente de la
interrupcion.

Los registros asociados con las interrupciones son el registro de control de


interrupcionINTCON, el registro habilitacion de interrupciones de perifericos PIE1 y
el registro de interrupciones de perifericos PIR1. En el registro INTCON se encuentra el bit
de habilitacion global de interrupciones GIE, el bit de habilitacion de interrupcion por
perifericos PEIE y los bits de habilitacion de algunas interrupciones como la interrupcion
externa del pin RB0(INTE), la interrupcion por cambio de estado en los pines RB4 a
RB7 (RBIE) y la interrupcion por desborde del timer 0 (T0IE), asi como las banderas
correspondientes a cada interrupcion (INTF, RBIF y T0IF). En el registro PIE1 se
encuentran los bits de habilitacion de las demas interrupciones y en el registro PIR1 se
encuentran las banderas asociadas con cada interrupcion.

Para habilitar las interrupciones se deben seguir los siguientes pasos:


 Habilitar el bit correspondiente a cada interrupcion.
 Limpiar la bandera correspondiente a la interrupcion habilitada para evitar falsas
interrupciones.
 En caso de ser necesario habilitar el bit PEIE del registro INTCON (necesario para todas
las interrupciones con excepcion de INTE y RBIE).
 Habilitar el bit de habilitacion global de interrupciones GIE del registro INTCON.
En el codigo tambien es necesario indicar hacia que rutina debe saltar el programa al
presentarse la interrupción. Ya se dijo que el vector de interrupción está en la dirección 0x04
por lo que es necesario agregar las lineas org 0x04 y goto ISR al programa, donde ISR es
la rutina de servicio de interrupción y puede, desde luego, tener cualquier otro nombre.

La ventaja de utilizar interrupciones es que mientras se espera a que se presente el evento


que produce la interrupción el microcontrolador puede estar ejecutando cualquier otra tarea.
De ese modo el micro no esta ciclado en una sola tarea sino que puede seguir trabajando
en otras hasta que una interrupción haga que el programa salte y ejecute la tarea que se
quiera y al terminarla el programa continuara su ejecución en el punto en el que se
encontraba en el momento de presentarse la interrupción.

Código:

;***************************************************************************************************
; This file is a basictemplateforassemblycodefor a PIC18F4550. Copy *
; this file intoyourprojectdirectory and modifyoradd to it as needed. *
; *
; The PIC18FXXXX architectureallowstwointerruptconfigurations. This *
; templatecodeiswrittenforpriorityinterruptlevels and the IPEN bit *
; inthe RCON registermust be set to enableprioritylevels. If IPEN is *
; left in its default zerostate, onlytheinterrupt vector at 0x008 will *
; beused and the WREG_TEMP, BSR_TEMP and STATUS_TEMP variables willnot *
; beneeded. *
; *
; Refer to the MPASM User'sGuideforadditionalinformationonthe *
; features of theassembler. *
; *
; Refer to the PIC18FXX50/XX55 Data Sheetforadditional *
; informationonthearchitecture and instruction set. *
; *
;***************************************************************************************************
; *
; Filename: PlantillaASM *
; Date: 12/01/11 *
; File Version: 1.0 *
; *
; Author: Ing. Alejandro Vicente Lugo Silva *
; Company: Acad. Computación ICE - ESIME Zac. *
; *
;***************************************************************************************************
; *
; Files required: P18F4550.INC *
; *
;***************************************************************************************************

LIST P=18F4550, F=INHX32 ;directive to define processor


#include<P18F4550.INC> ;processorspecific variable definitions

;***************************************************************************************************
;Configuration bits

CONFIG PLLDIV = 5 ;(20 MHz crystalon PICDEM FS USB board)


CONFIG CPUDIV = OSC1_PLL2
CONFIG USBDIV = 2 ;Clocksourcefrom 96MHz PLL/2
CONFIG FOSC = HSPLL_HS
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = OFF
CONFIG BOR = ON
CONFIG BORV = 3
CONFIG VREGEN = ON ;USBVoltageRegulator
config WDT = OFF
config WDTPS = 32768
config MCLRE = ON
config LPT1OSC = OFF
config PBADEN = OFF ;NOTE: modifyingthisvalueherewon'thaveaneffect
;ontheapplication. Seethe top of themain() function.
;By default the RB4 I/O pin isused to detectifthe
;firmwareshouldenterthebootloaderorthemainapplication
;firmwareafter a reset. In order to do this, itneeds to
;configure RB4 as a digital input, therebychangingitfrom
;theresetvalueaccording to thisconfiguration bit.
config CCP2MX = ON
config STVREN = ON
config LVP = OFF
config ICPRT = OFF ; Dedicated In-CircuitDebug/Programming
config XINST = OFF ; Extended Instruction Set
config CP0 = OFF
config CP1 = OFF
config CP2 = OFF
config CP3 = OFF
config CPB = OFF
config CPD = OFF
config WRT0 = OFF
config WRT1 = OFF
config WRT2 = OFF
config WRT3 = OFF
config WRTB = OFF ; Boot Block WriteProtection
config WRTC = OFF
config WRTD = OFF
config EBTR0 = OFF
config EBTR1 = OFF
config EBTR2 = OFF
config EBTR3 = OFF
config EBTRB = OFF
;***************************************************************************************************
;Variabledefinitions
; These variables are onlyneedediflowpriorityinterrupts are used.
; More variables may be needed to store otherspecialfunctionregistersused
; intheinterruptroutines.

;***************************************************************************************************
;Reset vector
; Thiscodewillstartexecutingwhen a resetoccurs.

RESET_VECTOR ORG 0

goto Main ;go to start of maincode

;***************************************************************************************************

;***************************************************************************************************
;Start of mainprogram
; Themainprogramcodeis placed here.
ORG 0x1000
Main ; *** maincodegoeshere **

callconfigptos
call configtimer0

consulta:
btfsc INTCON,TMR0IF
callnuevoretardo
goto consulta

; end of main
;***************************************************************************************************
; Start of subrutines
;***************************************************************************************************
configptos ;sunrutina

movlw 0x0F
movwf ADCON1
clrf TRISA
movlw 0x55
movwf LATA
return

configtimer0 ;subrutins

bcf INTCON,TMR0IF
movlw 0x48
movwf TMR0H
movlw 0xE5
movwf TMR0L
movlw 0x87
movwf T0CON

return

nuevoretardo ;reinici

bcf INTCON,TMR0IF
movlw 0x48
movwf TMR0H
movlw 0xE5
movwf TMR0L
comf LATA

return

;***************************************************************************************************
;End of program
END

Conclusion:

El código de este programa fue mas fácil debido a los conceptos teóricos ya aprendidos,
solo se dificulto en la parte del circuito debido al tipo de tarjeta que estábamos utilizando
no tenía la salida correspondiente y se tuvo que buscar las salidas entre las “rd”

Vous aimerez peut-être aussi