<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > msp430g2553與串口通信的驅(qū)動程序

          msp430g2553與串口通信的驅(qū)動程序

          作者: 時間:2016-11-28 來源:網(wǎng)絡(luò) 收藏
          #include "uart.h"

          #include <msp430g2553.h>
          #include "typedef.h"

          本文引用地址:http://www.ex-cimer.com/article/201611/322700.htm

          rece_data uart_buf; //串口緩沖區(qū)

          void init_uart_buf(void)
          {
          uart_buf.head = 0;
          uart_buf.tail = uart_buf.head;
          }

          //獲取串口數(shù)據(jù)
          u8 get_uart_data(u8* data)
          {
          if(uart_buf.tail == uart_buf.head)
          {
          return 0;
          }
          *data = uart_buf.buf[uart_buf.head];
          uart_buf.head = (uart_buf.head + 1) % BUF_SIZE;
          return 1;
          }

          //保存串口數(shù)據(jù)
          void save_uart_data(u8 data)
          {
          uart_buf.buf[uart_buf.tail] = data;
          uart_buf.tail = (uart_buf.tail + 1) % BUF_SIZE;
          }

          //串口初始化
          void uart_Init(void)
          {
          WDTCTL = WDTPW + WDTHOLD;// Stop WDT
          BCSCTL1 = CALBC1_1MHZ;// Set DCO
          DCOCTL = CALDCO_1MHZ;
          P1SEL = BIT1 + BIT2 ;// P1.1 = RXD, P1.2=TXD
          P1SEL2 = BIT1 + BIT2 ;// P1.1 = RXD, P1.2=TXD

          UCA0CTL1 |= UCSSEL_2;// SMCLK
          UCA0BR0 = 104;// 1MHz 9600
          UCA0BR1 = 0;// 1MHz 9600
          UCA0MCTL = UCBRS0;// Modulation UCBRSx = 1
          UCA0CTL1 &= ~UCSWRST;// **Initialize USCI state machine**
          IE2 |= UCA0RXIE;// Enable USCI_A0 RX interrupt
          _EINT();//Enable interrupt
          init_uart_buf();
          }

          //發(fā)送數(shù)據(jù)
          //發(fā)送字符
          void uart_send_ch(u8 ch)
          {

          while(!(IFG2& UCA0TXIFG)); //查詢發(fā)送是否結(jié)束
          UCA0TXBUF = ch;
          IFG2&=~UCA0TXIFG; //清除發(fā)送一標志位
          }

          //發(fā)送字符串
          void uart_send_str(char *str)
          {
          for( ; *str ; )
          {
          uart_send_ch((u8)*str);
          str++;
          }
          }

          //Echo back RXed character, confirm TX buffer is ready first
          #pragma vector=USCIAB0RX_VECTOR
          __interrupt void USCI0RX_ISR(void)
          {
          u8 data;
          while (!(IFG2&UCA0TXIFG));// USCI_A0 TX buffer ready?
          //UCA0TXBUF = UCA0RXBUF;// TX -> RXed character
          data = UCA0RXBUF;
          save_uart_data(data);//保存數(shù)據(jù)
          }



          評論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();