|
网上例子大把啊,随便找一个符合的试一下咯。
//******************************************************************************
// MSP-FET430P140 Demo - USART1, Ultra-Low Pwr UART 9600 Echo ISR, 32kHz ACLK
//
// Description: Echo a received character, RX ISR used. Normal mode is LPM3,
// USART1 RX interrupt triggers TX Echo.
// ACLK = UCLK1 = LFXT1 = 32768, MCLK = SMCLK = DCO~ 800k
// Baud rate divider with 32768hz XTAL @9600 = 32768Hz/9600 = 3.41 (0003h 4Ah )
// //* An external watch crystal is required on XIN XOUT for ACLK *//
//
//
// MSP430F149
// -----------------
// /|\| XIN|-
// | | | 32kHz
// --|RST XOUT|-
// | |
// | P3.6|----------->
// | | 9600 - 8N1
// | P3.7|<-----------
//
//
// M. Buccini
// Texas Instruments Inc.
// Feb 2005
// Built with IAR Embedded Workbench Version: 3.21A
//******************************************************************************
#include <msp430x14x.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0xC0; // P3.6,7 = USART1 TXD/RXD
ME2 |= UTXE1 + URXE1; // Ena××e USART1 TXD/RXD
UCTL1 |= CHAR; // 8-bit character
UTCTL1 |= SSEL0; // UCLK = ACLK
UBR01 = 0x03; // 32k/9600 - 3.41
UBR11 = 0x00; //
UMCTL1 = 0x4A; // Modulation
UCTL1 &= ~SWRST; // Initialize USART state machine
IE2 |= URXIE1; // Ena××e USART1 RX interrupt
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/ interrupt
}
#pragma vector=UART1RX_VECTOR
__interrupt void usart1_rx (void)
{
while (!(IFG2 & UTXIFG1)); // USART1 TX buffer ready?
TXBUF1 = RXBUF1; // RXBUF1 to TXBUF1
} |
|