#include"msp430g2553.h"
#define uint unsigned int //变量定义
#define uchar unsigned char
void main()
{
WDTCTL =WDTHOLD +WDTPW;
BCSCTL1 =CALBC1_1MHZ;
DCOCTL =CALDCO_1MHZ;
BCSCTL2 =DIVS_0;
P1SEL |=BIT1+BIT2;
P1SEL2 |=BIT1 +BIT2;
//UCA0CTL1 =UCSWRST; //USCI复位
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0MCTL = UCBRS2 + UCBRS0; // Modulation UCBRSx = 5
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // 串口使能开启
__bis_SR_register( GIE); // 总中断使能
while(1){}
}
void send_byte(uchar date) //串口发送数据
{
while (!(IFG2&UCA0TXIFG)); //发送寄存器空的时候 发送数据
UCA0TXBUF=date;
}
void print_str(uchar *s) //串口发送字符串
{
while(*s)
{
send_byte(*s++);
}
}
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
uchar date=0;
date=UCA0RXBUF; //存取接受数据
send_byte(date); //数据在发送
}
此帖出自
小平头技术问答
一周热门 更多>