2.6 Interrupts Interrupts are a mechanism of a microcontroller which enables it to respond to some events at the moment they occur, regardless of what microcontroller is doing at the time. This is a very important part, because it provides connection between a microcontroller and environment which surrounds it. Generally, each interrupt changes the program flow, interrupts it and after executing an interrupt subprogram (interrupt routine) it continues from that same point on. One of the possible sources of interrupt and how it affects the main program Control register of an interrupt is called INTCON and can be accessed regardless of the bank selected. Its role is to allow or disallowed interrupts, and in case they are not allowed, it registers single interrupt requests through its own bits. Bit 7 GIE (Global Interrupt Enable bit) Bit which enables or disables all interrupts. Bit 6 EEIE (EEPROM Write Complete Interrupt Enable bit) Bit which enables an interrupt at the end of a writing routine to EEPROM bit 5 T0IE (TMR0 Overflow Interrupt Enable bit) Bit which enables interrupts during counter TMR0 overflow. bit 4 INTE (INT External Interrupt Enable bit) Bit which enables external interrupt from pin RB0/INT. bit 3 RBIE (RB port change Interrupt Enable bit) Enables interrupts to occur at the change of status of pins 4, 5, 6, and 7 of port B. bit 2 T0IF (TMR0 Overflow Interrupt Flag bit) Overflow of counter TMR0. bit 1 INTF (INT External Interrupt Flag bit) External interrupt occurred. bit 0 RBIF (RB Port Change Interrupt Flag bit) Bit which informs about changes on pins 4, 5, 6 and 7 of port B. PIC16F84 has four interrupt sources: Common error: saving the value wasn't done before entering the interrupt routine Due to simplicity and frequent usage, these parts of the program can be made as macros. The concept of a Macro is explained in "Program assembly language". In the following example, contents of W and STATUS registers are stored in W_TEMP and STATUS_TEMP variables prior to interrupt routine. At the beginning of PUSH routine we need to check presently selected bank because W_TEMP and STATUS_TEMP are found in bank 0. For exchange of data between these registers, SWAPF instruction is used instead of MOVF because it does not affect the STATUS register bits. The same example can be carried out using macros, thus getting a more legible program. Macros that are already defined can be used for writing new macros. Macros BANK1 and BANK0 which are explained in "Memory organization" chapter are used with macros 'push' and 'pop'. External interrupt on RB0/INT pin of microcontroller The above example shows initialization of external interrupt on RB0 pin of a microcontroller. Where we see one being set, that means that interrupt is enabled. Occurrence of other interrupts is not allowed, and interrupts are disabled altogether until GIE bit is set to one.
|
2.6 Interrupts in PIC microcontrollers
online engineering degree/engineering degree online/online engineering courses/engineering technology online/engineering courses online/engineering technician degree online/online engineering technology/electronic engineering online
online civil engineering technology degree/online electrical engineering degree/online electrical engineering degree abet/online electrical engineering technology degree/online engineering courses/online engineering degree/online engineering technology/online engineering technology degree/online engineering technology degree programs/online mechanical engineering technology degree