Question: I have this code in CCS for a MSP432, whenever I press the button the LED turn on, but once I let go of the

I have this code in CCS for a MSP432, whenever I press the button the LED turn on, but once I let go of the button it turn off. I want it to stay on. How could I do that?

uint8_t DebounceSwitch1(void);

void pin_initial(void); void main(void) { WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer pin_initial();

while(1){

//DebounceSwitch1();

if(DebounceSwitch1() == 1){ P2OUT |= 0x01; // TURNS ON RED LED }

}

void pin_initial(void){ P1->SEL1 &= ~0x02; //SWITCH 1 P1->SEL0 &= ~0x02; P1REN |= 0x02; // SWITCH1 PULL RESISTOR ENABLED P1->DIR &= ~0x02; // SWITCH 1 IS SET AS AN INPUT P1OUT |= 0x02; // PULL UP RESISTOR

P2SEL1 &= ~0x01; // RED_LED PIN 2.0 P2SEL0 &= ~0x01; P2DIR |= 0x01; //RED_LED OUTPUT PIN P2OUT &= ~0x01; //RED LED OFF

}

uint8_t DebounceSwitch1(void) { uint8_t pin_value = 0; if((P1IN & 0x02) == 0x00){ _delay_cycles(15000); // delay for 5ms if((P1IN & 0x02) == 1) pin_value = 1; else return 0; } return pin_value;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!