In: Electrical Engineering
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
Solution:
LED1- is connected to P2.2 (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 one LEDs with duty cycle of 50% by delay of 352msec ON and 352msec OFF. A separate subroutine is implemented for time delay.
Program1:
/******** Progrman for alternate blinking of one led with 50%dutycycle *******/
#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); //delay of 352msec ON
P2OUT &= ~BIT2; //led1 off
delay_352us(1000); //delay of 352msec 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
/******** 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
blinkled1();
delay_352us(1000000); //long pause
blinkled1();
}
/*******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
delay_352us(1000);
}
}
//******************************************************
//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 two steps and it stops.