INTERRUPTS DefinitionThe method of interrupt defines the option to transfer the information generated by internal or external systems inside the micro by them self!... INTERRUPTS Interru
Trang 1CHAPTER 4
INTERRUPTS MODULE
Dr Vo Tuong Quan
Trang 2INTERRUPTS Definition
The method of interrupt defines the option to transfer the information generated by internal or external systems inside the micro by them self!
Trang 3INTERRUPTS How many types of connection between MCU and external devices?
- Waste of time: The micro needs to wait and review whether
a new information arrived
Trang 4INTERRUPTS 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 byexternal hardware devices
Trang 5INTERRUPTS Interrupt priority?
Trang 6INTERRUPTS 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
Trang 7INTERRUPTS 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.INTF - RB0/INT External Interrupt Flag bit
14.RBIF - RB Port Change Interrupt Flag bit
Trang 8INTERRUPTS Interrupt types
What are the difference between RBIF and EXT (External Interrupts)?
Trang 9INTERRUPTS Interrupt function
What are the functions of interrupts?
Trang 10Step 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.
Trang 11INTERRUPTSExample 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 INTF flag
Trang 12INTERRUPTS Example 1 (Cont’d) – Sample code
INTF=0; // Reset the external interrupt flag
for(i=0;i<300;i++) // A loop for creating a beep sound
{
RA4=0; // By setting LED RA4 high and low
RC2=1; // the will blink
for(j=0;j<10;j++); // By setting the RC2 high and low
RA4=1; //freguently, a sound is generated
RC2=0;
for(j=0;j<10;j++);
}
Trang 13INTERRUPTS
Example 1 (Cont’d) – Sample code
void main(void)
{
TRISA=0; // Ser PORT A as an OUTPUT
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
INTF=0; // Reset the external interrupt flag
INTE=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
}
}
Trang 14INTERRUPTSExample 2 - Read the circuit, the following code and show up the purpose of the program
Trang 15INTERRUPTS Example 2 (Cont’d)
Trang 16INTERRUPTS Example 2 - Read the circuit, the following code and add in more sub programs to make the full program.
Trang 17INTERRUPTS Example 2 (Cont’d)
Trang 18INTERRUPTS Example 2 (Cont’d)
What should we input more in the following program?
Trang 19INTERRUPTS Using functions of CCS-C Compiler
enable_interrupts ( level )
disable_interrupts ( level )
ext_int_edge ( source , edge )
Trang 20INTERRUPTS Example 3:
Find the errors in the circuit and codes and show the solutions
Trang 21INTERRUPTS Example 3: (Cont’d)
{ } }