/* www.microDigitalEd.com * p2_5.c Read a switch and write it to the LED. * * This program reads an external SW connected to P1.1 and writes * the value to the red LED on P2.0. * When switch is pressed, it connects P1.1 to ground and bit 1 of * P1IN reads as '0'. P1.1 pin pull-up is enabled so that it is high * when the switch is not pressed and bit 1 of P1IN reads as '1'. * The LEDs are high active (a '1' turns ON the LED). * * Tested with Keil 5.20 and MSP432 Device Family Pack V2.2.0 * on XMS432P401R Rev C. */ #include "msp.h" int main(void) { P1->SEL1 &= ~2; /* configure P1.1 as simple I/O */ P1->SEL0 &= ~2; P1->DIR &= ~2; /* P1.1 set as input */ P1->REN |= 2; /* P1.1 pull resistor enabled */ P1->OUT |= 2; /* Pull up/down is selected by P1->OUT */ P2->SEL1 &= ~1; /* configure P2.0 as simple I/O */ P2->SEL0 &= ~1; P2->DIR |= 1; /* P2.0 set as output pin */ while (1) { if (P1->IN & 2) /* use switch 1 to control red LED */ P2->OUT &= ~1; /* turn off P2.0 red LED when SW is not pressed */ else P2->OUT |= 1; /* turn on P2.0 red LED when SW is pressed */ } }