2. A MSP430 board has LED1 connected to P1.6, LED2 connected to P2.1, pushbutton
ID: 2081260 • Letter: 2
Question
2. A MSP430 board has LED1 connected to P1.6, LED2 connected to P2.1, pushbutton B1 connected to P1.7, and pushbutton B2 connected to p2.7. For the following program, answer questions (1) and (2).
(1) (11 pts) Comment each line of the program.
#include <msp430.h> // ________________
int main(void)
{ WDTCTL = WDTPW + WDTHOLD; // ________________
P1DIR |= BIT6; // ________________
P1DIR &= ~BIT7; // ________________
P1REN |= BIT7; // ________________
P1OUT |= BIT7; // ________________
P1IE |= BIT7; // ________________
P1IES &= ~BIT7; // ________________
P1IFG &= ~BIT7; // ________________
__enable_interrupt();
}
// Port 1 interrupt service routine
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1OUT ^= BIT6; // ________________
P1IFG &= ~BIT7; // ________________
}
(2) (4 pts) Describe what this program does overall.
Explanation / Answer
#include <msp430.h> //msp430.h hearder files automatically find the device specific header file that matches the target device you picked in the project
int main(void)
{ WDTCTL = WDTPW + WDTHOLD; // Stop the watchdog timer
P1DIR |= BIT6; // Set P1.6 (LED) to output direction
P1DIR &= ~BIT7; //Push Port 1 P1.7 (push button) as input
P1REN |= BIT7; // resistor enabled
P1OUT |= BIT7; // pull up resistor
P1IE |= BIT7; // Enable interrupt for P1.7
P1IES &= ~BIT7; // Set P1.7 as Genral Purpose Input Output
P1IFG &= ~BIT7; // Clear interrupt flag for P1.7
__enable_interrupt();
}
// Port 1 interrupt service routine
#pragma vector = PORT1_VECTOR
__interrupt void PORT1_ISR(void)
{
P1OUT ^= BIT6; // Toggle led at P1.6
P1IFG &= ~BIT7; // Clear interrupt flag for P1.7
}
B) Explanation
It is a MSP430 PushButtion program that toggles LED at P1.6 On and OFF. PushButton in P1.7 through interrupt turns on and off the lED in P1.6. By changing the P1.7 interrupt edge, the interrupt is called every time the button is pushed and pulled, thereby, toggling the LED everytime.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.