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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > LPC1114 UART收發(fā)實(shí)驗(yàn)

          LPC1114 UART收發(fā)實(shí)驗(yàn)

          作者: 時(shí)間:2016-11-10 來源:網(wǎng)絡(luò) 收藏
          串口是很多實(shí)驗(yàn)的基礎(chǔ),可以作為其他實(shí)驗(yàn)運(yùn)行的驗(yàn)證。在做LPC1114 UART實(shí)驗(yàn)時(shí),發(fā)現(xiàn)的例程只有發(fā)送函數(shù),而且是發(fā)送字符串的,所以本人完善了一些,添加了一個(gè)發(fā)送字符串的函數(shù)UARTSendByte(),一個(gè)接受字符的函數(shù)UARTReceiveByte(),一個(gè)接受字符串函數(shù)UARTReceive()。具體的代碼如下:

          // 發(fā)送字符函數(shù)

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

          /*****************************************************************************
          ** Function name:UARTSendByte
          **
          ** Descriptions:Send a block of data to the UART 0 port based
          **on the data Byte
          **
          ** parameters:send data
          ** Returned value:None
          **
          *****************************************************************************/
          void UARTSendByte(uint8_t dat)
          {
          while ( !(LPC_UART->LSR & LSR_THRE) )
          {
          ; // 等待數(shù)據(jù)發(fā)送完畢
          }

          LPC_UART->THR = dat;
          }

          // 接受字符函數(shù)

          /*****************************************************************************
          ** Function name:UARTReceiveByte
          **
          ** Descriptions:Receive a block of data to the UART 0 port based
          **on the data Byte
          **
          ** parameters:None
          ** Returned value:Byte
          **
          *****************************************************************************/
          uint8_t UARTReceiveByte(void)
          {
          uint8_t rcvData;

          while (!(LPC_UART->LSR & LSR_RDR))
          {
          ; // 查詢數(shù)據(jù)是否接收完畢
          }

          rcvData = LPC_UART->RBR; // 接收數(shù)據(jù)
          return (rcvData);
          }

          // 接收字符串函數(shù)

          /*****************************************************************************
          ** Function name:UARTReceive
          **
          ** Descriptions:Receive a block of data to the UART 0 port based
          **on the data Length
          **
          ** parameters:buffer pointer, and data length
          ** Returned value:Note
          **
          *****************************************************************************/
          void UARTReceive(uint8_t *BufferPtr, uint32_t Length)
          {
          while (Length--)
          {
          *BufferPtr++ = UARTReceiveByte(); // 把數(shù)據(jù)放入緩沖
          }
          }

          // 主函數(shù)

          int main(void) {

          // TODO: insert code here
          uint8_t ch = 0;

          UARTInit(9600);
          LPC_UART->IER = IER_THRE | IER_RLS; // 設(shè)置中斷使能寄存器

          UARTSend((uint8_t *)Buffer, 10);

          while (1)
          {
          ch = UARTReceiveByte(); // 接收字符
          if (ch != 0x00)
          {
          UARTSendByte(ch); // 發(fā)送接收數(shù)據(jù)
          }
          }

          // Enter an infinite loop, just incrementing a counter
          volatile static int i = 0 ;
          while(1) {
          i++ ;
          }
          return 0 ;
          }

          實(shí)驗(yàn)圖片如下:

          c510d9abb6b297dd281662e4c8c&t=1274344745¬humb=yes" rel="nofollow" target="_blank">IMG_3380.JPG(70.52 KB)

          2010-5-14 06:54

          IMG_3381.JPG(76.79 KB)

          2010-5-14 06:54

          IMG_3382.JPG(72.08 KB)

          2010-5-14 06:54

          串口我用的是USB轉(zhuǎn)串口進(jìn)行調(diào)試的,如果先打開串口進(jìn)行,再連接實(shí)驗(yàn)板時(shí)會(huì)提示如下:

          此時(shí)如果點(diǎn)擊"OK",將提示如下錯(cuò)誤:

          此時(shí)應(yīng)該點(diǎn)擊如下圖紅圈的地方,LPC-Link,然后點(diǎn)擊“OK”即可正常連接。

          2010-5-14 07:10




          關(guān)鍵詞: LPC1114UART收發(fā)實(shí)

          評(píng)論


          技術(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); })();