#include #include #define interrupt(x) void __attribute__((interrupt (x))) uint8_t rxbyte; uint16_t rxbuf; // byte currently being received uint8_t rxbit; // current bit uint8_t rxdone; // done receiving byte void delay_ms(uint16_t ms) { while (ms--) __delay_cycles(1000); } void wait_for_button() { while (!(P1IN & 0x08)) ; delay_ms(20); while (P1IN & 0x08) ; delay_ms(20); } uint16_t add = 0; uint8_t debug[8]; uint8_t buf[32]; uint16_t bufp = 0; int main() { WDTCTL = WDTPW | WDTHOLD; BCSCTL1 = CALBC1_1MHZ; DCOCTL = CALDCO_1MHZ; __delay_cycles(16000); // Button P1REN |= 0x08; P1OUT |= 0x08; // Led P1DIR |= 0x01; UCA0CTL1 |= UCSSEL_2; // SMCLK clock // http://mspgcc.sourceforge.net/cgi-bin/msp-uart.pl?clock=1000000&baud=9600&submit=calculate //UCA0BR0 = 0x68; //UCA0BR1 = 0x00; //UCA0MCTL = 0x04; // http://mspgcc.sourceforge.net/cgi-bin/msp-uart.pl?clock=8000000&baud=57600&submit=calculate UCA0BR0 = 0x8A; UCA0BR1 = 0x00; UCA0MCTL = 0xEF; // UART P1SEL |= 0x02 | 0x04; P1SEL2 |= 0x02 | 0x04; // RXD on P1.1, TXD on P1.2 UCA0CTL1 &= ~UCSWRST; // Start UART IE2 |= UCA0RXIE; __enable_interrupt(); while (1) { wait_for_button(); P1OUT ^= 0x01; add++; } return 0; } interrupt(USCIAB0RX_VECTOR) uart_rx_isr() { debug[0]++; while (!(IFG2 & UCA0TXIFG)) ; uint8_t rec = UCA0RXBUF; buf[bufp] = rec; bufp = (bufp + 1) % 32; UCA0TXBUF = rec + add; }