avr 矩阵键盘程序看不懂
unsignedcharkey_press(){delay_nms(10);unsignedchari;KEY_DDR=0XFF;KEY_PORT=0XF0;KEY_DD...
unsigned char key_press()
{
delay_nms(10);
unsigned char i;
KEY_DDR = 0XFF;
KEY_PORT = 0XF0;
KEY_DDR = 0X0F;
i = KEY_PIN;
if(i==0XF0)
{
KEY_DDR = 0XFF;
return 0;
}
else
{
KEY_DDR = 0XFF;
return 1;
}
}
unsigned char key_scan()
{
unsigned char key,i=0X7F,j;
delay_nms(10);
if(key_press())
{
do
{
i=(i<<1|i>>7);
KEY_PORT = i;
KEY_DDR = 0X0F;
key = KEY_PIN;
j = key&0XF0;
}while(j==0XF0);
while(key_press());
switch(key)
{
case 0xEE:
key = 1;
break;
case 0xDE:
key = 2;
break;
case 0xBE:
key = 3;
break;
case 0x7E:
key = 4;
break;
case 0xED:
key = 5;
break;
case 0xDD:
key = 6;
break;
case 0xBD:
key = 7;
break;
case 0x7D:
key = 8;
break;
case 0xEB:
key = 9;
break;
case 0xDB:
key = 10;
break;
case 0xBB:
key = 11;
break;
case 0x7B:
key = 12;
break;
case 0xE7:
key = 13;
break;
case 0xD7:
key = 14;
break;
case 0xB7:
key = 15;
break;
case 0x77:
key = 16;
break;
default:
key=0;
}
}
else
{
key=16;
}
return key;
}
看不懂,有人能注释一下吗
就是怎么知道按得是哪个键的? 展开
{
delay_nms(10);
unsigned char i;
KEY_DDR = 0XFF;
KEY_PORT = 0XF0;
KEY_DDR = 0X0F;
i = KEY_PIN;
if(i==0XF0)
{
KEY_DDR = 0XFF;
return 0;
}
else
{
KEY_DDR = 0XFF;
return 1;
}
}
unsigned char key_scan()
{
unsigned char key,i=0X7F,j;
delay_nms(10);
if(key_press())
{
do
{
i=(i<<1|i>>7);
KEY_PORT = i;
KEY_DDR = 0X0F;
key = KEY_PIN;
j = key&0XF0;
}while(j==0XF0);
while(key_press());
switch(key)
{
case 0xEE:
key = 1;
break;
case 0xDE:
key = 2;
break;
case 0xBE:
key = 3;
break;
case 0x7E:
key = 4;
break;
case 0xED:
key = 5;
break;
case 0xDD:
key = 6;
break;
case 0xBD:
key = 7;
break;
case 0x7D:
key = 8;
break;
case 0xEB:
key = 9;
break;
case 0xDB:
key = 10;
break;
case 0xBB:
key = 11;
break;
case 0x7B:
key = 12;
break;
case 0xE7:
key = 13;
break;
case 0xD7:
key = 14;
break;
case 0xB7:
key = 15;
break;
case 0x77:
key = 16;
break;
default:
key=0;
}
}
else
{
key=16;
}
return key;
}
看不懂,有人能注释一下吗
就是怎么知道按得是哪个键的? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询