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

Write a program for the TI microcontroller MSP430g2553 using Code Composer Studi

ID: 3866276 • Letter: W

Question

Write a program for the TI microcontroller MSP430g2553 using Code Composer Studio (not Energia) that flashes the Morse code pattern of a string with the Red LED(Port1 Pin 0(0x01)). To show a Morse letter on the MSP430, the red LED blinks for a short duration to represent a dot, or for a long duration to represent a dash.

The code should work for any string, it should discover the size of the string and flash all the words, and the only change to the code to make it flash a different message is by putting a new message between the quotes >>>>>>>>>>>>>>>>> char str[] = "Message";

The code must flash the message in an infinite loop, and a hint that was given was that you can store all the dot-dash patterns in a 2D array, where it has 36 rows(26 letters and 0-9 digits).

Explanation / Answer

const int BUTTON = 5; //use button on board
const int LED = 14; //use red led on board

int ledState = LOW; //current ledState
int buttonState; //current buttonState
int lastButtonState = LOW; //previous buttonState

long time = 0; //last time switch is pressed
long debounce = 50; //debounce time

void setup()
{
//set I/O pins
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
}

void loop()
{
int buttonState = digitalRead (BUTTON); //is switch press?

//when button is press & (previous & current state is different) & (previous - current time > debounce)
if (buttonState == HIGH && lastButtonState == LOW && millis() - time > debounce)
{
if (ledState == HIGH) //when LED IS ON
{
ledState = LOW; //turn LED OFF
}
else //when LED is OFF
{
ledState = HIGH; //turn it ON
}
time = millis(); //save time after releasing the button
}
digitalWrite (LED, ledState); //output LED
lastButtonState = buttonState; //save the previous buttonState to current buttonState
}

#include <msp430g2553.h>

void main(void)

{

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

P1DIR |= BIT6; // Set P1.6 (green LED) to output direction, 1 is output

P1OUT &= ~BIT6; // Set the green LED off

P1DIR &= ~BIT3; // Port 1 P1.3 (push button) as input, 0 is input

P1REN |= BIT3; // Enable Port 1 P1.3 (push button) pull-up resistor

P1OUT |= BIT3; // The button is up

while(1)

{

if( (P1IN & BIT3 ) == 0) // Push button down when bit 3 == 0

{

if ((P1OUT | BIT6) == 0)

{

P1OUT &= ~BIT6;

}

else

{

P1OUT |= BIT6;

}

}

}

}

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