You are on page 1of 12

ISTANBUL AYDIN UNIVERSITY

FACULTY OF ENGINEERING
ELECTRICAL & ELECTRONICS ENGINEERING DEPT.

EEE471: EMBEDDED SYSTEM DESIGN

4. PIC16F84A Interrupt Mechanism

Instructor:
Assist. Prof. Dr. Mohammed ALKRUNZ
Electrical & Electronics Engineering Dept.
PIC16F84A- Interrupt
 Interrupt is a mechanism of a microcontroller which enables it to respond to some
events at the moment they occur, regardless of what the microcontroller is doing at
the time.

 After executing an interrupt sub-program (interrupt routine), it continues from that


same point.
Enable Flag
 Sources of Interrupt (4 Sources):

1. Finishing writing data process to EEPROM. (EEIE, EEIF)

2. TMR0 interrupt caused by timer overflow. (T0IE, T0IF)

3. Alteration on RB4 to RB7 pins of port B. (RBIE, RBIF)

4. External interrupt from RB0/INT pin. (INTE, INTF)

Note: for each interrupt source, there are two corresponding pins: an Enable pin (to
activate the interrupt), and a Flag pin (to indicate that an interrupt occurred).

Dr. M. Alkrunz
31.10.2022 2
EEE471: Embedded System Design
PIC16F84A- Interrupt
 Registers Used with Interrupt:

1) Control Interrupt Register (INTCON) “Very important register”

2) Option Register (OPTION_REG) “Very important register”

3) Control EEPROM Register (EECON1) “important in EEPROM topic”

Let us study these registers in details

Dr. M. Alkrunz
31.10.2022 3
EEE471: Embedded System Design
PIC16F84A- Interrupt
 “INTCON” Register

“Global Interrupt Enable” EEPROM TMR0 RB0/INT RB(4-7) Flags of


write overflow external port interrupt for
1: Enable All complete interrupt interrupt change each type
0: Disable All interrupt enable. enable. interrupt source.
enable. enable.
1: Enable 1: Enable 1: Occurred
1: Enable 0: Disable 0: Disable 1: Enable 0: Did not occur
0: Disable 0: Disable
This register contains the enable (activation) pins for each interrupt type source, and it contains
also the flags of them except the flag of EEPROM.

Dr. M. Alkrunz
31.10.2022 4
EEE471: Embedded System Design
PIC16F84A- Interrupt

 “OPTION_REG” Register

This register is very important in this course, and we will take it in details in the topic of
TMR0. But, we are considering it in the topic of interrupt since it contains a pin related to
RB0/INT interrupt source type.

“Interrupt Edge Select”


1: Interrupt on rising edge of RB0/INT.
0: Interrupt on falling edge of RB0/INT.

Dr. M. Alkrunz
31.10.2022 5
EEE471: Embedded System Design
PIC16F84A- Interrupt
 “EECON1” Register

This register is very important in the topic of EEPROM. But, we care on one pin in the
interrupt topic here.

“EEPROM Interrupt Flag”


1: The write operation completed. (Interrupt occurred)
0: The write operation is not complete. (Interrupt did not occur)

 Note that All interrupt source flags are located on “INTCON” register except this one
here.

Dr. M. Alkrunz
31.10.2022 6
EEE471: Embedded System Design
PIC16F84A- Interrupt
 How to make an Interrupt

Dr. M. Alkrunz
31.10.2022 7
EEE471: Embedded System Design
PIC16F84A- Interrupt

 How to make an Interrupt

1) Enable the “GIE” pin (INTCON.GIE) which is the main enable bit for all interrupt
sources.

2) Enable the interrupt source type that you need. Activation is occurred by setting the
corresponding enable pin by “1” from the four sources (EEIE, T0IE, RBIE, INTE)

Example: INTCON.RBIE = 1 or INTCON.INTE = 1

3) Now, the pic is ready for the waiting interrupt to be occurred. When the interrupt is
occurred, directly the corresponding flag will have a value of “1”. Therefore, it is very
important to reset the flag in the program of interrupt.

Dr. M. Alkrunz
31.10.2022 8
EEE471: Embedded System Design
PIC16F84A- Interrupt
Example 1:

Write a program to do the following:

 Continuous flasher on RB1.

 Each click on the push button that connected to RB0 (interrupt source), a toggle on the
led which is connected to RB2 will be achieved.

This means that the first click on RB0,


RB2 will be ON, and in the second click,
RB2 will be OFF, and so on.

Dr. M. Alkrunz
31.10.2022 9
EEE471: Embedded System Design
PIC16F84A- Interrupt
Example 2:

Write a program to do the following:

 A flasher on RA0.

 Use the interrupt method to control the flashing speed of this flasher.

 Use the interrupt on port B change


(RB4 – RB7).

Dr. M. Alkrunz
31.10.2022 10
EEE471: Embedded System Design
*Questions

Dr. M. Alkrunz
31.10.2022 11
EEE471: Embedded System Design
*Thanks
Dr. M. Alkrunz
31.10.2022 12
EEE471: Embedded System Design

You might also like