大哥,还是得手动复位,加延时都不行,麻烦看看才行那有问题,多谢了。
#include "msp430g2553.h"
#define uchar unsigned char
#define uint unsigned int
# define LED1_1 P1OUT |= BIT0
# define LED1_0 P1OUT &= ~BIT0
# define LED2_1 P1OUT |= BIT6
# define LED2_0 P1OUT &= ~BIT6
/*****系统时钟初始化*****/
void Clock_Init()
{
//BCSCTL2 |= SELS;
//BCSCTL1 = CALBC1_8MHZ;//MCLK为DCO,8MHZ
//DCOCTL = CALDCO_8MHZ;
BCSCTL1 = CALBC1_1MHZ;//MCLK为DCO,8MHZ
DCOCTL = CALDCO_1MHZ;
}
void delay_us( uchar k )
{
uchar i,j;
for( i=0;i<100;i++ )
for( j=100;j<100;j++ );
}
/*****串口设置*****/
void UART_Init()
{
P1SEL = BIT1 + BIT2;//P1.1 P1.2设置为TXD,RXD
P1SEL2 = BIT1 + BIT2;
delay_us(10);
UCA0CTL1 |= UCSWRST;
UCA0CTL1 |= UCSSEL_1; //ACLK
UCA0BR0 = 3; // ACLK 32768Hz 9600 32768Hz/9600 = 3.41
UCA0BR1 = 0; // 32768Hz 9600
UCA0MCTL = UCBRS1 + UCBRS0; // Modulation UCBRSx = 3
//UCA0CTL1 |= UCSWRST;
//UCA0CTL1 &= ~UCSWRST;
UCA0CTL1 &= (~UCSWRST);//串口设置完毕,在UCSWRST=1时设置串口
UC0IE |= UCA0TXIE + UCA0RXIE;//使能接收和发送中断
}
/*****串口发送数据函数*****/
void Send_Byte(uchar data)
{
while(IFG2 & UCA0TXIFG == 0);//发送寄存器空的时候发送数据
UCA0TXBUF = data;
}
/*****处理来自串口的接收中断*****/
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
uchar data = 0;
data = UCA0RXBUF;//接收到的数据存起来
Send_Byte(data);//将接收到的数据再发送出去
}
/*****处理来自串口的发送中断*****/
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
}
/*****主函数*****/
int main( void )
{
WDTCTL = WDTPW + WDTHOLD;
Clock_Init();
UCA0CTL1 &= ~UCSWRST;
UART_Init();//串口初始化
//_EINT();//开中断
while(1)
{
Send_Byte('n');
Send_Byte('s');
}
}