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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機設(shè)計的四個按鍵發(fā)音

          單片機設(shè)計的四個按鍵發(fā)音

          作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
          電路圖:

          程序?qū)崿F(xiàn)功能:
          實現(xiàn)四個按鍵發(fā)出不同的音調(diào),代碼如下:
          #include
          #define uchar unsigned char
          #define uint unsigned int
          sbit BEEP = P3^7; //將P3.7接口賦予BEEP(接喇叭)
          sbit K1 = P1^4; //將P1.4接口賦予K1
          sbit K2 = P1^5; //將P1.5接口賦予K2
          sbit K3 = P1^6; //將P1.6接口賦予k3
          sbit K4 = P1^7; //將p1.7接口賦予K4
          //延時
          void DelayMS(uint x)
          {
          uchar t;
          while(x--)
          {
          for(t=0;t<120;t++);
          }
          }
          void Play(uchar t)
          {
          uchar i;
          for(i=0;i<100;i++)
          {
          BEEP = ~BEEP; //半個周期取反一次
          DelayMS(t); //延時
          }
          BEEP = 0;
          }
          void main()
          {
          P1 = 0xff;
          while(1)
          {
          if(K1==0) Play(1);
          if(K2==0) Play(2);
          if(K3==0) Play(3);
          if(K4==0) Play(4);
          }
          }



          關(guān)鍵詞: 按鍵發(fā)音單片

          評論


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