Question

Write a complete and concise TI-MSP432 C program with suitable comments that would allow the usage...

Write a complete and concise TI-MSP432 C program with suitable comments that would allow the usage of an onboard push button to control the onboard RGB LEDs so that they cycle through the following patterns: only R on, only G on, only B on. An LED stays on until the push button is pushed again. Do not use any of the low power modes. There will be penalty on un-necessary codes.

Homework Answers

Answer #1

You can control the color of the 3-color LED by using analogWrite() and using a value of 0-255 for each of the three pins that control the LED. For the MSP432 Those pins are named: RED_LED, GREEN_LED, and BLUE_LED.

The single-color red LED (named LED1) can only have its color changed by desoldering the current LED and replacing it with a comparably specced LED of the color you desire. (This is probably not what you wanted, but I included it just in case it was.)

Here's a quick snippet that creates a purplish color:

analogWrite( RED_LED , 64 ); // PWM at about one quarter intensity

analogWrite( BLUE_LED , 64 ); // PWM at about one quarter intensity

analogWrite( GREEN_LED , 0 ); // full off

And the color orange would be a tiny bit of green and blue, combined with a little red.

#include <io.h>
#include <signal.h>

#define BUTTON BIT3 // Port 1.3
#define REDLED BIT0 // Port 1.0
#define GRNLED BIT6 // Port 1.6

int doflip = 1;

int main(void) {
// Watchdog setup
WDTCTL = WDTPW + WDTHOLD; // stop watchdog (password + hold counter)

// LED initial setup
P1DIR |= REDLED + GRNLED; // set P1.0 and P1.6 as output (1) pins
P1OUT |= REDLED; // Enable REDLED
P1OUT &= ~GRNLED; // Disable GRNLED

// Button setup
P1DIR &= ~BUTTON; // button is an input
P1OUT |= BUTTON; // pull-up resistor
P1REN |= BUTTON; // resistor enabled
P1IES |= BUTTON; // interrupt on low-to-high transition
P1IE |= BUTTON; // interrupt enable

// Timer setup
BCSCTL3 |= LFXT1S_2; // Set clock source to VLO
TACCR0 = 2500; // Count to this, then interrupt
TACTL = TASSEL_1 | MC_1; // Clock source ACLK
TACCTL1 = CCIE; // Timer A interrupt enable

// Shut down CPU, General Interrupt Enabled
__bis_SR_register(CPUOFF | GIE);
return 0;
}

interrupt(TIMERA1_VECTOR) ta1_isr(void) {
TACCTL1 &= ~CCIFG; // reset the interrupt
if (doflip)
P1OUT ^= (REDLED + GRNLED); // flip LED output
}

interrupt(PORT1_VECTOR) port1_isr(void) {
P1IFG = 0; // reset interrupt
doflip ^= 1; // toggle LED flipping
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT