写了个矩阵键盘扫描程序功能是 矩阵键盘数码管显示键值 可是不论如何按按键显示的值都不变。。请指点下。

#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar num=6,temp=0,t;
/*共阳数码管数字显示 */
uchar Disp_Tab[] = { 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void delay(uint z);
uint keycheck();
void main()
{
P0=0xff;
delay(200);
while(1)
{
P0= Disp_Tab[keycheck()];
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uint keycheck()
{

P1=0xfd;
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
if(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xed:num=1;break;
case 0xdd:num=2;break;
case 0xbd:num=3;break;
case 0x7d:num=4;break;
}
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
P1=0xfb;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xeb:num=5;break;
case 0xdb:num=6;break;
case 0xbb:num=7;break;
case 0x7b:num=8;break;
}
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
P1=0xf7;
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P1;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P1;
switch(temp)
{
case 0xe7:num=9;break;
case 0xd7:num=10;break;
case 0xb7:num=11;break;
case 0x77:num=12;break;
}
}
while(temp!=0xf0)
{
temp=P1;
temp=temp&0xf0;
}
}
return num;
}
麻烦说明一下为什么
程序太长蔽蔽了,不太好看;另外也可能硬件有问题。
建仔并腔议念衫看看:
http://hi.baidu.com/%D7%F6%B6%F8%C2%DB%B5%C0/blog/item/ef086222268d4f4eac34de59.html