All pastes #2113128 Raw Edit

Stuff

public text v1 · immutable
#2113128 ·published 2012-02-08 17:49 UTC
rendered paste body
int main(void)
{
// Stop watchdog
  WDTCTL = WDTPW + WDTHOLD;

  // Todo maybe remove the defaults?
  // Not necessary as they default to input just like arduino
  P1DIR = 255; // All input (arduino's default?)
  P2DIR = 255; // All input
  P1SEL = 0; // All GPIO
  #ifdef P2SEL
  P3SEL = 0; // All GPIO
  #endif
  #ifdef P3SEL
  P3SEL = 0; // All GPIO
  #endif
  #ifdef P4SEL
  P3SEL = 0; // All GPIO
  #endif
  setup();
  for(;;) {
   loop();
  }

  return 0;
}

void setup() {
    BCSCTL1 = CALBC1_1MHZ;                    // Set DCO (already set by arduino.h to 16mhz, so skip it)

    DCOCTL = CALDCO_1MHZ;

    P1SEL = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

    P1SEL2 = BIT1 + BIT2 ;                     // P1.1 = RXD, P1.2=TXD

    UCA0CTL1 |= UCSSEL_2;                     // SMCLK

    UCA0BR0 = 104;                            // 1MHz 9600
    UCA0BR1 = 0;
    //UCA0BR0 = (F_CPU/9600)&0xFF;

    //UCA0BR1 = (F_CPU/9600)/256;

    UCA0MCTL = UCBRS0;                        // Modulation UCBRSx = 1

    UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**

    IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt



    //__bis_status_register(LPM0_bits + GIE);       // Enter LPM0, interrupts enabled
}

//  Echo back RXed character, confirm TX buffer is ready first

interrupt(USCIAB0RX_VECTOR) ucarx_isr(void)

{

  while (!(IFG2&UCA0TXIFG));                // USCI_A0 TX buffer ready?

  UCA0TXBUF = UCA0RXBUF;                    // TX -> RXed character
  __bis_status_register(LPM4_bits|GIE);

}

void loop() {
}