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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AVR單片機串口接收與發(fā)送程序

          AVR單片機串口接收與發(fā)送程序

          作者: 時間:2016-11-13 來源:網(wǎng)絡(luò) 收藏
          #include "iom16v.h" //頭文件,不同的編譯器不一樣

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

          /*串口初始化函數(shù)*/ //使用同一個串口進行發(fā)送與接收,mega162具有雙串口功能
          void Uart_Init(void)

          {
          UCSRA = 0x02;/*倍速*/
          UCSRB = 0x18;/*允許接收和發(fā)送*/
          UCSRC = 0x06;/*8位數(shù)據(jù)*/
          UBRRH = 0x00;
          UBRRL = 12;/*9600*/
          }

          /*數(shù)據(jù)發(fā)送,查詢方式*/
          void Uart_Transmit(unsigned char i)

          {

          while (!(UCSRA & (1<UDR = i;/* 發(fā)送數(shù)據(jù)*/
          }

          /*數(shù)據(jù)接收,查詢方式*/
          unsigned char Uart_Receive( void ) //注意函數(shù)類型

          {

          while (!(UCSRA & (1<return UDR;/* 獲取并返回數(shù)據(jù)*/
          }


          /*主函數(shù)*/
          void main(void)

          {

          unsigned char temp;

          DDRA = 0x00;/*方向輸入*/
          PORTA = 0xFF;/*打開上拉*/
          DDRB = 0xFF;/*方向輸出*/
          PORTB = 0xFF;/*電平設(shè)置*/
          DDRC = 0x00;
          PORTC = 0xFF;
          DDRD = 0x02;
          PORTD = 0xFF;
          Uart_Init();

          while (1)

          {
          temp = Uart_Receive();/*等待接收數(shù)據(jù)*/
          PORTB = ~temp;/*顯示低電平有效*/
          Uart_Transmit(temp);/*發(fā)送收到的數(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); })();