Question

In: Electrical Engineering

1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and...

1. IN C LANGUAGE: Write a code that makes the MSP430 blink the red LED and the green LED at the same time. The two LEDs should be on at the same time and then off at the same time

Solutions

Expert Solution

#include  <msp430g2553.h>

 unsigned int i = 0;                         // Initialize variables. This will keep count of how many cycles between LED toggles


void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer. This line of code is needed at the beginning of most MSP430 projects. 
                                            // This line of code turns off the watchdog timer, which can reset the device after a certain period of time.

  P1DIR |= 0x01;                            // P1DIR is a register that configures the direction (DIR) of a port pin as an output or an input. 


                                            // To set a specific pin as output or input, we write a '1' or '0' on the appropriate bit of the register.


                                            // P1DIR = <PIN7><PIN6><PIN5><PIN4><PIN3><PIN2><PIN1><PIN0>


                                            // Since we want to blink the on-board red LED, we want to set the direction of Port 1, Pin 0 (P1.0) as an output

                                            // We do that by writing a 1 on the PIN0 bit of the P1DIR register
                                            // P1DIR = <PIN7><PIN6><PIN5><PIN4><PIN3><PIN2><PIN1><PIN0>
                                            // P1DIR = 0000 0001
                                            // P1DIR = 0x01     <-- this is the hexadecimal conversion of 0000 0001



  for (;;)                                  // This empty for-loop will cause the lines of code within to loop infinitely
  {



    P1OUT ^= 0x01;                          // Toggle P1.0 using exclusive-OR operation (^=)

                                            // P1OUT is another register which holds the status of the LED. 
                                            // '1' specifies that it's ON or HIGH, while '0' specifies that it's OFF or LOW
                                            // Since our LED is tied to P1.0, we will toggle the 0 bit of the P1OUT register



    for(i=0; i< 20000; i++);                // Delay between LED toggles. This for-loop will run until the condition is met. 
                                            //In this case, it will loop until the variable i increments to 20000.
  }
P.S: If you are having any doubt, please comment here, I will surely reply you.Please provide your valuable feedback by a thumbsup. Your thumbsup is a result of our efforts. Thanks in advance!

#include <msp43092553.h> unsigned int i = 0; 1/ Initialize variables. This will keep count of how many cycles between LED toggles void main(void) { WDTCTL = WDTPW + WDTHOLD; 1 Stop watchdog timer. This line of code is needed at the beginning of most MSP430 projects. // This line of code turns off the watchdog timer, which can reset the device after a certain period of time. // PIDIR is a register that configures the direction (DIR) of a port pin as an output or an input. PIDIR = Ox01; 1/ To set a specific pin as output or input, we write a 'l' or 'o' on the appropriate bit of the register. // PIDIR = <PIN7><PIN6><PIN"><PIN4><PIN3><PIN2><PINI><PINO> // Since we want to blink the on-board red LED, we want to set the direction of Port 1, Pino (P1.0) as an output // We do that by writing a 1 on the PINO bit of the PIDIR register // PIDIR = <PIN7><PIN6><PIN5><PIN4><PIN3><PIN2><PINI><PINO> // PIDIR = 0000 0001 // PIDIR = Ox01 <-- this is the hexadecimal conversion of 0000 0001 for (;;) { // This empty for-loop will cause the lines of code within to loop infinitely

PLOUT ^= Ox01; // Toggle P1.0 using exclusive-OR operation (=) // PIOUT is another register which holds the status of the LED. // '1' specifies that it's On or HIGH, while 'o' specifies that it's OFF or LOW // Since our LED is tied to P1.0, we will toggle the 0 bit of the plout register for(i=0; i< 20000; i++); // Delay between LED toggles. This for-loop will run until the condition is met. // In this case, it will loop until the variable i increments to 20000. }


Related Solutions

1.write a program for the msp430 to make led 1 blink at 50 percent duty cycle....
1.write a program for the msp430 to make led 1 blink at 50 percent duty cycle. 2 modify the program to make led 1 blink 5 times, make a long pause, then blink 5 more times then stop. The time delays should be carried out in subroutines
Using Arduino to blink an LED in morse code. Morse code is used as one of...
Using Arduino to blink an LED in morse code. Morse code is used as one of the methods for communications. It consists of a series of “dit” and “dah” symbols. (i) Develop an Arduino program to produce a Morse code to express the phrase “We are students” using Pin #13 (connect an LED that is in series with a 220-Ω resistor to Pins #13 to view the information sent via the Morse code). Express one “dit” with LED on for...
Write the following in C language for Arduino: Write a program that turns on the LED...
Write the following in C language for Arduino: Write a program that turns on the LED at 25%, 50%, 75%, 100%, and then 0% brightness with a one second delay in between each change. Remember you are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine the values for...
Write a function that can be used to blink an LED when called.
Write a function that can be used to blink an LED when called.
Write the following in C language for Arduino: Write a program that increases the LED brightness...
Write the following in C language for Arduino: Write a program that increases the LED brightness in five steps with each press of the button. Remember you are going to using a digital input and the "digitalRead" command. You are going to need to use a PWM pin and use the "analogWrite" command. The maximum value for our Arduino R3 boards is 255 and you need five steps (25%, 50%, 75%, 100%, and 0%) so you will need to determine...
1.write a program for the msp430FR6989 to make led 1 blink at 50 percent duty cycle....
1.write a program for the msp430FR6989 to make led 1 blink at 50 percent duty cycle. 2 modify the program to make led 1 blink 5 times, make a long pause, then blink 5 more times then stop. The time delays should be carried out in subroutines
1.. Write a code that LED1 (Red LED- P1.0) turns ON when after you push S1(push...
1.. Write a code that LED1 (Red LED- P1.0) turns ON when after you push S1(push button - P1.1) five times and stays OFF forever after that. 2.. Write a code that LED1 (Red LED- P1.0) turns OFF and LED2 (Red LED- P9.7) Turns ON after you push S1(push button -P1.1) five times and they stay that way forever.
Write a program for the msp430 to make led1 and led 2 alternate blinking 2. repeat...
Write a program for the msp430 to make led1 and led 2 alternate blinking 2. repeat the program to make each led blink 5 times in a sequence, then 5 times simultaneously
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at...
Write a C program to blink two LEDs connected to Raspberry pi. One must blink at a rate of 1 Hz and the other at a rate of 2 HZ.
4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays...
4. Write a code that S1(push button -P1.1) turns LED1 (Red LED- P1.0) ON and stays on when you push once and turns off and stays OFF when you push 3 times. This should repeat forever. 5. Write a code that S2(push button -P1.2) turns LED2 (Red LED- P9.7) ON and stays ON when you push once and turns OFF and stays OFF when you push 3 times. This should repeat five times. 6. Write a code that LED2 (Red...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT