Question

In: Electrical Engineering

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

Solutions

Expert Solution

Solution:

Two LEDs are connected to two Pins of Port-2

LED1- is connected to P2.2 (Port -2) and it is active high means that when the bit is high LED will glow.

LED2- is connected to P2.3 (Port -2) and it is active high means that when the bit is high LED will glow.

The below program is implementation of alternative blinking of Two LEDs with delay of 352msec.

Program1:

/******** Progrman for alternate blinking of two leds *******/

#include "msp430x14x.h"

#define BIT2 0x04u

#define BIT3 0x08u

void delay_352us(unsigned int i);//352us delay program statement

//*************************************

int main( void )

{

WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer to prevent time out reset

P2DIR |= BIT2;          //Port 2.2 as output port for led1

P2DIR |= BIT3;          //Port 2.3 as output port for led2

P2OUT &= ~BIT2;                  //led1 off        

P2OUT &= ~BIT3;                  //led2 off

while(1)

{

            P2OUT |= BIT2;                       //led1 on

            delay_352us(1000);

            P2OUT &= ~BIT2;                    //led1 off        

            P2OUT |= BIT3;                       //led2 on

            delay_352us(1000);

            P2OUT &= ~BIT3;                    //led2 off

   }

}

}

//******************************************************

//352 ms delay procedure

void delay_352us(unsigned int i)//352us delay procedures, the calculation of delay time in front of already mentioned

{

unsigned char j;

while(i--)

{

   for(j=0;j<255;j++)

   {

    _NOP();

    _NOP();

    _NOP();

    _NOP();  

    }

}

}

/******************end of program********/

Program2:

It is an implementation of following sequences for the two LEDs

  1. Blink LED1 – 5 times
  2. Blink LED2 – 5 times
  3. Blink LED1 and LED2 – 5 times simultaneously and repeat the steps 1 to 3.

/******** Progrman for alternate blinking of two leds *******/

#include "msp430x14x.h"

#define BIT2 0x04u

#define BIT3 0x08u

void delay_352us(unsigned int i);//352us delay program statement

void blinkled1();

void blinkled2();

void blinkled1and2();

//*************************************

int main( void )

{

WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer to prevent time out reset

P2DIR |= BIT2;          //Port 2.2 as output port for led1

P2DIR |= BIT3;          //Port 2.3 as output port for led2

P2OUT &= ~BIT2;                  //led1 off        

P2OUT &= ~BIT3;                  //led2 off

while(1)

{

            blinkled1();

            blinkled2();

            blinkled1and2();

}

}

/*******Blink LED1*****/

void blinkled1()

{

            unsigned char i=0;

            for(i=0;i<5;i++)

            {

                        P2OUT |= BIT2;                       //led1 on

                        delay_352us(1000);

                        P2OUT &= ~BIT2;                    //led1 off        

            }          

}

/*******Blink LED2*****/

void blinkled2()

{

            unsigned char i=0;

            for(i=0;i<5;i++)

            {

                        P2OUT |= BIT3;                       //led2 on

                        delay_352us(1000);

                        P2OUT &= ~BIT3;                    //led2 off

            }

}

/*******Blink LED1*****/

void blinkled1and2()

{

            unsigned char i=0;

            for(i=0;i<5;i++)

            {

                        P2OUT |= (BIT2|BIT3);                       //led1&2 on

                        delay_352us(1000);

                        P2OUT &= ~(BIT2|BIT3);                    //led1&2 off

            }                      

}

//******************************************************

//352 ms delay procedure

void delay_352us(unsigned int i)//352us delay procedures, the calculation of delay time in front of already mentioned

{

unsigned char j;

while(i--)

{

   for(j=0;j<255;j++)

   {

    _NOP();

    _NOP();

    _NOP();

    _NOP();   

    }

}

}

/*****end of Program***************/

Three functions are defined for the three steps and it is repeated forever.


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
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5...
For the mspfr6989 write program #2 1(b) Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop. Program #2 – Using both S1 and S2 1 Write a program like 1(b) above, but the LED1 will blink until S2 is pressed. 2 Write a program that simulates a motor coming up to speed. When S1 is pressed, LED1 blinks at 50% duty cycle for 10 cycles (indicating a motor coming up to speed)....
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. 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
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called...
Write an MSP430 assembly language program that implements the following 2 algorithms: 2) a macro called "vdot" that calculates the "dot product" of two vectors "a" and "b", implemented as “arrays” (following the “C” language convention), of 3 elements. the macro should receive 2 pointers to the first element of each vector and return the result in R13.
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.
Write an assembly program for the MSP430 to calculate the number of zeros and ones in...
Write an assembly program for the MSP430 to calculate the number of zeros and ones in an array. If the number of zeros is more than the number of ones, the red LED(connected to P1.0 on the MSP430 launchpad) will turn on. Otherwise, the green LED (connected to P1.6 on the MSP430 launchpad) will turn on.
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 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.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT