本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
对4乘4键盘扫描,按下S1到S4数码管上分别显示0到3,,先当按下S1后,显示0,在按别的键没反应,当先按S2到S4之间时并换着按,显示正常,但当按下S1后又显示0,之后按什么都没变化,好像只要一按S1数码管显示0就像锁住了一样,求高人指点哈
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};
uchar code weixuan[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};
void delay(uchar);
void display(uchar);
uchar temp;
main()
{
uchar key=17;
display(key);
while(1)
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xfe)
{
temp=P3;
switch(temp)
{
case 0xee: key=1;break;
case 0xde: key=2;break;
case 0xbe: key=3;break;
case 0x7e: key=4;break;
}
display(key);
}
}
}
}
void display(uchar m)
{
uint i;
P0=table[m-1];
for(i=0;i<8;i++)
{
P1=weixuan[i];
delay(15);
}
}
void delay(uchar z)
{
uchar x,y;
for(x=0;x<20;x++)
for(y=0;y<z;y++);
} |