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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > MSP430單片機 矩陣鍵盤與數(shù)碼管實驗

          MSP430單片機 矩陣鍵盤與數(shù)碼管實驗

          作者: 時間:2016-11-22 來源:網(wǎng)絡 收藏
          #include "msp430x44x.h"

          #define ROW P2OUT //矩陣鍵盤的行宏定義
          #define COL P2IN //矩陣鍵盤的列宏定義
          #define DPYOUT P3OUT //數(shù)碼管輸出口宏定義
          unsigned char keyval; //鍵值

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

          //共“陽”極數(shù)碼管的碼表
          unsigned char LED7CA[] ={~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,
          ~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71,0xff};


          unsigned char keyscan()
          {
          int i=0;
          unsigned char key=0;
          ROW = 0x8f; //先置三行輸出低電平
          if((COL & 0x0f)!= 0x0f) //是否有按鍵
          {
          do i++;
          while(i<3000); //消抖動延時
          ROW = 0xbf; //掃描第一行
          if((COL & 0x0f)== 0x0f)
          { ROW = 0xdf; //掃描第二行
          if((COL & 0x0f)== 0x0f)
          { ROW = 0xef; //掃描第三行
          if((COL & 0x0f)== 0x0f)
          key = 15;
          else key = ~((ROW & 0XF0)|(COL & 0X0F));
          }
          else key = ~((ROW & 0XF0)|(COL & 0X0F));
          }
          else key = ~((ROW & 0XF0)|(COL & 0X0F));
          if(key != 15)
          switch(key) //獲取有效地鍵值
          { case 0x48: key=0; break;
          case 0x44: key=1; break;
          case 0x42: key=2; break;
          case 0x41: key=3; break;
          case 0x28: key=4; break;
          case 0x24: key=5; break;
          case 0x22: key=6; break;
          case 0x21: key=7; break;
          case 0x18: key=8; break;
          case 0x14: key=9; break;
          case 0x12: key=10;break;
          case 0x11: key=11;break;
          default: key=15;
          }
          }
          else key = 15;
          keyval=key;
          return key;
          }


          void main( void )
          {
          // Stop watchdog timer to prevent time out reset
          WDTCTL = WDTPW + WDTHOLD;
          P3DIR |= 0xff;
          P3OUT = 0xff; //共陽極數(shù)碼管輸出口初始化
          P2DIR |= BIT4 +BIT5+BIT6; //先配置矩陣鍵盤的行(輸出)
          //P2.6 第一行,P2.5 第二行,P2.4 第三行
          //P2.3 第一列,P2.2 第二列,P2.1 第三列,P2.0 第四列
          keyval=16;
          while(1)
          { keyscan();
          if(keyval != 15 && keyval<17)
          DPYOUT = LED7CA[keyval];//數(shù)碼管顯示鍵值
          }
          }



          評論


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