Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program for the MSP430 with the following specifications: When the pus

ID: 3911424 • Letter: W

Question

Write a C program for the MSP430 with the following specifications: When the push button (connected to P1.3 on the MSP430 LaunchPad) is pressed, the red LED (connected to P1.0 on the MSP430 LaunchPad) will turn on and wait for a certain time. Then, both the red and green LEDs (connected to P1.0 and P1.6 on the MSP430 LaunchPad) will turn on and wait for a certain time. Afterwards, the red LED (connected to P1.0 on the MSP430 LaunchPad) will turn off and the green LED (connected to P1.6) will turn on and wait for a certain time. Finally, both LEDs will turn off. This procedure is repeated indefinitely. Hint: Use loop operations to generate waiting times.

Then: convert the C program in assembly language for the MSP430.

Explanation / Answer

MSP430 Blink LED / Start Stop Blinking with Button Demo - Software Toggle P1.0 & P1.6

Description; Toggle P1.0 and P1.6 by xor'ing them inside of a software loop. To
start/stop blink, an interrupt in Port 1 will toggle the condition statement.
ACLK = n/a, MCLK = SMCLK = default DCO

MSP430x2xx
|| XIN|-
| | |
|RST XOUT|-
| P1.6|-->LED
Button -->|P1.3 P1.0|-->LED

Aldo Briano
Texas Instruments, Inc
June 2010
Built with Code Composer Studio v4

#include <msp430g2231.h>


#define LED_0 BIT0
#define LED_1 BIT6
#define LED_OUT P1OUT
#define LED_DIR P1DIR
#define BUTTON BIT3

unsigned int blink = 0;

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
LED_DIR |= (LED_0 + LED_1); // Set P1.0 and P1.6 to output direction
LED_OUT &= ~(LED_0 + LED_1); // Set the LEDs off
P1REN |= BUTTON; //Enables a puller-Resistor on the button-pin
P1OUT |= BUTTON; //Writes a "1" to the portpin, tellling the resistor to pullup
P1IES |= BUTTON; //Triggers when you PRESS the button :: Pick one...
//P1IES &= ~BUTTON; // Triggers when you RELEASE the button :: ...or pick the other
P1IE |= BUTTON; //Enables the selector-mask for generating interrupts on the relevant
pinenable_interrupt(); // Interrupts get enabled *here* - they were disabled thus far..

for (;;)
{

if(blink > 0)
{
P1OUT ^= (LED_0 + LED_1); // Toggle P1.0 and P1.6 using exclusive-OR_delay_cycles(100000);
SW Delay of 10000 cycles at 1Mhz

}
}

}

Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR__interrupt void Port_1(void)
{
blink ^= 0x01;
P1IFG &= ~BUTTON; // P1.3 IFG cleared
LED_OUT &= ~(LED_0 + LED_1); Clear the LEDs so they start in OFF state

}

=================== ======================

hope this will help

Pleasecomment for further queries

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote