//
//
//MSP430G2xx3
//—————–
///||XIN|-
//| ||
//–|RSTXOUT|-
//||
//|CCI0B/TXD/P1.1|——–>
//|| 9600 8N1
//|CCI0A/RXD/P1.2|<--------
// Built withIAR Embedded Workbench Version: 5.40
//串口调试帮手,下载地址:http://www.sudt.com/download/AccessPort137.zip
//******************************************************************************
#include “msp430g2553.h”
//——————————————————————————
// Hardware-related definitions
//——————————————————————————
#define UART_TXD0x02// TXD on P1.1 (Timer0_A.OUT0)
#define UART_RXD0x04// RXD on P1.2 (Timer0_A.CCI1A)
//——————————————————————————
// Conditions for 9600 Baud SW UART, SMCLK = 1MHz,设置波特率,只是修正下面一下数据即可,如9600,2400
//9600,2400作业安稳。波特率不宜太高。
//——————————————————————————
#define UART_TBIT_DIV_2(1000000 / (9600 * 2))
#define UART_TBIT(1000000 / 9600)
//——————————————————————————
// Global variables used for full-duplex UART communication
//——————————————————————————
unsigned int txData;// UART internal variable for TX
unsigned char rxBuffer;// Received UART character
//——————————————————————————
// Function prototypes
//——————————————————————————
void TimerA_UART_init(void);
void TimerA_UART_tx(unsigned char byte);
void TimerA_UART_print(char *string);
//——————————————————————————
// main()
//——————————————————————————
void main(void)
{
WDTCTL = WDTPW + WDTHOLD;// Stop watchdog timer
DCOCTL = 0x00;// Set DCOCLK to 1MHz
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
P1OUT = 0x00;// Initialize all GPIO
P1SEL = UART_TXD + UART_RXD;// Timer function for TXD/RXD pins
P1DIR = 0xFF & ~UART_RXD;// Set all pins but RXD to output
P2OUT = 0x00;
P2SEL = 0x00;
P2DIR = 0xFF;
__enable_interrupt();
TimerA_UART_init();// Start Timer_A UART
TimerA_UART_print(“G2553 TimerA UART”);
TimerA_UART_print(“READY.Echo Input,and Monitor.”);
for (;;)
{
// Wait for incoming character
__bis_SR_register(LPM0_bits);
// Update board outputs according to received byte,依据接收到的数据点亮发光管
//主张16进制,例如01H P1.0亮 11H P1.0 1.6亮
if (rxBuffer & 0x01) P1OUT |= 0x01; else P1OUT &= ~0x01;// P1.0
if (rxBuffer & 0x02) P1OUT |= 0x08; else P1OUT &= ~0x08;// P1.3
if (rxBuffer & 0x04) P1OUT |= 0x10; else P1OUT &= ~0x10;// P1.4
if (rxBuffer & 0x08) P1OUT |= 0x20; else P1OUT &= ~0x20;// P1.5
if (rxBuffer & 0x10) P1OUT |= 0x40; else P1OUT &= ~0x40;// P1.6
if (rxBuffer & 0x20) P1OUT |= 0x80; else P1OUT &= ~0x80;// P1.7
if (rxBuffer & 0x40) P2OUT |= 0x40; else P2OUT &= ~0x40;// P2.6
if (rxBuffer & 0x80) P2OUT |= 0x80; else P2OUT &= ~0x80;// P2.7
// Echo received character,回传发送的数据
TimerA_UART_tx(rxBuffer);//
}
}
//——————————————————————————
// Function configures Timer_A for full-duplex UART operation
//——————————————————————————
void TimerA_UART_init(void)
{
TACCTL0 = OUT;// Set TXD Idle as Mark = 1
TACCTL1 = SCS + CM1 + CAP + CCIE;// Sync, Neg Edge, Capture, Int
TACTL = TASSEL_2 + MC_2;// SMCLK, start in continuous mode
}
//——————————————————————————
// Outputs one byte using the Timer_A UART
//——————————————————————————
void TimerA_UART_tx(unsigned char byte)
{
while (TACCTL0 & CCIE);