新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 一種非傳統的矩陣鍵盤掃描函數

        一種非傳統的矩陣鍵盤掃描函數

        作者: 時間:2016-11-30 來源:網絡 收藏
        //子函數delay_1ms(1)大家自己寫吧

        #define scan_key_port P3

        本文引用地址:http://www.104case.com/article/201611/323831.htm

        uchar key_scan()
        {
        uchar sccode,recode;
        uchar key_value;
        scan_key_port=0xf0; /* 發全 "0" 的行掃描碼,列線輸入 */
        if((scan_key_port&0xf0)!=0xf0) /* 若有鍵按下 */
        {
        delay_1ms(1); /*延時去抖動*/
        if((scan_key_port&0xf0)!=0xf0) /* 若有鍵按下 */
        {
        sccode=0xfe; /*逐行掃描初值*/
        while((sccode&0x10)!=0)
        {
        scan_key_port=sccode; /* 輸出行掃描碼 */
        if((scan_key_port&0xf0)!=0xf0) /* 本行有鍵按下 */
        {
        recode=(scan_key_port&0xf0)|0x0f;
        key_value=(~sccode)+(~recode);/* 返回特征碼 */
        }
        else sccode=(sccode<<1)|0x01; /* 行掃描左移一位 */
        }
        }
        }
        else { //若無鍵按下
        scan_key_port = 0xff;
        return (0);
        }
        scan_key_port = 0xff; /*釋放按鍵掃描端口*/
        switch(key_value){ /*顯示adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=eda4a0003316455c&k=%B0%B4%BC%FC&k0=%B0%B4%BC%FC&kdi0=0&luki=1&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=5c451633a0a4ed&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2075%2Ehtml&urlid=0" id="0_nwl" mpid="0" target="_blank">按鍵對應的絲印*/
        case 0x11:
        return(0);

        case 0x12:
        return(1);

        case 0x14:
        return(2);

        case 0x21:
        return(3);

        case 0x22:
        return(4);

        case 0x24:
        return(5);

        case 0x41:
        return(6);

        case 0x42:
        return(7);

        case 0x44:
        return(8);

        case 0x81:
        return(9);

        case 0x82:
        return(A);

        case 0x84:
        return(B);

        case 0x18:
        return(C);

        case 0x28:
        return(D);

        case 0x48:
        return(E);

        case 0x88:
        return(F);
        }
        }



        關鍵詞: 矩陣鍵盤掃描函

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 和田市| 台南县| 伊春市| 滦南县| 辽阳县| 怀集县| 临朐县| 通江县| 卓尼县| 柳林县| 汝州市| 平远县| 长沙市| 南城县| 阳信县| 建瓯市| 城口县| 霍邱县| 南安市| 乌审旗| 怀安县| 高台县| 日喀则市| 永善县| 寿宁县| 融水| 神农架林区| 尤溪县| 连山| 北海市| 临漳县| 连平县| 女性| 清流县| 衡阳县| 镇雄县| 达日县| 涿鹿县| 乐亭县| 屯留县| 南皮县|