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

          新聞中心

          單片機(jī)鍵盤C程序

          作者: 時(shí)間:2012-12-11 來(lái)源:網(wǎng)絡(luò) 收藏

          void int1proc() interrupt IE1_VECTOR using 1
          {
          unsigned char i, key;
          code unsigned char PS2TAB[] = {//20鍵PS2小鍵盤鍵碼表
          0x70,//0
          0x69,//1
          0x72,//2
          0x7a,//3
          0x6b,//4
          0x73,//5
          0x74,//6
          0x6c,//7
          0x75,//8
          0x7d,//9
          0x05,//F1
          0x06,//F2
          0x04,//F3
          0x0c,//F4
          0x03,//F5
          0x0b,//F6
          0x5a,//Enter
          0x76,//Esc
          0x66,//Bksp
          0x71//KP.
          };
          if (PS2Buffers.PS2KeyCount == 0){//PS2測(cè)試
          if (!PS2CLOCK !PS2DATA){//低電平是
          if (PS2Buffers.PS2KeyExtFlage != 0xf0){
          PS2Buffers.PS2KeyTemp = 0;
          PS2Buffers.PS2KeyExtFlage = 0;
          PS2Buffers.PS2KeyPopError = 0;
          }
          PS2Buffers.PS2KeyCount ++;//脈沖計(jì)數(shù)
          }
          else PS2Buffers.PS2KeyPopError = 0xeb;//置鍵錯(cuò)誤號(hào)0xeb
          }
          else if (PS2Buffers.PS2KeyCount 9){//PS2數(shù)據(jù)位
          key = PS2Buffers.PS2KeyTemp;//取鍵盤緩沖區(qū)移位數(shù)據(jù)
          key >>= 1;
          if (PS2DATA) key = 0x80;
          PS2Buffers.PS2KeyTemp = key;
          PS2Buffers.PS2KeyCount++;//脈沖計(jì)數(shù)
          }
          else if (PS2Buffers.PS2KeyCount == 9){//PS2數(shù)據(jù)奇校驗(yàn)
          ACC = PS2Buffers.PS2KeyTemp;//取鍵盤緩沖區(qū)移位數(shù)據(jù)(C51取偶校驗(yàn)位)
          if (P != PS2DATA) PS2Buffers.PS2KeyCount ++;//脈沖計(jì)數(shù)
          else{
          PS2Buffers.PS2KeyPopError = 0xec;////置鍵奇校驗(yàn)位錯(cuò)誤號(hào)0xec
          PS2Buffers.PS2KeyCount = 0;//脈沖計(jì)數(shù)歸零
          }
          }
          else if (PS2Buffers.PS2KeyCount == 10){//停止位
          key = PS2Buffers.PS2KeyTemp;//取鍵盤緩沖區(qū)移位數(shù)據(jù)
          PS2Buffers.PS2KeyCount = 0;//脈沖計(jì)數(shù)歸零
          if (PS2DATA){//高電平是停止位
          if (key == 0xe0){//本次是擴(kuò)展鍵
          PS2Buffers.PS2KeyExtFlage = 0xe0;//置擴(kuò)展鍵標(biāo)志(小鍵盤只有回車鍵)
          }
          else if (key == 0xf0){//本次是鍵斷碼,鍵釋放
          PS2Buffers.PS2KeyExtFlage = 0xf0;//置鍵釋放標(biāo)志
          }
          else{//本次必為鍵值
          if ((key == 0xaa) (key == 0xfa)) PS2Buffers.PS2KeyPushCount = 0;//長(zhǎng)
          壓鍵計(jì)數(shù)器清零
          else{
          PS2CLOCK = 0;//阻止PS2鍵盤立即回送數(shù)據(jù)
          PS2Buffers.PS2KeyPopError = 0xaa;//出錯(cuò)碼
          for (i = 0; i 20; i++){
          if (key == (PS2TAB[i])){//搜索
          key = i + 1;
          if (PS2Buffers.PS2KeyExtFlage == 0xf0){
          key = 0x80;//鍵釋放
          PS2Buffers.PS2KeyPushCount = 0;//長(zhǎng)壓鍵計(jì)數(shù)器清零
          PS2Buffers.PS2KeyMessage = key;//存入當(dāng)前鍵值并執(zhí)行命令
          }
          else{
          if (key != PS2Buffers.PS2KeyVal){//換了一個(gè)鍵
          PS2Buffers.PS2KeyPushCount = 0;//長(zhǎng)壓鍵計(jì)數(shù)器清零
          PS2Buffers.PS2KeyMessage = key;//存入當(dāng)前鍵值并執(zhí)行命令
          }
          else{//未換鍵
          PS2Buffers.PS2KeyPushCount ++;//長(zhǎng)壓鍵計(jì)數(shù)器計(jì)數(shù)
          if (PS2Buffers.PS2KeyPushCount > DEFPS2PUSHCOUNT){//長(zhǎng)壓時(shí)間到
          PS2Buffers.PS2KeyMessage = key 0x40;//存入當(dāng)前鍵值并執(zhí)行命

          PS2Buffers.PS2KeyPushCount = 0;//長(zhǎng)壓鍵計(jì)數(shù)器清零
          }
          }
          }
          PS2Buffers.PS2KeyVal = key;//存入當(dāng)前鍵值值1~20或0x80+(1~20)
          PS2Buffers.PS2KeyTemp = 0;//鍵碼移位記錄器
          PS2Buffers.PS2KeyExtFlage = 0;//擴(kuò)展鍵標(biāo)志
          PS2Buffers.PS2KeyPopError = 0;//鍵釋放標(biāo)志或出錯(cuò)碼
          break;
          }
          }
          if (PS2Buffers.PS2KeyPopError) PS2Buffers.PS2KeyPushCount = 0;//長(zhǎng)壓鍵
          計(jì)數(shù)器清零
          PS2CLOCK = 1;//釋放PS2時(shí)鐘總線
          }
          }
          }
          else PS2Buffers.PS2KeyPopError = 0xed;//置停止位錯(cuò)誤號(hào)0xed
          }
          else PS2Buffers.PS2KeyCount = 0;//PS2鍵盤出錯(cuò)
          }


          上一頁(yè) 1 2 下一頁(yè)

          評(pí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); })();