Write a program for the MSP430g2553 using Code Composer Studio (not Energia) tha
ID: 3866098 • Letter: W
Question
Write a program for the 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).
This would be appreciated, will rate for correct answer!!
.The length of a dot is one unit (1x) The length of a dot is one unit (1x) A dash is three units (3x) The space between a dot and a dash within a letter is one unit (x) The space between letters within a word is three units (3x) The space between words is seven units (7x)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;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.