一个关于矩阵案件中switch的问题
'''#include<reg52.h>
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
#define GPIO_KEY P1
#define GPIO_DIG P0
int keyvalue;
int code smgduan[] = {0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d,
0x7d, 0x07, 0x7f, 0x6f};
void delay(int a)
{
while(a--)
{
;
}
}
void keydown()
{ int n = 0;
GPIO_KEY = 0x0f;
if(GPIO_KEY != 0x0f)
{
delay(1000);
if(GPIO_KEY != 0x0f)
{
GPIO_KEY = 0x0f;
switch(GPIO_KEY)
{
case 0x07: //s1列
{
keyvalue = 0;
break;
}
case 0x0b: //s2列
{
keyvalue = 1;
break;
}
case 0x0d://s3列
{
keyvalue = 2;
break;
}
case 0x0e: //s4列
{
keyvalue = 3;
break;
}
}
GPIO_KEY = 0xf0;
switch(GPIO_KEY)
{
case 0x70:
{
keyvalue = keyvalue;
break;
}
case 0xb0:
{
keyvalue = keyvalue + 4;
break;
}
case 0xd0:
{
keyvalue = keyvalue + 8;
break;
}
case 0xe0:
{
keyvalue = keyvalue + 12;
break;
}
while((n < 50) && (GPIO_KEY != 0XF0))
{
delay(1000);
n++;
}
}
}
}
}
void main()
{
LSA = 0;
LSB = 0;
LSC = 0;
while(1)
{
keydown();
GPIO_DIG = smgduan;
}
}
'''
这段代码中,先判断了GPIO_KEY的值,然后进行消抖,后来又判断了一次。
确认按键按下后,对GPIO_KEY进行了重新赋值?
赋值后switch获取的值不应该是对GPIO_KEY重新赋值后的值而不是按键传回的值?
怎么还能正确进行判断呢?
上面的代码可以正常运行,跪求大神解答!
感激不尽!
页:
[1]