Question

In: Electrical Engineering

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.

Solutions

Expert Solution

Answer :- 1) The code has been written below-

#include <msp430g2553.h> // header file that depends upon your variant

int main(void)
{
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer

P1DIR = 0X40; //Declare PIN0 as output and PIN1 as input for port one

P1OUT = 0X00; //initially make LED1 in off state

unsigned int i, cnt = 0; //Delay variable
while(1)
{
if (!(BIT1 & P1IN)) //when S1 is pressed
{
cnt++;
if(cnt == 5)
{
P1OUT = 0X01; //Make LED on after five time press
for(i=0;i<30000;i++); //Necessary delay, change it to see the effect on toggling
P1OUT = 0x00; //make LED off forever
break; //come out of infinite loop
}
}

}
return 0;
}

Answer :- 2) The code is written below-

#include <msp430g2553.h> // header file that depends upon your variant

int main(void)
{
WDTCTL = WDTPW | WDTHOLD;// Stop watchdog timer

P1DIR = 0x01; //Declare PIN0 as output and PIN1 as input for port one

P4DIR = 0x80; //make port4 pin7 as output for LED2

P1OUT = 0x01; //initially make LED1 in on state

P4OUT = 0x00; //initially make LED2 in off state
unsigned int i, cnt = 0; //Delay variable
while(1)
{
if (!(BIT1 & P1IN)) //when S1 is pressed
{
cnt++;
if(cnt == 5)
{
P1OUT = 0X00; //Make LED1 off after five time press
P4OUT = 0X80; //Make LED2 on after five time press

break; //come out of infinite loop
}
}

}
return 0;
}

Note :- For problem 2, the LED2 is at P4.7 and not at P9.7 as per the datasheet. I request the student to post name of board also in further posting of questions. Thank You.


Related Solutions

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...
1. Write a code that makes the MSP430 blink the red LED and the green LED...
1. 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
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It...
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS 2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS
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
using code composer studio 1. write a program for the msp430fr6989 that will light LED1, whenever...
using code composer studio 1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
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 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...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red,...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red, blue, and green. Use ‘analogWrite’ command inside the 'for loop.' Use the value ranges from 0-255 for this command. So, to activate any of the pins, the value should be 255. To turn off 0. pattern: First for loop Red light – delay – Second for loop for blue light – delay - Third for loop for green light - delay. (The resulting lights...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT