0% found this document useful (0 votes)
298 views21 pages

Chapter 4 - Interrupt Module

The document discusses interrupts in microcontrollers. It defines an interrupt as a signal sent to the microcontroller to mark an event that requires immediate attention, causing the processor to stop its current program and execute interrupt service code. There are two types of interrupts: software interrupts, which are caused by procedure calls, and hardware interrupts, which are triggered by external devices. Interrupts have priority levels and there are multiple interrupt sources including timers, ports, and analog-to-digital converters. Interrupts preempt the main program to allow for real-time response to external events. Example code is provided to illustrate using interrupts to light an LED in response to port changes.

Uploaded by

nam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
298 views21 pages

Chapter 4 - Interrupt Module

The document discusses interrupts in microcontrollers. It defines an interrupt as a signal sent to the microcontroller to mark an event that requires immediate attention, causing the processor to stop its current program and execute interrupt service code. There are two types of interrupts: software interrupts, which are caused by procedure calls, and hardware interrupts, which are triggered by external devices. Interrupts have priority levels and there are multiple interrupt sources including timers, ports, and analog-to-digital converters. Interrupts preempt the main program to allow for real-time response to external events. Example code is provided to illustrate using interrupts to light an LED in response to port changes.

Uploaded by

nam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

MICROCONTROLLERS

CHAPTER 4
INTERRUPTS MODULE

Dr. Vo Tuong Quan

HCMUT - 2011
INTERRUPTS
Definition
What is interrupt?
“Interrupt is the signal sent to the micro to mark the event that
requires immediate attention”

Interrupt is “asking" the processor to stop to perform the


current program and to “make time” to execute a special
code.

The method of interrupt defines the option to transfer the


information generated by internal or external systems inside
the micro by them self!

2
 2011 – Vo Tuong Quan
INTERRUPTS
How many types of connection between MCU and
external devices?
1. Polling
- MCU accesses at the exact time interval the external
device, and gets the required information.
- The processor must access the device itself and request
the desired information that is needed to be processed.
- Waste of time: The micro needs to wait and review whether
a new information arrived.
2. Interrupt
- Interrupt is the signal sent to the micro to mark the event
that requires immediate attention.
- Interrupt is “asking" the processor to stop to perform the
current program and to “make time” to execute a special
code.
3
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt sources?
- Software Interrupt
Example: Procedure - when there is a procedure call, the
processor stops the execution of the program, jumps to the
place in memory that reserved for a procedure – executes
the procedure and only then returns back to the program
and continues to execute.
- Hardware Interrupt
The hardware interrupts are sent to the microcontroller by
external hardware devices.

4
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt priority?

5
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt types
There are normally 14 interrupt type
XXXIF is an interrupt flag that shows the result that we are
getting from an interrupt.
XXXIE is an interrupt enable bit that is used to enable or
“block” the interrupt.
We can determine whether or not to allow the system to
address the interrupts. This is done by using Global
Interrupt Enable bit GIE.

The method to use Interrupt (2 steps)


Step 1: Active the GIE bit
Step 2: Active the Interrupt type to be used.

6
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt types
1. EEIF - EEPROM Write Operation Interrupt Flag bit
2. PSPIF – Parallel Slave Port Read/Write Interrupt Flag bit
3. ADIF - A/D Converter Interrupt Flag bit
4. RCIF - USART Receive Interrupt Flag bit
5. TXIF - USART Transmit Interrupt Flag bit
6. SSPIF - Synchronous Serial Port (SSP) Interrupt Flag bit
7. CCP1IF - CCP1 Interrupt Flag bit
8. TMR2IF - TMR2 to PR2 Match Interrupt Flag bit
9. TMR1IF - TMR1 Overflow Interrupt Flag bit
10.CCP2IF - CCP2 Interrupt Flag bit
11.BCLIF - Bus Collision Interrupt Flag bit
12.T0IF – Timer 0 interrupt flag
13.INTIF - RB0/INT External Interrupt Flag bit
14.RBIF - RB Port Change Interrupt Flag bit
7
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt types
What are the difference between RBIF and EXT (External
Interrupts)?

