#include "msp.h" int main(void) { void delayMs(int n); P4->SEL1 &= ~0x03; /* configure P4.1-P4.0 as simple I/O output */ P4->SEL0 &= ~0x03; P4->DIR |= 0x03; 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 &= ~0x02; /* Relay 2 = Off */ delayMs(100); /* wait 0.1 second */ P4->OUT |= 0x01; /* Relay 1 = On */ while((P6->IN & 0x02) == 0); /* wait till switch change */ } else { /* P6.1 == 1 */ P4->OUT &= ~0x01; /* Relay 1 = Off */ delayMs(100); /* wait 0.1 second */ P4->OUT |= 0x02; /* Relay 2 = On */ 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 = 250; i > 0; i--); /* delay 1 ms */ }