1. What is the difference between the interrupt service routine and the interrup
ID: 2248115 • Letter: 1
Question
1. What is the difference between the interrupt service routine and the interrupt vector?
2. Write a C program for the MSP430 that will count the number of times the push button (connected to P1.3 on the MSP430 LaunchPad) is pressed. The button-pressing operation should be defined in an ISR.
3. Expand problem 2 such that a) At the beginning of the program, the green LED (connected to P1.6 on the MSP430 LaunchPad) will turn on. b) When the count reaches multiples of five (5), the green LED will toggle.
Explanation / Answer
Answer:-1) The interrupt service routine is the actual code or set of instruction that will be executed by the processor when the interrupt occurs.
Before entering to the interrupt service routine the processor saves the current instruction and data into stack memory and after completion of ISR, stack is popped and instruction execution is done again as normal.
Interrupt vector is the memory location where the address of ISR( or Interrupt Handler) and Priority of Interrupt has been defined. When interrupt comes CPU takes address of ISR and priority from this location. If more number of inerrupts are there in CPU then interrupt vector table is formed.
Answer:-2) The code to count the number of times button is pressed is written below-
#include "msp430g2231.h"
unsigned int counter = 0; /* a global variable to keep count value */
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; /* stop WDT */
P1OUT &= 0x00 ; /* make output low before pin setup */
P1DIR &= 0x00; /* all are input pin */
P1REN |= BIT3; /* enable internal pull-up/down resistos */
P1OUT |= BIT3; /* Select pull up mode for p1.3 pin, interrupt pin */
P1IE |= BIT3; /*p1.3 interrupt enabled */
P1IES |= BIT3; /* P1.3 high / low edge select */
P1IFG |= ~BIT3; /* P1.3 interrupt flag cleared */
_BIS_SR(CPUOFF + GIE); /* Enter low power mode, global interrupt enabled */
while(1) /* Infinite loop starts */
{
} /* while loop end */
}
/* Interrupt service routine definition */
__interrupt void Port_1(void)
{
counter ++; /* Increment the count value */
P1IFG &= ~BIT3; /* Clear the interrupt flag */
}
Note:- Finally counter keeps the count value.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.