#include "msp430x54x.h"
void main(void)
{ WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P5SEL |=BIT6+BIT7; //USCI_A1 TXD/RXD
P5DIR |=BIT5+BIT6;
P5OUT &=~BIT5;
UCA1CTL1 |= UCSWRST; // **Put state machine in reset**
UCA1CTL1 |= UCSSEL_1; // CLK = ACLK
UCA1BR0 = 0x03; // 32kHz/9600=3.41 (see User's Guide)
UCA1BR1 = 0x00; //
UCA1MCTL = UCBRS_3+UCBRF_0; // Modulation UCBRSx=3, UCBRFx=0
UCA1CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
UCA1IE |= UCRXIE+UCTXIE; // Enable USCI_A0 RX interrupt
__bis_SR_register(LPM3_bits + GIE); // Enter LPM3, interrupts enabled
__no_operation(); // For debugger
}
// Echo back RXed character, confirm TX buffer is ready first
#pragma vector=USCI_A1_VECTOR
__interrupt void USCI_A1_ISR(void)
{
switch(__even_in_range(UCA1IV,4))
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA1IFG&UCTXIFG)); // USCI_A1 TX buffer ready?
UCA1TXBUF = UCA1RXBUF; // TX -> RXed character
P5OUT |=BIT5;
while (!(UCA1IFG&UCTXIFG));
P5OUT &=~BIT5;
break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}
这是用TI的一个例程改的程序,只是将232改为485而已,但MCU总是停在低功耗状态无法进入中断或者停在红 {MOD}语句处,一步一步调试时只能进行一次中断,但串口助手无数据显示,已经检查过引脚,没有问题的,不知道哪里出错了,请高手指教
此帖出自
小平头技术问答
一周热门 更多>