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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AT89S52兩單片機之間的通信 C程序

          AT89S52兩單片機之間的通信 C程序

          作者: 時間:2016-11-23 來源:網(wǎng)絡(luò) 收藏
          #include

          #define uint unsigned int
          #define uchar unsigned char
          sbit key1 = P1^0;//按鍵位定義
          sbit key2 = P1^1;
          sbit key3 = P1^2;
          sbit key4 = P1^3;

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

          void send(uchar key_num)//通過串口發(fā)送按鍵值子函數(shù)
          {
          SBUF = key_num;
          while(!TI);
          TI = 0;
          }

          void delay(uint z)//延時_ms子函數(shù)
          {
          uint x,y;
          for(x = 0;xfor(y = 0;y<125;y++);
          }

          uint key_scan()//鍵盤掃描子函數(shù),帶返回值num
          {
          uint num;
          if(key1 == 0)//鍵1按下則數(shù)碼管將顯示1
          {
          delay(5);
          if(key1 ==0)
          {num = 1;}
          }


          if(key2 == 0)//鍵2按下則數(shù)碼管將顯示2
          {
          delay(5);
          if(key2 ==0)
          {num = 2;}
          }


          if(key3 == 0)//鍵3按下則數(shù)碼管將顯示3
          {
          delay(5);
          if(key3 ==0)
          {num = 3;}
          }


          if(key4 == 0)//鍵4按下則數(shù)碼管將顯示4
          {
          delay(5);
          if(key4 ==0)
          {num = 4;}
          }

          return num;//返回值為num
          }

          void scon_init()//初始化串口子函數(shù)
          {
          TMOD = 0x20;
          TH1 = 0xfd;
          TL1 = 0xfd;
          TR1 = 1;
          SM0 = 0;
          SM1 = 1;
          EA = 1;
          ES = 1;
          }
          void main()
          {
          scon_init();//初始化串口
          while(1)
          {
          send(key_scan());//不停掃描并發(fā)送按鍵值
          }
          }


          #include
          #define uint unsigned int
          #define uchar unsigned char

          uchar code tab[]={//數(shù)碼管字形
          0x40,0x79,0x24,0x30,
          0x19,0x12,0x02,0x78,
          0x00,0x10,0x08,0x03,
          0x46,0x21,0x06,0x0e};

          void scon_init()//串口寄存器初始化
          {
          TMOD = 0x20;
          TH1 = 0xfd;
          TL1 = 0xfd;
          TR1 = 1;
          REN = 1;//注意REN的位置
          SM0 = 0;
          SM1 = 1;
          EA = 1;
          ES = 1;
          }

          void main()
          {
          scon_init();//調(diào)用串口初始化子函數(shù)
          while(1);//等待串口中斷
          }

          void ser() interrupt 4//串口中斷子函數(shù)
          {
          uchar a;
          RI = 0;
          a = SBUF;//將接收到在SBUF中的key值送給變量a
          P2 = tab[a];//在串口中斷中顯示字形
          }



          關(guān)鍵詞: AT89S52單片機通

          評論


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