求助大家,谢谢
功能:按一个键显示一位数码管,第二次按显示两位数码管,类推6个
问题:按键有16个,为啥左边8个能用,右边八个不能用,按右边8个键会出现0或者好几个0,急问为啥。
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code table_dula[17]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
uchar code table_wela[7]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xff};
sbit dula=P2^6;
sbit wela=P2^7;
uchar num,temp,a,b,c,d,e,f;
void delay(char z); //延时z毫秒函数
void keyscan4x4(); //键盘扫描
void display(char shu,char wei); //数码管显示
void main() //主函数
{
P3=0xf0;
while(P3==0xf0);
delay(10);
keyscan4x4();
a=num;
P3=0xf0;
while(P3==0xf0)
display(a,0);
delay(10);
keyscan4x4();
b=num;
P3=0xf0;
while(P3==0xf0)
{display(a,0);
display(b,1);}
delay(10);
keyscan4x4();
c=num;
P3=0xf0;
while(P3==0xf0)
{display(a,0);
display(b,1);
display(c,2);}
delay(10);
keyscan4x4();
d=num;
P3=0xf0;
while(P3==0xf0)
{display(a,0);
display(b,1);
display(c,2);
display(d,3);}
delay(10);
keyscan4x4();
e=num;
P3=0xf0;
while(P3==0xf0)
{display(a,0);
display(b,1);
display(c,2);
display(d,3);
display(e,4);}
delay(10);
keyscan4x4();
f=num;
P3=0xf0;
while(P3==0xf0)
{display(a,0);
display(b,1);
display(c,2);
display(d,3);
display(e,4);
display(f,5);}
delay(10);
}
void delay(char z) //延时z毫秒函数
{
char x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void keyscan4x4() //键盘扫描
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=0;
break;
case 0xde:num=1;
break;
case 0xbe:num=2;
break;
case 0x7e:num=3;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num=4;
break;
case 0xdd:num=5;
break;
case 0xbd:num=6;
break;
case 0x7d:num=7;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num=8;
break;
case 0xdb:num=9;
break;
case 0xbb:num=10;
break;
case 0x7b:num=11;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:num=12;
break;
case 0xd7:num=13;
break;
case 0xb7:num=14;
break;
case 0x77:num=15;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
}
void display(char shu,char wei) //数码管显示
{
P0=table_dula[shu];
dula=1;
dula=0;
P0=table_wela[wei];
wela=1;
wela=0;
P0=0xff;
wela=1;
wela=0;
} |