8
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt function
What are the functions of interrupts?

9
 2011 – Vo Tuong Quan
INTERRUPTS
Interrupt function
The interrupt functions is called by the hardware itself and
operates by following steps:

Step 1: After the interrupt function is loaded into the memory,


the function waits for a moment for the interrupt to occur.

Step 2: When the interrupt has occurred, the operating system


stops the execution of the main function and “free itself” to
perform the interrupt function.

Step 3: After the execution of the interrupt function, the


operating system continues to run the main function from the
place it stopped before the interrupt has occurred.
10
 2011 – Vo Tuong Quan
INTERRUPTS
Example 1:
Suppose that the external interrupts is connected to PORTB pin
RB0. The program will play a sound from a buzzer that is
located on the PIC development board, every time there is an
external interrupt that is generated through RB0 pin.
Solution:
Suppose that we will increase the value of PORTB by 1
(PORTB + + )  the last bit (LSB) will vary each cycle of the
program from "0" to "1" and vice versa  cause the INTIF flag
to be set. 00000000
a change from 0 to 1
00000001
00000010
a change from 0 to 1
00000011
00000100
a change from 0 to 1
00000101
00000110 11
a change from 0 to 1
 2011 – Vo Tuong Quan 00000111
INTERRUPTS

Example 1 (Cont’d) – Sample code


#include <picxxxx.h>
int i=0;
int j=0;

interrupt beep(void) // Interrupt function definition


{
if (INTIF ) // If the external flag is 1, do .....
{
INTIF=0; // Reset the external interrupt flag
PORTC.0=1;
}
}

12
 2011 – Vo Tuong Quan
INTERRUPTS
Example 1 (Cont’d) – Sample code
void main(void)
{
TRISB=0; // Set PORT B as an OUTPUT
TRISC=0; // Set PORT C as an OUTPUT
PORTC=0; // Set the value of PORT C to 0
INTIF=0; // Reset the external interrupt flag
INTIE=1; // Enable external interrupts from RB0
GIE=1; // Global interrupt enable
while(1)
{
PORTB++;// Increase the PORT B value by 1.
for(i=0;i<30000;i++); // a simple delay
}
}

13
 2011 – Vo Tuong Quan
INTERRUPTS
Example 2 - Read the circuit, the following code and show up
the purpose of the program

14
 2011 – Vo Tuong Quan
INTERRUPTS
Example 2 (Cont’d)

15
 2011 – Vo Tuong Quan
INTERRUPTS
Example 2 - Read the circuit, the following code and add in
more sub programs to make the full program.

16
 2011 – Vo Tuong Quan
INTERRUPTS
Example 2 (Cont’d)

17
 2011 – Vo Tuong Quan
INTERRUPTS
Example 2 (Cont’d)
What should we input more in the following program?

18
 2011 – Vo Tuong Quan
INTERRUPTS
Using functions of CCS-C Compiler
enable_interrupts ( level )
disable_interrupts ( level )
ext_int_edge ( source , edge )

19
 2011 – Vo Tuong Quan
INTERRUPTS
Example 3:
Find the errors in the circuit and codes and show the solutions.

20
 2011 – Vo Tuong Quan
INTERRUPTS
Example 3: (Cont’d)
#include < 16F877.h > void main ( )
#device PIC16F877 *=16 { set_tris_b ( 0xF0 ) ;
#use delay (clock = 20000000 ) set_tris_d ( 0x00 ) ;
#byte portb = 0x06 enable_interrupts ( INT_RB ) ;
#byte portd = 0x08 enable_interrupts ( GLOBAL ) ;
while( true )
#INT_RB {
Void RB_LED ( ) }
{ }
portd=portb;
}

21
 2011 – Vo Tuong Quan

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy