在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 單片機鍵盤掃描實驗

            單片機鍵盤掃描實驗

            作者: 時間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
            代碼如下:
            //實例7
            #include
            //led字模
            char led_mod[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
            0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71};
            //鍵值
            char key_buf[] = {0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,
            0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88};
            char getKey(void);
            void delay(unsigned int time){
            unsigned int j = 0;
            for(;time>0;time--)
            for(j=0;j<125;j++);
            }
            void main(void) {
            char key = 0;
            P2 = 0x00;
            //P0=0x11;
            while(1) {
            key = getKey();
            if (key != -1) {
            P2 = led_mod[key];
            }
            delay(10);
            }
            }
            //檢測按鍵
            //返回-1表示沒有檢測到按鍵按下
            char getKey(void) {
            char i = 0;
            unsigned char keycode=0xff;
            unsigned char scancode=0xff;
            scancode=0xf7;
            P0=0xf0;
            while(scancode!=0xff) {
            P0=scancode;
            //delay(10);
            keycode=P0;
            if((keycode&0xf0)!=0xf0)break;
            scancode=(keycode>>1)|0xf0;
            //if(keycode==0xff)scancode=scancode&0xf0;
            }
            keycode=~keycode;
            for (i = 0 ; i < 16 ; i++) {
            if (key_buf[i] == keycode) {
            return i;
            }
            }
            return-1;
            }



            關(guān)鍵詞: 單片機鍵盤掃

            評論


            技術(shù)專區(qū)

            關(guān)閉