新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 一個改進型的4*4矩陣鍵盤掃描

        一個改進型的4*4矩陣鍵盤掃描

        作者: 時間:2016-11-30 來源:網絡 收藏
        #include
        #define uchar unsigned char
        #define uint unsigned int
        uchar temp,num,bai,shi,ge;
        uchar key[]={0x3f,0x5f,0x6f};
        uchar code table[]=
        {
        0x3f , 0x06 , 0x5b ,
        0x4f , 0x66 , 0x6d ,
        0x7d , 0x07 , 0x7f ,
        0x6f };
        void keyscan();
        void delay(uchar z);
        void dsp(uchar bai,uchar shi,uchar ge);
        void main()
        {
        while(1)
        {
        keyscan();
        dsp(bai,shi,ge);
        }
        }
        void delay(uchar z)
        {
        uchar x,y;
        for(x=100;x--;x>0)
        for(y=z;y--;y>0);
        }
        void dsp(uchar bai,uchar shi,uchar ge)
        {

        bai=num/100;
        shi=num%100/10;
        ge=num%10;

        P0=0xfb;
        P2=table[bai];
        delay(1);
        P0=0xfd;
        P2=table[shi];
        delay(1);
        P0=0xfe;
        P2=table[ge];
        delay(1);
        }
        void keyscan()
        { uchar i;
        for(i=0;i<3;i++)
        {
        P1=key[i];
        temp=P1;
        temp&=0x0f;
        if(temp!=0x0f) //如果有鍵按下
        {
        delay(5);
        temp=P1;
        temp&=0x0f;
        if(temp!=0x0f)//確實有鍵按下
        {
        switch(temp)
        {
        case 0x07:adclass=0&app_id=0&c=news&cf=1001&ch=0&di=128&fv=17&is_app=0&jk=f1c2511670cd2325&k=switch&k0=switch&kdi0=0&luki=1&n=10&p=baidu&q=98059059_cpr&rb=0&rs=1&seller_id=1&sid=2523cd701651c2f1&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1831118&u=http%3A%2F%2Fwww%2E51hei%2Ecom%2Fmcu%2F2002%2Ehtml&urlid=0" id="1_nwl" mpid="1" target="_blank">switch(i)
        {
        case 0:num=1;break;
        case 1:num=5;break;
        case 2:num=9;break;
        };

        break;

        case 0x0b:switch(i)
        {
        case 0:num=2;break;
        case 1:num=6;break;
        case 2:num=10;break;
        };
        break;

        case 0x0d:switch(i)
        {
        case 0:num=3;break;
        case 1:num=7;break;
        case 2:num=11;break;
        };
        break;

        case 0x0e:switch(i)
        {
        case 0:num=4;break;
        case 1:num=8;break;
        case 2:num=12;break;
        };;
        break;

        while(temp!=0xf0) //松開手后就跳出循環,否則等待松手
        {
        temp=P1;
        temp=temp&0xf0;
        dsp(bai,shi,ge);
        }
        }

        }
        }
        }
        }


        評論


        技術專區

        關閉
        主站蜘蛛池模板: 平和县| 修水县| 增城市| 密山市| 贺兰县| 娄底市| 蕲春县| 栾川县| 青田县| 乐陵市| 榕江县| 来安县| 若尔盖县| 喜德县| 白银市| 虹口区| 松溪县| 龙海市| 安达市| 宁波市| 霍城县| 苍溪县| 宜昌市| 微山县| 灵丘县| 仁怀市| 确山县| 祁连县| 龙游县| 儋州市| 裕民县| 敖汉旗| 永胜县| 汾西县| 如皋市| 铁力市| 拜泉县| 泰顺县| 永康市| 逊克县| 根河市|