因仑“3+1”工程特种兵精英论坛

标题: 一个高效的键盘扫描函数 [打印本页]

作者: 因为思念谁    时间: 2016-6-4 01:12
标题: 一个高效的键盘扫描函数
unsigned char keyscan()
{
        unsigned char com,com1,com2,i;
        keyport=0xf0;
        while(keyport!=0xf0)
        {   
                delayms(10);
                keyport=0xf0;
                while(keyport!=0xf0)
                {
                        keyport=0xf0;
                        if(keyport!=0xf0)
                        {
                                com1=keyport;
                                keyport=0x0f;
                                com2=keyport;
                        }
                        com=com1|com2;
                        if(com==0xee)i=12;
                        if(com==0xde)i=8;
                        if(com==0xbe)i=4;
                        if(com==0x7e)i=0;
                        if(com==0xed)i=13;
                        if(com==0xdd)i=9;
                        if(com==0xbd)i=5;
                        if(com==0x7d)i=1;
                        if(com==0xeb)i=14;
                        if(com==0xdb)i=10;
                        if(com==0xbb)i=6;
                        if(com==0x7b)i=2;
                        if(com==0xe7)i=15;
                        if(com==0xd7)i=11;
                        if(com==0xb7)i=7;
                        if(com==0x77)i=3;
                }
        }
        return(i);         
}





欢迎光临 因仑“3+1”工程特种兵精英论坛 (http://bbs.enlern.com/) Powered by Discuz! X3.4