3. A MSP430 board has LED1 connected to P1.6, LED2 connected to P2.1, pushbutton
ID: 2290904 • Letter: 3
Question
3. 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) Comment each line of the program // add head file #include int main(void) PI DIR-BIT6; PI DIR &-,-BIT7; PIREN BIT7; PIOUT-BIT7; P1IE BIT7; enable_interrupt0; // Port 1 interrupt service routine #pragma vector-PORT 1 VECTOR interrupt void PORT1 ISR(void) P1OUT- BIT6; P1IFG &~BIT7 (2) Describe what this program does ove rallExplanation / Answer
ANSWER:
The below code shows with respect to the data;
#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
}
2)the below shows the Explanation of the program:
-> the MSP430 PushButtion program that toggles light emmiting diode( 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.hence our required data is explained.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.