这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » 4x4 4x4键盘问题,有四个键值始终不对,请大家帮帮忙

共2条 1/1 1 跳转至

4x4 4x4键盘问题,有四个键值始终不对,请大家帮帮忙

院士
2006-09-17 18:14:16     打赏
4x4 4x4键盘问题,有四个键值始终不对,请大家帮帮忙



关键词: 键盘     问题     四个     键值     始终     不对     大家     帮帮忙    

院士
2006-12-22 22:43:00     打赏
2楼
问 用89c2051做了一个键盘,P1.0-P1.3接上拉电阻,程序如下:
uchar getkey()
{
    uchar recode,key;               
    uchar sccode;
    P1=0xF0;
    if((P1&0xF0)!=0xF0)                   
         {                 
            delay(200);                 //延时1MS
        if((P1&0xF0)!=0xF0)
        {
            sccode=0xFE;
        while((sccode&0x10)!=0)
        {                                 P1=sccode;
                 if((P1&0xF0)!=0xF0)
                                          {
                                     recode=(P1&0xF0)|0x0F;
         keydd=0;                         key=(~sccode)+(~recode);
         key=changekey(key);
         return (key);                        }
    else sccode=(sccode<<1)|0x01;
    }                
    }
    }
    if((P1&0xF0)==0xF0)
        {
        delay(200);
        if((P1&0xF0)==0xF0)
            {
             keydd=1;
             return 0;
             }
        }  
}

uchar changekey(uchar keystate)
{
    switch(keystate)
        {
               
            case 0x41: keystate=0x47;break;
            case 0x42: keystate=0x49;break;
            case 0x44: keystate=0x45;break;
            case 0x48: keystate=0x42;break;
            case 0x22: keystate=0x48;break;
            case 0x24: keystate=0x46;break;
            case 0x28: keystate=0x43;break;
            case 0x11: keystate=0x51;break;
            case 0x12: keystate=0x16;break;
            case 0x14: keystate=0x11;break;
            case 0x18: keystate=0x41;break;

            *case 0x01: keystate=0x50;break;
            *case 0x02: keystate=0x15;break;
            *case 0x04: keystate=0x12;break;
            *case 0x08: keystate=0x44;break;

            default: break;
           }
    DOG=!DOG;
    return (keystate);
}

其中打*的四句不对,始终得不到我想要的值(如:keystate=0x50等),其他的都没有问题。一直没有找到原因!请大家帮帮忙看下,谢谢 1: 有原理图吗 2: 当然不会有0x01,0x02,0x04,0x08的数据出现为1的位为行列相交的点,键按下时行列必然都有至少1点为1,即高4位和低4位必然都有为1的位!

当然不会有0x01,0x02,0x04,0x08的数据出现:
            *case 0x01: keystate=0x50;break;
            *case 0x02: keystate=0x15;break;
            *case 0x04: keystate=0x12;break;
            *case 0x08: keystate=0x44;break;

应该是0x81,0x82,0x84,0x88才对
            case 0x81: keystate=0x50;break;
            case 0x82: keystate=0x15;break;
            case 0x84: keystate=0x12;break;
            case 0x88: keystate=0x44;break;



3: 搞定了,感谢xwj!确实没有注意到这个问题!谢谢指点 4: 同意,同意 5: 对,是这个样子!!!对,是这个样子!!!

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]