新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > MSP430G2553測試程序(串口程序,USCI模式)

MSP430G2553測試程序(串口程序,USCI模式)

作者: 時間:2016-11-11 來源:網(wǎng)絡(luò) 收藏
//******************************************************************************

// HW UART(J4)!!!!!! 特別注意,板子上J4有2個跳線要豎放,設(shè)為HW UART模式
// MSP430G2xx3 Demo - USCI_A0, 9600 UART Echo ISR, DCO SMCLK
//
// Description: Echo a received character, RX ISR used. Normal mode is LPM0.
// USCI_A0 RX interrupt triggers TX Echo.
// Baud rate divider with 16MHz
// ACLK = n/a, MCLK = SMCLK = CALxxx_16MHZ = 16MHz
//
// MSP430G2xx3
// -----------------
// /|| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.2/UCA0TXD|------------>
// | | 9600 - 8N1
// | P1.1/UCA0RXD|<------------
//
// 修改http://jiwm.blog.163.com

本文引用地址:http://m.butianyuan.cn/article/201611/316568.htm

//串口調(diào)試助手,下載地址:http://www.sudt.com/download/AccessPort137.zip
// Texas Instruments Inc.
// February 2011
// Built with IAR Embedded Workbench Version: 5.40
//******************************************************************************
#include "msp430g2553.h"

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_16MHZ; // Set DCO
DCOCTL = CALDCO_16MHZ;
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2;
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 0x82; // 16MHz 9600 UCA0BRX=1666=0x0682
UCA0BR1 = 0x06; // 16MHz 9600
UCA0MCTL = UCBRS2 + UCBRS1; // Modulation UCBRSx = 6
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

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

// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}



評論


技術(shù)專區(qū)

關(guān)閉