|
本帖最后由 司马朝阳 于 2013-4-16 15:33 编辑
我用msp430g2533 编写的串口通信,只要打开串口调试助手,他就自动发送数据。高手们帮忙看看,那个地方出错了。
程序如下
#include "msp430G2553.h"
#include "stdio.h"
int a[8],i;
void Init_uart0()
{
UCA0CTL1|=UCSWRST;
UCA0CTL0&=~UC7BIT; //字符长度为8
UCA0CTL1|=UCSSEL_2; //选择系统时钟
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; //paizhi shizhong
DCOCTL = CALDCO_1MHZ;
Init_uart0();
_EINT();
while(1)
{
Uart0Sends("朋友");
__delay_cycles (1048576); //延时
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void usart0_rx(void)
{
while((IFG2&UCA0RXIFG )==0);
//a=RXBUF0;
//i++;
i=UCA0RXBUF;
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|