4 chapter 4 interrupt module

21 122 0
4  chapter 4   interrupt module

Đ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

MICROCONTROLLERS CHAPTER 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!  2011 – Vo Tuong Quan INTERRUPTS How many types of connection between MCU and external devices? 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 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  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  2011 – Vo Tuong Quan INTERRUPTS Interrupt priority?  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  2011 – Vo Tuong Quan INTERRUPTS Interrupt types EEIF - EEPROM Write Operation Interrupt Flag bit PSPIF – Parallel Slave Port Read/Write Interrupt Flag bit ADIF - A/D Converter Interrupt Flag bit RCIF - USART Receive Interrupt Flag bit TXIF - USART Transmit Interrupt Flag bit SSPIF - Synchronous Serial Port (SSP) Interrupt Flag bit CCP1IF - CCP1 Interrupt Flag bit TMR2IF - TMR2 to PR2 Match Interrupt Flag bit TMR1IF - TMR1 Overflow Interrupt Flag bit 10.CCP2IF - CCP2 Interrupt Flag bit 11.BCLIF - Bus Collision Interrupt Flag bit 12.T0IF – Timer interrupt flag 13.INTF - RB0/INT External Interrupt Flag bit 14.RBIF - RB Port Change Interrupt Flag bit  2011 – Vo Tuong Quan INTERRUPTS Interrupt types What are the difference between RBIF and EXT (External Interrupts)?  2011 – Vo Tuong Quan INTERRUPTS Interrupt function What are the functions of interrupts?  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 (PORTB + + )  the last bit (LSB) will vary each cycle of the program from "0" to "1" and vice versa  cause the INTF flag 00000000 to be set a change from to 00000001 00000010 00000011 00000100 00000101 00000110  2011 – Vo Tuong Quan 00000111 a change from to a change from to a change from to 11 INTERRUPTS Example (Cont’d) – Sample code #include int i=0; int j=0; interrupt beep(void) // Interrupt function definition { if (INTF) // If the external flag is 1, { INTF=0; // Reset the external interrupt flag for(i=0;i

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