这是我做的矩阵按键显示,但是在
仿真时无论怎么按都不显示啊
#include <reg51.h>
#define unchar unsigned char
unchar duan[]={0xff,0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
char key;
void delayms(int n)
{
char j;
while(n--)
{
for(j=0;j<=50;j++);
}
}
void keym()
{
unchar temp,i,k;
P2=0xf0;
temp=P2;
while(temp!=0xf0)
{
delayms(10);
if(temp!=0xf0)
{
P2=0xfe;
for(i=0;i<4;i++)
{
temp=P2&0xf0;
switch(temp)
{
case 0xe0: key=k+1;break;
case 0xd0: key=k+2;break;
case 0xb0: key=k+3;break;
case 0x70: key=k+4;break;
}
k=k+4;
P2=(P2<<1)+1;
}
P2=0xf0;
temp=P2;
while(temp!=0xf0);
}
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;ET0=1;
TR0=1;
while(1)
{
P0=duan[key];
}
}
void
timer() interrupt 1
{
char t;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
if(t==2)
{
t=0;
keym();
}
}
-
一周热门 更多>