下面的程序可以让MSP430通过串口传输数据给PC,但我想通过串口调试助手发送数据给MSP430,并且在接收中断中改变430单片机的状态(如点亮Led灯,方便观测实验结果)。那么应该怎么写,请高手指教!
#include "msp430G2553.h"
#include "stdio.h"
unsigned char a[8];
void Init_uart0()
{
UCA0CTL1|=UCSWRST; //UCA0软件复位
//UCA0CTL0&=~UC7BIT;//字符长度为8
UCA0CTL1|=UCSSEL_2;//选择系统时钟:SMCLK
UCA0BR0=0x6D; //波特率为9600
UCA0BR1=0;
UCA0MCTL=0;//UCA0MCTL=UCBRS0;
IE2=UCA0RXIE+UCA0TXIE;//开接收使能
UCA0CTL1&=~UCSWRST;
P1SEL|=BIT1+BIT2; //将P1.1 P1.2设为第二功能
P1SEL2|=BIT1+BIT2;
}
void Uart0Sends(char *s)
{
while(*s!='\0')
{
UCA0TXBUF=*s;
while((IFG2&UCA0TXIFG)==0); //查询发送是否结束
IFG2&=~UCA0TXIFG; //清除发送一标志位
s++;
}
}
void main( )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
BCSCTL1 = CALBC1_1MHZ;
DCOCTL = CALDCO_1MHZ;
Init_uart0();
_EINT();
while(1)
{
Uart0Sends("ni hao");
__delay_cycles (1048576);
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void usart0_rx(void)
{
while((IFG2&UCA0RXIFG)==0);
//a=RXBUF0;
//i++;
a[0]=UCA0RXBUF;
} |