P1OUT = UART_TXD; // Initialize P1.1
P1SEL = UART_TXD; // Timer function for TXD pin
P1DIR = UART_TXD; // Set TXD pin to output
// Timer_A for transmit UART operation
TA0CCTL0 = OUT; // Set TXD Idle as Mark = '1'
TA0CCTL1 = SCS + CM1 + CAP; // Sync, Neg Edge, Capture
TA0CTL = TASSEL_2 + MC_2; // SMCLK, start in continuous mode
P2DIR |= (BIT3 | BIT4); //Set P1.0 and P1.6 to outputs
_BIS_SR(GIE); // Enable CPU interrupts
while (1) {
TimerA_UART_print("G2553 TimerA UART\r\n"); // Send test message
TimerA_UART_print("READY.\r\n");
P2OUT ^= 0x18;
delay1s();
}
}
void TimerA_UART_tx(unsigned char byte) // Outputs one byte using the Timer_A UART
{
while (TACCTL0 & CCIE); // Ensure last char got TX'd
TA0CCR0 = TAR; // Current state of TA counter
TA0CCR0 += UART_TBIT; // One bit time till first bit
txData = byte; // Load transmit data, e.g. 'A'=01000001
txData |= 0x100; // Add mark stop bit, e.g. 101000001
txData <<= 1; // Add space start bit, e.g. 1010000010
TA0CCTL0 = OUTMOD0 + CCIE; // Set TXD on, enable counter interrupt
}
void TimerA_UART_print(char *string) { // Prints a string using the Timer_A UART
while (*string)
TimerA_UART_tx(*string++);
}