Write a program for the MSP430 using code composer studio (not Energia) that wil
ID: 653735 • Letter: W
Question
Write a program for the MSP430 using code composer studio (not Energia) that will place an interrupt on the push2 button to blink either the red or green LED in one of two particular patterns for each color LED. The first time the button is pushed the red LED should turn on for 1 second and then turn off. The second time the button is pushed the red LED should turn on for 1 second, turn off for 1 second, turn back on for 1 second, and off again. The third time the button is pushed the green LED should turn on for 1 second and then turn off. The fourth time the button is pushed the green LED should turn on for 1 second, turn off for 1 second, turn back on for 1 second, and off again. The fifth time the button is pushed the red LED should turn on for 1 second and then turn off. The sixth time the button is pushed the red LED should turn on for 1 second, turn off for 1 second, turn back on for 1 second, and off again
Explanation / Answer
#include <msp430g2553.h>
#define pin0mask (0x01 << 0)
#define pin3mask (0x01 << 3)
#define pin6mask (0x01 << 6)
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
P1DIR = pin0mask | pin6mask;
int buttonPushed = 0;
int blinkMode = 0;
int blinkMask = pin0mask;
P1OUT &= ~pin6mask;
for( ; ; ) {
int j;
for( j = 0; j < 100; j++ )
{
volatile int i;
for( i = 0; i < 200; i++ );
if(( P1IN & pin3mask ) == 0 )
{
if( !buttonPushed )
{
buttonPushed = 1;
blinkMode = (blinkMode + 1)%4;
if( blinkMode == 0 )
{
blinkMask = pin0mask;
P1OUT &= ~pin6mask;
}
else if( blinkMode == 1 )
{
blinkMask = pin6mask;
P1OUT &= ~pin0mask;
}
else if( blinkMode == 2 )
{
blinkMask = pin0mask|pin6mask;
P1OUT |= pin0mask|pin6mask;
}
else
{
blinkMask = pin0mask|pin6mask;
P1OUT &= ~pin0mask;
P1OUT |= pin6mask;
}
}
} else
{
buttonPushed = 0;
}
}
P1OUT ^= blinkMask;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.