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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > LPC21XX 串口的接收和發(fā)送中斷(MDK)

          LPC21XX 串口的接收和發(fā)送中斷(MDK)

          作者: 時(shí)間:2016-11-09 來源:網(wǎng)絡(luò) 收藏
          由于使用檢測(cè)方式僅適合于數(shù)據(jù)量少的設(shè)備中使用,當(dāng)需要發(fā)送或者接收大量數(shù)據(jù)時(shí)應(yīng)該采用串口中斷接收或發(fā)送的方式。

          /*============================================================
          LPC21XX 串口使用接收發(fā)送中斷
          ==============================================================
          本例程的CCLK=60M.
          晶振采用12M
          倍頻系數(shù)為:5
          分頻系數(shù)為:2
          以上設(shè)置在Startup.s中設(shè)置
          */
          #include
          #include "Config.H"
          #define UART_BAUD(baud) (unsigned int)(Fpclk/(baud * 16))
          uint8 buffer[100];
          uint8 SendLen;//發(fā)送數(shù)據(jù)長(zhǎng)度
          uint8 SendCount;//數(shù)據(jù)發(fā)送計(jì)數(shù)
          uint8 SendData[256];
          void Init_Uart0(unsigned int Baud)
          {
          /* initialize the serial interface */
          PINSEL0 = 0x00000005; /* Enable RxD0 and TxD0 */
          U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
          U0DLM=(unsigned char)(Baud>>8);
          U0DLL = (unsigned char)Baud;
          U0LCR = 0x03; /* DLAB = 0 */
          }
          void delay (unsigned int i)
          { /* Delay function */
          unsigned int n;
          while(i>1)
          {
          for(n=65535;n>1;n--);
          i--;
          }
          }
          //發(fā)送普通二進(jìn)制數(shù)據(jù)
          void Sent_Byte(uint8 *da,uint8 len)
          {
          uint8 i;
          for(i=0;i
          SendData[i]=da[i];
          SendLen=len;
          U0THR = SendData[0];
          SendCount=1;
          }
          // 發(fā)送字符
          void Sent_Str(unsigned char const *str)
          {
          uint8 i=0;
          while(1)
          {
          SendData[i]=*str;
          if( *str == /0 ) break;
          str++;
          i++;
          }
          SendLen=i;
          U0THR = SendData[0];
          SendCount=1;
          }
          //串口中斷
          void __irq uart_int()
          {
          uint8 i;
          if((U0IIR&0x0f)==0x02) //發(fā)送中斷
          {
          if(SendCount!=SendLen)
          {
          U0THR = SendData[SendCount];
          SendCount++;
          }
          }
          // 接收中斷
          else if(((U0IIR & 0x0F) == 0x0C)||((U0IIR & 0x0F) == 0x04))
          { // 如果中斷是由FIFO數(shù)據(jù)達(dá)到觸發(fā)點(diǎn)引起的
          for (i=0; i<14; i++)
          {
          buffer[i] = U0RBR;
          }
          Sent_Byte(buffer,8);
          }
          /*
          else if ((U0IIR & 0x0F) == 0x0C)
          { // 如果中斷是由FIFO超時(shí)引起的
          buffer[0] = U0RBR;
          } */
          VICVectAddr = 0; // 清中斷標(biāo)志,不是外部中斷不必復(fù)位EXTINT
          }
          int main(void)
          {
          Init_Uart0(UART_BAUD(115200));
          U0FCR = 0xc1; // 開啟UART FIFO模式 1個(gè)字符觸發(fā)0x01,4-0x41,8-0x81,14-0xc1
          U0IER = 0x03; // 使能RBR中斷,禁止THRE Rx線狀態(tài)中斷(DLAB=0時(shí))
          VICIntSelect = 0; // 選擇所有中斷為IRQ中斷
          VICVectCntl0 = 0x20 | 0x06; // slot0 對(duì)應(yīng)中斷源為UART
          VICVectAddr0 = (uint32)uart_int; // slot0 中斷服務(wù)程序
          VICIntEnable = 1 << 0x06; // 使能UART中斷源
          Sent_Str("http://blog.csdn.net/cy757//n") ;
          for(;;)
          {
          delay(200);
          }
          }


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