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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機矩陣鍵盤的控制

          單片機矩陣鍵盤的控制

          作者: 時間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
          本來感覺矩陣鍵盤很簡單的,沒有想到編了一個程序,編了一個下午,哎,難怪有人說,如果技術(shù)和科學有你理想那么容易,那它就不是科學了。在參考http://www.51hei.com/mcuteach/226.html后終于把矩陣鍵盤里的16個按鍵控制數(shù)碼管顯示0至16的效果實現(xiàn)了出來,呵呵,功夫不負有心人,雖然編了好久,好累,好困。但還是一個字,值!下面看下程序吧,如果各位高手看到了我程序有所不足的,麻煩指點。


          下面是我的程序:#include
          unsigned char temp;
          char x;
          unsigned char number[]={
          0x3f,
          0x06,
          0x5b,
          0x4f,
          0x66,
          0x6d,
          0x7d,
          0x07,
          0x7f,
          0x6f,
          0x77,
          0x7c,
          0x39,
          0x5e,
          0x79,
          0x71
          };//¶¨ÒåÊý×é0ÖÁ15
          void delay()
          {
          int i,j;
          for(i=5;i<0;i--)
          for(j=120;j<0;j--);
          }//ÑÓʱ³ÌÐò
          void main()
          {
          P1 = 0x00;//³ÌÐò¿ªÊ¼Ê±ÊýÂë¹Ü²»ÏÔʾ
          while(1)
          {
          P3 = 0x7f;//ʹ°´¼üS1ÖÁS4ÏÔʾ0ÖÁ3
          temp = P3;
          temp = temp & 0x0f;
          while(temp != 0x0f)
          {
          delay();
          temp = P3;
          temp = temp & 0x0f;

          while(temp != 0x0f)
          {
          temp = P3;
          switch(temp)
          {
          case 0x7e:x=0;
          break;
          case 0x7d:x=1;
          break;
          case 0x7b:x=2;
          break;
          case 0x77:x=3;
          break;
          }
          while(temp!=0x0f)//Ìø³ö
          {
          temp=P3;
          temp=temp&0x0f;
          }
          P1 = number[x];

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

          }

          }


          //cond

          P3 = 0xbf;//ʹ°´¼üS5ÖÁS8ÏÔʾ4ÖÁ7
          temp = P3;
          temp = temp & 0x0f;
          while(temp != 0x0f)
          {
          delay();
          temp = P3;
          temp = temp & 0x0f;

          while(temp != 0x0f)
          {
          temp = P3;
          switch(temp)
          {
          case 0xbe:x=4;
          break;
          case 0xbd:x=5;
          break;
          case 0xbb:x=6;
          break;
          case 0xb7:x=7;
          break;
          }
          while(temp!=0x0f)//Ìø³ö
          {
          temp=P3;
          temp=temp&0x0f;
          }

          P1 = number[x];
          }
          }

          //thirth

          P3 = 0xdf;//ʹS9ÖÁS12ÏÔʾ8ÖÁb
          temp = P3;
          temp = temp & 0x0f;
          while(temp != 0x0f)
          {
          delay();
          temp = P3;
          temp = temp & 0x0f;

          while(temp != 0x0f)
          {
          temp = P3;
          adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=a65eeeafe947a97a&k=switch&k0=switch&kdi0=0&luki=3&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=7aa947e9afee5ea6&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2001%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">switch(temp)
          {
          case 0xde:x=8;
          break;
          case 0xdd:x=9;
          break;
          case 0xdb:x=10;
          break;
          case 0xd7:x=11;
          break;
          }
          while(temp!=0x0f)//Ìø³ö
          {
          temp=P3;
          temp=temp&0x0f;
          }

          P1 = number[x];

          }

          }

          //four
          P3 = 0xef;//ʹS13ÖÁS16ÏÔʾCÖÁF
          temp = P3;
          temp = temp & 0x0f;
          while(temp != 0x0f)
          {
          delay();
          temp = P3;
          temp = temp & 0x0f;

          while(temp != 0x0f)
          {
          temp = P3;
          switch(temp)
          {
          case 0xee:x=12;
          break;
          case 0xed:x=13;
          break;
          case 0xeb:x=14;
          break;
          case 0xe7:x=15;
          break;
          }
          while(temp!= 0x0f)
          {
          temp = P3;
          temp = temp&0x0f;
          }
          while(temp!=0x0f)//Ìø³ö
          {
          temp=P3;
          temp=temp&0x0f;
          }
          P1 = number[x];

          }

          }
          }
          }
          感覺好長,如果厲害點的話,應(yīng)該可以做編得更短的,有時間只有再把它完善了。



          關(guān)鍵詞: 單片機矩陣鍵

          評論


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