日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀]初始化1 void Uart_Init(void)2 {3 BCSCTL1 = CALBC1_1MHZ; // Set DCO4 DCOCTL = CALDCO_1MHZ;5 P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD6 P1SEL2 = BIT1 + BIT2 ;

初始化



1 void Uart_Init(void)

2 {

3 BCSCTL1 = CALBC1_1MHZ; // Set DCO

4 DCOCTL = CALDCO_1MHZ;

5 P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD

6 P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD

7 UCA0CTL1 |= UCSSEL_2; // SMCLK

8 UCA0BR0 = 104; // 1MHz 9600

9 UCA0BR1 = 0; // 1MHz 9600

10 UCA0MCTL = UCBRS0; // Modulation UCBRSx = 1

11 UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**

12 IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

13 }


1 // Echo back RXed character, confirm TX buffer is ready first

2 #pragma vector=USCIAB0RX_VECTOR

3 __interrupt void USCI0RX_ISR(void)

4 {

5 while (!(IFG2&UCA0TXIFG)); // USCI_A0 TX buffer ready?

6 UCA0TXBUF = UCA0RXBUF; // TX -> RXed character

7 }




1 //發(fā)送數(shù)據(jù)

2 //發(fā)送字符

3 void uart_send_ch(unsigned char ch)

4 {

5

6 while(!(IFG2& UCA0TXIFG)); //查詢發(fā)送是否結(jié)束

7 UCA0TXBUF = ch;

8 IFG2&=~UCA0TXIFG; //清除發(fā)送一標志位

9 }

10

11 //發(fā)送字符串

12 void uart_send_str(char *str)

13 {

14 for( ; *str ; )

15 {

16 uart_send_ch((unsigned char)*str);

17 str++;

18 }

19 }


在用uart_send_str()發(fā)送一個數(shù)組合緊接著發(fā)送回車會出現(xiàn)亂碼,大約九個字符出現(xiàn),在中間delay一下解決了


char a[4];


uart_send_str(a);


__delay_cycles(5);


uart_send_huiche();



void uart_send_huiche(void)

{

uart_send_ch(0x0d);

uart_send_ch(0x0a);

}


本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