1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

4 chapter 4 interrupt module

21 122 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 21
Dung lượng 1,72 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 1

CHAPTER 4

INTERRUPTS MODULE

Dr Vo Tuong Quan

Trang 2

INTERRUPTS 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 3

INTERRUPTS 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 4

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 byexternal hardware devices

Trang 5

INTERRUPTS Interrupt priority?

Trang 6

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

Trang 7

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.INTF - RB0/INT External Interrupt Flag bit

14.RBIF - RB Port Change Interrupt Flag bit

Trang 8

INTERRUPTS Interrupt types

What are the difference between RBIF and EXT (External Interrupts)?

Trang 9

INTERRUPTS Interrupt function

What are the functions of interrupts?

Trang 10

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.

Trang 11

INTERRUPTSExample 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 12

INTERRUPTS 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 13

INTERRUPTS

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 14

INTERRUPTSExample 2 - Read the circuit, the following code and show up the purpose of the program

Trang 15

INTERRUPTS Example 2 (Cont’d)

Trang 16

INTERRUPTS Example 2 - Read the circuit, the following code and add in more sub programs to make the full program.

Trang 17

INTERRUPTS Example 2 (Cont’d)

Trang 18

INTERRUPTS Example 2 (Cont’d)

What should we input more in the following program?

Trang 19

INTERRUPTS Using functions of CCS-C Compiler

enable_interrupts ( level )

disable_interrupts ( level )

ext_int_edge ( source , edge )

Trang 20

INTERRUPTS Example 3:

Find the errors in the circuit and codes and show the solutions

Trang 21

INTERRUPTS Example 3: (Cont’d)

{ } }

Ngày đăng: 07/11/2017, 14:17

w