#include #include void initPort(); void initUSCI(); void initInterrupt(); void main(void) { initPort(); initUSCI(); initInterrupt(); __enable_interrupt(); UCA0TXBUF = '0'; while(UCA0STAT & 0x1); UCA0TXBUF = '1'; while(UCA0STAT & 0x1); UCA0TXBUF = '2'; while(UCA0STAT & 0x1); UCA0TXBUF = '3'; while(UCA0STAT & 0x1); UCA0TXBUF = '4'; while(UCA0STAT & 0x1); while(1); } void initPort() { P1DIR = 0x0; //P1 is input (buttons at P1.0 and P1.1) P1SEL = 0x0; //select I/O for P1 P2OUT = 0; P2DIR = 0x6; //P2.2 and P2.1 are output P2SEL = 0x0; //select I/O for P2 } void initUSCI() { UCA0CTL1 = 0x1; //reset USCI UCA0CTL0 = 0x0; //no parity, LSB first, 8 data bits, one stop bit //UART-Mode, asynchronous mode UCA0CTL1 |= 0x80; //SMCLK as clock source UCA0BR0 = 0x09; UCA0BR1 = 0x00; UCA0MCTL = 0x2; //UCBRSx = 1, UCOS16 = 0, UCBRFx = 0 P2DIR |= 0x10; //P2.4 is USCI transmit P2DIR &= 0xdf; //P2.5 is USCI receive P2SEL |= 0x30; //select USCI-function for P2.4 UCA0CTL1 &= 0xfe; //clear UCSWRST } void initInterrupt() { P1IES = 0x3; //select high-to-low-transition for interrupts P1IFG = 0x0; //make sure no interrupts are pending P1IE = 0x3; //enable interrupts for P1.0 and P1.1 } #pragma vector=PORT1_VECTOR __interrupt void port1ISR(void) { if (P1IFG & 0x1) { //->interrupt on button S1 UCA0TXBUF = '1'; P1IFG &= 0xfe; //reset IRQ-bit } else if (P1IFG & 0x2) { //->interrupt on button S2 UCA0TXBUF = '2'; P1IFG &= 0xfd; //reset IRQ-bit } }