#include <msp430.h>int main(void)
{WDTCTL = WDTPW | WDTHOLD; P3SEL = BIT3 + BIT4; UCA0CTL1 |= UCSWRST; UCA0CTL1 |= UCSSEL_1; UCA0BR0 = 0x0D; UCA0BR1 = 0x00; UCA0MCTL |= UCBRS_6 + UCBRF_0; UCA0STAT |= UCLISTEN; UCA0CTL1 &= ~UCSWRST; P1DIR |= (BIT3 + BIT4); P1OUT &= ~(BIT3 + BIT4); while (1){if (UCA0STAT | UCPE) {P1OUT |= BIT3; }else{P1OUT &= ~ BIT3; }if (UCA0STAT | UCOE) {P1OUT |= BIT4; }else{P1OUT &= ~BIT4; }}}
#include <msp430.h>int main(void)
{char key1_ifg, key2_ifg, key3_ifg; WDTCTL = WDTPW | WDTHOLD; P1DIR |= (BIT0 + BIT1 + BIT2 + BIT3); P1OUT &= ~(BIT0 + BIT1 + BIT2 + BIT3); P1DIR &= ~(BIT4 + BIT5 + BIT6); P1REN |= (BIT4 + BIT5 + BIT6); P1OUT |= (BIT4 + BIT5 + BIT6); while (1){if ((P1IN & BIT4) == 0) {key1_ifg = 1; }else{key1_ifg = 0;}if ((P1IN & BIT5) == 0) {key2_ifg = 1; }else{key2_ifg = 0;}if ((P1IN & BIT6) == 0) {key3_ifg = 1; }else{key3_ifg = 0;}if (key1_ifg == 1 || key2_ifg == 1) {P1OUT |= BIT0; }else{P1OUT &= ~BIT0; }if (key2_ifg == 1 && key3_ifg == 1) {P1OUT |= BIT1; }else{P1OUT &= ~BIT1; }if ((key1_ifg == 1 && key3_ifg == 0)|| (key1_ifg == 0 && key3_ifg == 1)) {P1OUT |= BIT2; }else{P1OUT &= ~BIT2; }if (key1_ifg == 1) {P1OUT |= BIT3; }if (key2_ifg == 1) {P1OUT &= ~BIT3; }}}
#include <msp430.h>int main(void)
{WDTCTL = WDTPW + WDTHOLD; P1DIR |= (BIT0 + BIT1 + BIT2);P1OUT &= ~(BIT0 + BIT1 + BIT2);TA0CCTL0 = CCIE; TA0CCR0 = 327; TA0CTL = TASSEL_1 + MC_1 + TACLR; __bis_SR_register(LPM0_bits + GIE); }int led1_ifg, led2_ifg, led3_ifg;
#pragma vector=TIMER0_A0_VECTOR
__interrupt void TIMER0_A0_ISR(void)
{led1_ifg = (led1_ifg + 1) % 100;if (led1_ifg < 50){P1OUT |= BIT0;}else{P1OUT &= BIT0;}led2_ifg = (led2_ifg + 1) % 50;if (led2_ifg < 25){P1OUT |= BIT1;}else{P1OUT &= BIT1;}led3_ifg = led3_ifg + 1) % 100;if led3_ifg < 25){P1OUT |= BIT2;}else{P1OUT &= BIT2;}
}