{"id":3180,"date":"2011-07-21T21:33:11","date_gmt":"2011-07-22T01:33:11","guid":{"rendered":"http:\/\/embedded-lab.com\/blog\/?p=3180"},"modified":"2012-11-06T14:00:30","modified_gmt":"2012-11-06T19:00:30","slug":"lab-16-understanding-interrupts","status":"publish","type":"post","link":"https:\/\/embedded-lab.com\/blog\/lab-16-understanding-interrupts\/","title":{"rendered":"Lab 16: Understanding Interrupts"},"content":{"rendered":"<p>Interrupts are powerful concept in embedded systems for controlling events in a time-critical environment. In a typical embedded system, the embedded processor (microcontroller) is responsible for doing more than one task (but can do only one at a time). For example, let&#8217;s say in a programmable digital room thermostat, the microcontroller is assigned to monitor the room temperature, turn the AC or heater ON and OFF, control the LCD display, and respond to any new temperature setting from the user. Out of these the first three tasks are non-time-critical and are executed continuously in sequence one after the other, within the main loop. But when the user presses any button on the setting panel, the microcontroller should be able to read it before the user releases the button. So this is a time-critical event and the microcontroller should stop whatever it is doing and respond to this higher priority event. This is possible through the use of interrupts. This tutorial first describes the interrupt system in general and then illustrates how it is handled in PIC micrcontrollers.<\/p>\n<div id=\"attachment_3198\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptTitle.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3198\" class=\"size-full wp-image-3198\" title=\"InterruptTitle\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptTitle.jpg\" alt=\"\" width=\"560\" height=\"390\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptTitle.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptTitle-550x383.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3198\" class=\"wp-caption-text\">Understanding interrupts in PIC microcontrollers<\/p><\/div>\n<p><!--more--><strong>Theory<\/strong><\/p>\n<p>As mentioned above, interrupts form the basis for separating the time-critical events from the others and execute them in a prioritized manner. An interrupt tells the microcontroller to drop whatever it is doing and execute another program (the Interrupt Service Routine or ISR)\u00a0stored at a predefined place in the program memory.\u00a0Interrupt requests are asynchronous events which means that an interrupt\u00a0request can occur at any time during the execution of a program. But whenever it occurs,\u00a0the CPU finishes the current instruction and stores the address for the next instruction (which is in the Program Counter, or PC) in to the stack memory so that the current program can continue once the interrupt service ends. The CPU then jumps to a certain program memory location (0x0004 in the PIC), where the ISR begins. At the end of the ISR, execution of the return instruction\u00a0loads the address at the top of the stack back into the program counter, and execution proceeds from the same point where the processor was interrupted.<\/p>\n<p>A microcontroller\u00a0has several sources of interrupts, which can be external or internal. The most common internal interrupt sources are timers, EEPROM, ADC module, and comparator.\u00a0External\u00a0interrupts originate in peripherals and reach the microcontroller through\u00a0one of its pins and associated ports.<\/p>\n<div id=\"_mcePaste\">Interrupts in medium-end PIC microcontrollers are fixed, maskable interrupts.\u00a0This means that interrupts can be globally enabled or disabled, as\u00a0well as each interrupt source can be individually enabled or disabled. We will consider the PIC16F688 microcontroller for today&#8217;s discussion on interrupts.<\/div>\n<p>The PIC16F688 has the following sources of interrupt:<\/p>\n<p><span style=\"color: #800000;\">\u2022 External Interrupt at RA2\/INT pin<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 TMR0 Overflow Interrupt<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 PORTA Change Interrupts<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 2 Comparator Interrupts<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 A\/D Interrupt<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 Timer1 Overflow Interrupt<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 EEPROM Data Write Interrupt<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 Fail-Safe Clock Monitor Interrupt<\/span><\/p>\n<p><span style=\"color: #800000;\">\u2022 EUSART Receive and Transmit interrupts<\/span><\/p>\n<p>Each of these interrupts can be enabled or disabled individually, and more than one interrupt can be active at the same time.\u00a0When an interrupt is requested, the microcontroller\u00a0finishes executing the current instruction, stores the value of the program\u00a0counter in the stack, and jumps to address 0004h in program memory, where the ISR is located. As all interrupt sources make the program to jump to the same place (0004h), the programmer, when writing the ISR, must first\u00a0find out the source that requested the interrupt. This is done by reading\u00a0the appropriate bits in the special function registers, INTCON and PIR1,\u00a0associated with the interrupt system. The figure below shows the\u00a0bits in the interrupt control register (INTCON).<\/p>\n<div id=\"attachment_3211\" style=\"width: 580px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/INTCON1.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3211\" class=\"size-full wp-image-3211\" title=\"INTCON1\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/INTCON1.jpg\" alt=\"\" width=\"570\" height=\"134\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/INTCON1.jpg 570w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/INTCON1-550x129.jpg 550w\" sizes=\"auto, (max-width: 570px) 100vw, 570px\" \/><\/a><p id=\"caption-attachment-3211\" class=\"wp-caption-text\">INTCON register bits in PIC16F688<\/p><\/div>\n<p>The details for each bit are described here:<\/p>\n<p><em>GIE (global interrupt enable):<\/em> This bit is the master switch for all interrupts. Turn it off (GIE = 0) and no interrupts are enabled (regardless of the state of their individual enable bits). Turn it on\u00a0(GIE = 1) and interrupts whose individual enable bits are set will be enabled. When an\u00a0interrupt is requested, this bit is automatically set to 0, thus disabling any further interrupts.\u00a0The return\u00a0instruction at the end of the interrupt service subroutine\u00a0sets bit GIE back to 1, thus enabling the global interrupt system.<\/p>\n<p><em>PEIE (peripheral interrupt enable)<\/em> is a mini-master switch for a group of interrupts which are known as &#8216;peripheral interrupts&#8217;. They have their own enable bits in the PIE1 register (discussed later). This bit must be set to enable any enabled peripheral interrupts.<\/p>\n<p><em>T0IE, T0IF:<\/em> These bits are related to Timer0 overflow interrupt. When\u00a0T0IE = 1, the Timer0 interrupt is enabled. T0IF is set to 1 whenever TMR0 overflows from 255 to 0. This has been discussed in <a href=\"http:\/\/embedded-lab.com\/blog\/?p=1042\" target=\"_blank\"><strong>PIC Timers and Counters<\/strong><\/a> article too.<\/p>\n<p><em>INTE, INTF:<\/em> These bits are related to the external interrupt which depends on the state of the RA2\/INT pin of PIC16F688. Bit INTE\u00a0enables this interrupt. The interrupt can be set to trigger on the rising edge or falling edge of the signal on INT pin. This is done using the bit 6 (INTEDG) of the OPTION register (shown below). Bit INTF is a flag that indicates the detection\u00a0of an edge (rising or falling) in the input pin INT.<\/p>\n<p><em>RAIE, RAIF:<\/em> These bits are related to the interrupt due to a change\u00a0of logic level at PORTA pins. RAIE = 1 enables this interrupt and RBIF\u00a0is a flag that indicates a change in one of the pins of PORTA. In order to select which PORTA pin should be able to trigger the interrupt, the corresponding bit of INTERRUPT-ON-CHANGE PORTA (IOCA) register must be set.<\/p>\n<p>The individual bits of OPTION, PIE1 and IOCA registers are shown in the figures below.<\/p>\n<div id=\"attachment_3242\" style=\"width: 547px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/OPTIONReg.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3242\" class=\"size-full wp-image-3242\" title=\"OPTIONReg\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/OPTIONReg.jpg\" alt=\"\" width=\"537\" height=\"95\" \/><\/a><p id=\"caption-attachment-3242\" class=\"wp-caption-text\">INTEDG bit of OPTION_REG is used to set the edge select for interrupt on INT pin. Please read the datasheet of PIC16F688 for details on the functions of other bits. <\/p><\/div>\n<div id=\"attachment_3243\" style=\"width: 552px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/IOCA.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3243\" class=\"size-full wp-image-3243\" title=\"IOCA\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/IOCA.jpg\" alt=\"\" width=\"542\" height=\"93\" \/><\/a><p id=\"caption-attachment-3243\" class=\"wp-caption-text\">Setting an IOCA bit enables the interrupt-on-change on the corresponding PORTA pin<\/p><\/div>\n<div id=\"attachment_3245\" style=\"width: 578px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIE11.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3245\" class=\"size-full wp-image-3245\" title=\"PIE11\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIE11.jpg\" alt=\"\" width=\"568\" height=\"523\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIE11.jpg 568w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIE11-550x506.jpg 550w\" sizes=\"auto, (max-width: 568px) 100vw, 568px\" \/><\/a><p id=\"caption-attachment-3245\" class=\"wp-caption-text\">PIE1 register bits are to enable the peripheral interrupts<\/p><\/div>\n<div id=\"attachment_3246\" style=\"width: 578px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIR11.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3246\" class=\"size-full wp-image-3246\" title=\"PIR11\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIR11.jpg\" alt=\"\" width=\"568\" height=\"523\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIR11.jpg 568w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/PIR11-550x506.jpg 550w\" sizes=\"auto, (max-width: 568px) 100vw, 568px\" \/><\/a><p id=\"caption-attachment-3246\" class=\"wp-caption-text\">PIR1 register contains the flag bits for peripheral interrupts and are set during interrupt conditions.<\/p><\/div>\n<p>Please read <a href=\"ww1.microchip.com\/downloads\/en\/DeviceDoc\/41203B.pdf\" target=\"_blank\"><strong>datasheet of PIC16F688<\/strong><\/a> for the detail description of these registers. In the following section, we will discuss how to program the interrupt that originates in the RA2\/INT line of PIC16F688.<\/p>\n<p>In order to initialize the <strong>RA2\/INT<\/strong> interrupt, the following operations must take place:<br \/>\n<span style=\"color: #800000;\"> 1. Port-A, line 2 (RA2), must be initialized for input.<br \/>\n2. The interrupt source must be set to take place either on the falling or the rising edge of<br \/>\nthe signal using <strong>INTEDG<\/strong> bit of <strong>OPTION_REG<\/strong>.<br \/>\n3. The external interrupt flag (<strong>INTF<\/strong> in the <strong>INTCON<\/strong> Register) must be initially cleared.<br \/>\n4. Global interrupts must be enabled by setting the <strong>GIE<\/strong> bit in the <strong>INTCON<\/strong> Register.<br \/>\n5. The External Interrupt on <strong>RA2\/INT<\/strong> must be enabled by setting the <strong>INTE<\/strong> bit in the <strong>INTCON<\/strong><br \/>\nRegister.<\/span><\/p>\n<p>A sample program using the RA2\/INT interrupt is developed later in this article.<\/p>\n<p><strong>Circuit Diagram<\/strong><\/p>\n<p>In the circuit diagram shown below, a push button switch is wired to the RA2 port of PIC16F688. This switch produces the interrupt when pressed. Four red color LEDs are connected to RC0 through RC3 port and an yellow LED is wired to port RA0. The main program is a 4-bit binary up counter that increments at a rate of approximately one second. The value of the counter is sent to PORT-C and displayed on the four red LEDs. The yellow LED is toggled on and off when the pushbutton switch is pressed. The switch is active low and therefore, the interrupt is programmed on the falling edge of the signal (INTEDG = 0). The PIC16F688 runs at 4.0 MHz clock derived from the internal source.<\/p>\n<div id=\"attachment_3223\" style=\"width: 585px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/Lab16_InterruptCkt.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3223\" class=\"size-full wp-image-3223\" title=\"Lab16_InterruptCkt\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/Lab16_InterruptCkt.jpg\" alt=\"\" width=\"575\" height=\"394\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/Lab16_InterruptCkt.jpg 575w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/Lab16_InterruptCkt-550x376.jpg 550w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/a><p id=\"caption-attachment-3223\" class=\"wp-caption-text\">Circuit diagram for demonstrating external interrupt handling in PICMicro<\/p><\/div>\n<div id=\"attachment_3218\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptSetup.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3218\" class=\"size-full wp-image-3218\" title=\"InterruptSetup\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptSetup.jpg\" alt=\"\" width=\"560\" height=\"412\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptSetup.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptSetup-550x404.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3218\" class=\"wp-caption-text\">Circuit setup on breadboard<\/p><\/div>\n<p><strong>Software<\/strong><\/p>\n<p>The Interrupt Service Routine (ISR) depends on the specific application. However, certain steps are applicable to all cases. For example, the ISR should begin by checking which particular event triggered the interrupt (if more than one input is enabled). In this case, the INTF bit of INTCON register must be checked to verify that the source of interrupt is from RA2\/INT pin. Similarly, the interrupt flag (INTF bit in INTCON register) must be cleared by the ISR before returning to the main program otherwise an endless series of interrupts will occur. This is because on return the CPU finds the interrupt flag still set and assumes it as another interrupt and jumps back to the ISR.<\/p>\n<p>In PIC microcontrollers, the processor automatically clears the GIE bit in the INTCON register when an interrupt occurs. This means that no interrupt can\u00a0take place in the ISR, otherwise you can imagine the havoc that would take place if it should not\u00a0be the case. When the processor executes the return statement in the ISR, the GIE bit is set and the interrupts are enabled again.<\/p>\n<p>The interrupt programming for this experiment is written in mikroC Pro for PIC. It is a C compiler for PIC from mikroElektronika. In mikroC, the ISR is written just like another subroutine but with a reserved name, <em>interrupt<\/em>. Within the ISR, appropriate flag bits are checked to identify the source of interrupt. The complete program for this experiment is given below.<\/p>\n\n<div class=\"wp_syntax\"><table><tr><td class=\"code\"><pre class=\"c\" style=\"font-family:monospace;\"><span style=\"color: #808080; font-style: italic;\">\/*\nLab 16: Understanding Interrupts\nMCU: PIC16F688\nInternal Clock @ 4MHz, MCLR Enabled, PWRT Enabled, WDT OFF\nCopyright @ Rajendra Bhatt\nJul 19, 2011\n*\/<\/span>\n&nbsp;\nsbit LED at RA0_bit<span style=\"color: #339933;\">;<\/span>  <span style=\"color: #666666; font-style: italic;\">\/\/ Interrupt LED<\/span>\n<span style=\"color: #993333;\">unsigned<\/span> <span style=\"color: #993333;\">short<\/span> count<span style=\"color: #339933;\">;<\/span>\n&nbsp;\n<span style=\"color: #666666; font-style: italic;\">\/\/ Interrupt service routine<\/span>\n<span style=\"color: #993333;\">void<\/span> interrupt<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #009900;\">&#123;<\/span>\n <span style=\"color: #b1b100;\">if<\/span><span style=\"color: #009900;\">&#40;<\/span>INTCON.<span style=\"color: #202020;\">INTF<\/span> <span style=\"color: #339933;\">==<\/span> <span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span> LED <span style=\"color: #339933;\">=<\/span> ~LED<span style=\"color: #339933;\">;<\/span>\n delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">200<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/ Key debounce time<\/span>\n INTCON.<span style=\"color: #202020;\">INTF<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n<span style=\"color: #009900;\">&#125;<\/span>\n&nbsp;\n<span style=\"color: #993333;\">void<\/span> main<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #009900;\">&#41;<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n ANSEL <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0b00000000<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ All I\/O pins are configured as digital<\/span>\n CMCON0 <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0x07<\/span> <span style=\"color: #339933;\">;<\/span>        <span style=\"color: #666666; font-style: italic;\">\/\/ Disbale comparators<\/span>\n TRISC <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0b00010000<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ PORTC all outputs except RC4<\/span>\n TRISA <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0b00000100<\/span><span style=\"color: #339933;\">;<\/span>    <span style=\"color: #666666; font-style: italic;\">\/\/ PORTA all outputs except RA2<\/span>\n INTCON <span style=\"color: #339933;\">=<\/span> <span style=\"color: #208080;\">0b10010000<\/span><span style=\"color: #339933;\">;<\/span>   <span style=\"color: #666666; font-style: italic;\">\/\/ Set GIE and INTE bits<\/span>\n OPTION_REG.<span style=\"color: #202020;\">INTEDG<\/span> <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/ External interrupt on falling edge of RA2\/INT pin<\/span>\n count <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n LED <span style=\"color: #339933;\">=<\/span> <span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n PORTC <span style=\"color: #339933;\">=<\/span> count<span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #b1b100;\">do<\/span> <span style=\"color: #009900;\">&#123;<\/span>\n  count <span style=\"color: #339933;\">++;<\/span>\n  <span style=\"color: #b1b100;\">if<\/span> <span style=\"color: #009900;\">&#40;<\/span>count <span style=\"color: #339933;\">==<\/span><span style=\"color: #0000dd;\">16<\/span><span style=\"color: #009900;\">&#41;<\/span> count <span style=\"color: #339933;\">=<\/span><span style=\"color: #0000dd;\">0<\/span><span style=\"color: #339933;\">;<\/span>\n  PORTC <span style=\"color: #339933;\">=<\/span> count<span style=\"color: #339933;\">;<\/span>\n  delay_ms<span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1000<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span>\n <span style=\"color: #009900;\">&#125;<\/span><span style=\"color: #b1b100;\">while<\/span> <span style=\"color: #009900;\">&#40;<\/span><span style=\"color: #0000dd;\">1<\/span><span style=\"color: #009900;\">&#41;<\/span><span style=\"color: #339933;\">;<\/span> <span style=\"color: #666666; font-style: italic;\">\/\/ infinite loop<\/span>\n<span style=\"color: #009900;\">&#125;<\/span><\/pre><\/td><\/tr><\/table><\/div>\n\n<p style=\"text-align: center;\"><a href=\"http:\/\/embedded-lab.com\/uploads\/HexFiles\/PIC16F688\/Lab_Interrupts.zip\" target=\"_blank\">Download the source code and HEX file<\/a><\/p>\n<p><strong>Output<\/strong><\/p>\n<p>You will see the microcontroller will keep counting from 0 to 15 and roll over to 0 again and keep it continue. Whenever you press the interrupt switch, the processor will respond to it by changing the status of the yellow LED and then will resume the counting task.<\/p>\n<div id=\"attachment_3219\" style=\"width: 570px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptOutput.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-3219\" class=\"size-full wp-image-3219\" title=\"InterruptOutput\" src=\"http:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptOutput.jpg\" alt=\"\" width=\"560\" height=\"421\" srcset=\"https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptOutput.jpg 560w, https:\/\/embedded-lab.com\/blog\/wp-content\/uploads\/2011\/07\/InterruptOutput-550x413.jpg 550w\" sizes=\"auto, (max-width: 560px) 100vw, 560px\" \/><\/a><p id=\"caption-attachment-3219\" class=\"wp-caption-text\">Demonstrating interrupt request at INT pin<\/p><\/div>\n<p><strong>Summary<\/strong><\/p>\n<ul>\n<li>An interrupt is an event that requires the CPU to stop normal program execution and perform\u00a0some service (the ISR) related to the event.<\/li>\n<li>An interrupt can be generated internally (inside the chip by ADC, EEPROM, Timers, etc) or\u00a0externally (outside the chip through the INT pin).<\/li>\n<li>Proper use of interrupts allows more efficient utilization of the CPU time.<\/li>\n<li>Interrupts are very helpful to perform time-critical applications. Many emergent events, such as power\u00a0failure and process control, require the CPU to take action immediately. The\u00a0interrupt mechanism provides a way to force the CPU to divert from normal\u00a0program execution and take immediate actions.<\/li>\n<\/ul>\n<p><strong>References:<\/strong><\/p>\n<p>PIC Microcontroller: An Introduction to Software and Hardware Interfacing by\u00a0<em>Han-Way Huang<\/em><\/p>\n<p>Microcontrollers : Fundamentals and applications with PIC \/ authors, <em>Fernando\u00a0E. Valdes?Perez and Ramon Pallas?Areny<\/em>.<\/p>\n<p>Datasheet of PIC16F688 from <em>Microchip Technology, Inc<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Interrupts are powerful concept in embedded systems for controlling events in a time-critical environment. In a typical embedded system, the embedded processor (microcontroller) is responsible for doing more than one task (but can do only one at a time). For example, let&#8217;s say in a programmable digital room thermostat, the microcontroller is assigned to monitor the room temperature, turn the AC or heater ON and OFF, control the LCD display, and respond to any new temperature setting from the user. Out of these the first three tasks are non-time-critical and are executed continuously in sequence one after the other, within<\/p>\n","protected":false},"author":1,"featured_media":3198,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,38],"tags":[309,308,20],"class_list":["post-3180","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded-labs","category-pic-tutorials","tag-int","tag-pic-interrupts","tag-pic16f688"],"_links":{"self":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/3180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/comments?post=3180"}],"version-history":[{"count":45,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/3180\/revisions"}],"predecessor-version":[{"id":3256,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/posts\/3180\/revisions\/3256"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media\/3198"}],"wp:attachment":[{"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/media?parent=3180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/categories?post=3180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/embedded-lab.com\/blog\/wp-json\/wp\/v2\/tags?post=3180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}