#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code dula[]={0x3F, //"0"
0x06, //"1"
0x5B, //"2"
0x4F, //"3"
0x66, //"4"
0x6D, //"5"
0x7D, //"6"
0x07, //"7"
0x7F, //"8"
0x6F, //"9"
0x77, //"A"
0x7C, //"B"
0x39, //"C"
0x5E, //"D"
0x79, //"E"
0x71, };
void delay(uint z)
{
uint x,y;
for(x=100;x>0;x--)
for(y=z;y>0;y--);
}
keyboard()
{
uchar rcode,ccode;
P0=0xf0;
if((P0&0xf0)!=0xf0)
{ delay(4);
if((P0&0xf0)!=0xf0)
{
rcode=0xfe;
while((rcode&0x10)!=0)
{
P0=rcode;
if((P0&0xf0)!=0xf0)
{
ccode=(P0&0xf0)|0x0f;
do{;}while((P0&0xf0)!=0xf0);
delay(4);
while((P0&0xf0)!=0xf0);
return((~rcode)+(~ccode));
}
else rcode=(rcode<<1)|0x01;
}
}
}
return 0;
}
void disp(k)
{
P2=dula[k];
P1=0xff;
delay(1);
}
void display(k)
{
switch(k)
{
case 0x11:disp(0);break;
case 0x21:disp(1);break;
case 0x41:disp(2);break;
case 0x81:disp(3);break;
case 0x12:disp(4);break;
case 0x22:disp(5);break;
case 0x42:disp(6);break;
case 0x82:disp(7);break;
case 0x14:disp(8);break;
case 0x24:disp(9);break;
case 0x44:disp(10);break;
case 0x84:disp(11);break;
case 0x18:disp(12);break;
case 0x28:disp(13);break;
case 0x48:disp(14);break;
case 0x88:disp(15);break;
default:
break;
}
}
void main()
{
while(1)
{
uchar key;
key=keyboard();
display(key);
}
其中main()函数中,我若这样改
void main()
{
while(1)
{
display(keyboard());
}
}
这样就不行了,请大家看看这是为什么啊
} |