#include "msp.h" int main(void) { void delayMs(int n); P4->SEL1 &= ~0x0F; /* configure P4.3-P4.0 as simple I/O output */ P4->SEL0 &= ~0x0F; P4->DIR |= 0x0F; P6->SEL1 &= ~0x02; /* configure P6.1 as simple I/O input */ P6->SEL0 &= ~0x02; P6->DIR &= ~0x02; P6->REN |= 0x02; /* P6.1 pull-up resistor enabled */ P6->OUT |= 0x02; while (1) { if((P6->IN & 0x02) == 0) { /* P6.1 == 0 */ P4->OUT &= ~0x0F; /* open all switches */ delayMs(100); /* wait 0.1 second */ P4->OUT |= 0x09; /* close SW1 & SW4 */ while((P6->IN & 0x02) == 0); /* wait till switch change */ } else { /* P6.1 == 1 */ P4->OUT &= ~0x0F; /* open all switches */ delayMs(100); /* wait 0.1 second */ P4->OUT |= 0x06; /* close SW2 & SW3 */ while((P6->IN & 0x02) != 0); /* wait till switch change */ } } } /* delay milliseconds when system clock is at 3 MHz */ void delayMs(int n) { int i, j; for (j = 0; j < n; j++) for (i = 750; i > 0; i--); /* delay 1 ms */ }