郭天祥MSP430教程源码-UART.zip
时间:10-27 14:37
查看:1076次
下载:162次
简介:
有关郭天祥MSP430教程源码-UART实验程序设计。
#include <msp430x14x.h>
#include "BoardConfig.h"
void main(void)
{
BoardConfig(0xb8);
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= UTXE0 + URXE0; // Enable USART0 TXD/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x0D; // 32k/2400 - 13.65
UBR10 = 0x00; //
UMCTL0 = 0x6B; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
IE1 |= URXIE0; // Enable USART0 RX interrupt
// Mainloop
for (;;)
{
_BIS_SR(LPM3_bits + GIE); // Enter LPM3 w/interrupt
while (!(IFG1 & UTXIFG0)); // USART0 TX buffer ready?
TXBUF0 = RXBUF0; // RXBUF0 to TXBUF0
}
}
// UART0 RX ISR will for exit from LPM3 in Mainloop
#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
_BIC_SR_IRQ(LPM3_bits); // Clear LPM3 bits from 0(SR)
}