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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 模擬串口的實(shí)現(xiàn)單片機(jī)IO口

          模擬串口的實(shí)現(xiàn)單片機(jī)IO口

          作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏
          用EBOX向我們的電力線調(diào)試模塊發(fā)數(shù)據(jù),但是要有一個控制接口,但是EBOX沒有提供,所有只好用MCU來做伺服器。

          一般的單片機(jī)都只有一個串口,所以必須模擬一個出來。

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

          /*

          sbit TXD1= P1^4;//define p14 as the analog transmit port

          sbit RXD1= P1^2;//define p12 as the analog recieve port

          */

          #include "REG52.H"

          #define uint unsigned int

          #define uchar unsigned char

          #include

          void WaitTF0(void);

          void TIMEINI(void)//counter initial

          {

          TMOD=0x02;

          TH0=0xA0;、//9600 BPS

          TL0=TH0;

          TR0=1;

          TF0=0;

          }

          void WByte(uchar input)//send function

          {

          uchar i=8;

          TR0=1;

          TXD1=0;//begin bit

          WaitTF0();

          //send the Byte

          while(i--)

          {

          TXD1=input&0x01;//send Byte from low bit to high bit

          WaitTF0();

          input=input>>1;//right shift

          }

          TXD1=1;//stop bit

          WaitTF0();

          TR0=0;//stop the counter

          }

          uchar RByte()//the recieve function

          {

          uchar Output=0;

          uchar i=8;

          while(RXD1);

          i=i;

          i=i;

          i=i;

          i=i;

          i=i;

          i=i;

          i=i;

          TR0=1;//計數(shù)器開始工作

          WaitTF0();

          while(i--)//接收8位數(shù)據(jù)位

          {

          Output>>=1;

          if(RXD1)Output=Output|0x80;//recieve from the high bit to low bit

          WaitTF0();

          }

          TR0=0;

          returnOutput;

          }

          void WaitTF0(void)//check the counter

          {

          while(!TF0);

          TF0=0;

          }



          關(guān)鍵詞: 模擬串口單片機(jī)IO

          評論


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