Question: 1) The following program is the simple I/O sample program (Ch8) we discussed in class. Basically when you push the button, LED1 toggles, and when
1) The following program is the simple I/O sample program (Ch8) we discussed in class. Basically when you push the button, LED1 toggles, and when you release it, LED2 toggles. Modify the program, so that at the push of the button, the micro cycles through 4 different as follows:
1- LED1 flashes while LED2 off
2- LED2 flashes while LED1 off
3- LED1 and LED2 flash simultaneously
4- LED1 and LED2 flash alternatively
Hint: use a counting semaphore to cycle through 4 different values, each of which corresponds to the four different modes, See the other sample code for flasher with multiple speeds.
#include
#include "msp430g2553.h"
int sw2=0;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; //stop watchdog timer
P1DIR = 0x00; //port 1 all inputs
P1DIR |= (BIT0 | BIT6); //set P1.0 and P1.6 as outputs (LED1, LED2)
P1REN |= BIT3; //activate resister on P1.3
P1OUT |= BIT3; //make it pull up because SW2 is active low
For (;;)
{sw2 = P1IN; //read values from P1
sw2 &= BIT3; //mask out only BIT3 whereSW2 is connected
if (sw2 == BIT3)
{ //if SW2 is high
P1OUT &= ~BIT6; //turn LED2 off
P1OUT ^= BIT0; //toggle
LED1 __delay_cycles(50000); //delay 50,000 micro seconds
}
else
{ //else (SW2 is low)
P1OUT &= ~BIT0; //turn LED1 off
P1OUT ^= BIT6; //toggle LED2
__delay_cycles(200000); //delay 200,000 micro seconds
}
}
// end of infinite loop
}
//end of main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
