Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am doing C programming using an MSP430 attached to external buttons. At this stage in my project, I am trying to make it so

I am doing C programming using an MSP430 attached to external buttons. At this stage in my project, I am trying to make it so that the default state before buttons pressed is no RGB LEDs on, but when you press a button, the RGB LED will turn on for a time and be a corresponding color. I had it working fine with two buttons (green and blue) but when I added two more, for some reason the RGB LED is now flashing different colors, like pink and violet in its resting state and pressing a button changes the color to a color that is not the desired one. Here is my code; most of the comments are not correct.

#include

#define LED0 BIT0 #define LED1 BIT6 #define RGB_LED_all BIT1|BIT2|BIT3|BIT4|BIT5 #define BUTTON BIT2 //Bit3 = 0x08 =P1.3 #define BUTTON2 BIT3 //Bit2= 0x04 =P1.2 #define BUTTON3 BIT4 //Bit2= 0x04 =P1.2 #define BUTTON4 BIT5 //Bit2= 0x04 =P1.2

int main(void) { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P2DIR |= RGB_LED_all; P2SEL &= ~RGB_LED_all; P2SEL2 &= ~RGB_LED_all; //P1DIR |= BIT3 + BIT2; //P1OUT |= 0x00; P1REN |= 0x08;

P2OUT &= ~RGB_LED_all; //~(0x10 + 0x04 + 0x02); P1IE |= (BUTTON); // P1.3 interrupt enabled P1IE |= (BUTTON2); P1IE |= (BUTTON3); P1IE |= (BUTTON4);

P1IFG &= ~(BUTTON); // P1.3 IFG cleared P1IFG &= ~(BUTTON2); P1IFG &= ~(BUTTON3); P1IFG &= ~(BUTTON4);

__enable_interrupt(); // enable all interrupts for(;;) {} }

// Port 1 interrupt service routine #pragma vector=PORT1_VECTOR __interrupt void Port_1(void) { if (!(P1IN & 0x08)){ //P2OUT &= ~0x10; P2OUT = (0x10); //blue

//P1IES ^= BUTTON; // toggle the interrupt edge, //P1IES ^= BUTTON2; } if (!(P1IN & 0x04)){ //P2OUT &= ~0x04; P2OUT = (0x04); // color

// P1IES ^= BUTTON2; // toggle the interrupt edge, //P1IES ^= BUTTON; // toggle the interrupt edge, } if (!(P1IN & 0x10)){ //P2OUT &= ~0x06; P2OUT = (0x06); // color

// P1IES ^= BUTTON2; // toggle the interrupt edge, //P1IES ^= BUTTON; // toggle the interrupt edge, } if (!(P1IN & 0x20)){ //P2OUT &= ~0x12; P2OUT = (0x12); // color

// P1IES ^= BUTTON2; // toggle the interrupt edge, //P1IES ^= BUTTON; // toggle the interrupt edge, } else if(P1IN & 0xCC) { P2OUT &= ~RGB_LED_all; P1IFG &= ~BUTTON; // P1.3 IFG cleared P1IFG &= ~BUTTON2; P1IFG &= ~BUTTON3; P1IFG &= ~BUTTON4; }

/* else if (P1IN & BUTTON3){ P2OUT ^= (0x02); // P1.0 = toggle P1IFG &= ~BUTTON3; // P1.3 IFG cleared P1IES ^= BUTTON3; // toggle the interrupt edge, } else if (P1IN & BUTTON4){ P2OUT ^= (0x12); // P1.0 = toggle P1IFG &= ~BUTTON; // P1.3 IFG cleared P1IES ^= BUTTON; // toggle the interrupt edge, } // the interrupt vector will be called // when P1.3 goes from HitoLow as well as // LowtoHigh */ }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions