帮帮忙 矩阵键盘看看哪里出问题了 按键没反应
unsigned char key[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71}; //0~f的十六个数 共阳极
unsigned int keyvalue;
void keyscan(); //扫描函数
void delay(); //延时
void main()
{
while(1)
{
keyscan();
P3=~key[keyvalue];
}
}
void keyscan()
{
unsigned int a;
P1=0x0f;
if(P1!=0x0f)
{
delay();
if(P1!=0x0f)
{
a=P1; //读取p1口的值给a
switch(a)
{
case 0x0e: keyvalue=0;break;
case 0x0d: keyvalue=1;break;
case 0x0b: keyvalue=2;break;
case 0x07: keyvalue=3;break;
}
}
}
P1=0xf0;
if(P1!=0xf0)
{
delay();
if(P1!=0xf0)
{
a=P1;
switch(a)
{
case 0xe0: keyvalue=keyvalue;break;
case 0xd0: keyvalue=keyvalue+4;break;
case 0xb0: keyvalue=keyvalue+8;break;
case 0x70: keyvalue=keyvalue+12;break;
}
}
}
}
void delay()
{
unsigned int c;
for(c=1;c>0;c--)
TMOD=0x10;
TH1=0xb1;
TL1=0xe0;
while(!TF1);
TF1=0;
}
void keyscan()
{
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:
key=1;
wei++;
break;
case 0xde:
key=2;
wei++;
break;
case 0xbe:
key=3;
wei++;
break;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:
key=4;
wei++;
break;
case 0xdd:
key=5;
wei++;
break;
case 0xbd:
key=6;
wei++;
break;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:
key=7;
wei++;
break;
case 0xdb:
key=8;
wei++;
break;
case 0xbb:
key=9;
wei++;
break;
case 0x7b:
retry=1;
break;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(10);
if(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xd7:
key=0;
wei++;
break;
case 0xb7:
close=1;
break;
case 0x77:
wanbi=1;
break;
}
}
}
}
}
给你参考参考…………
delay 中
for(c=1;c>0;c--)
TMOD=0x10;
这句没看出是起什么作用的
学习中。。