在四位共阳极数码管上显示键盘输入
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
bit flag;
unsigned char key_scannum[] = {0xef,0xdf,0xbf,0x7f};
unsigned char table[]= {0xee,0xed,0xeb,0xe7,0xde,0xdd,0xdb,0xd7,0xbe,0xbd,0xbb,0xb7,0x7e,0x7d,0x7b,0x77};//?ü?ì°′?ü??
unsigned char led[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; //P0?ú????±à??
void delay(uint x) //?óê±3ìDò
{
uint y;
for(x;x>0;x--)
for(y=0;y<100;y++);
}
unsigned char keyscan(void)//?ü?ìé¨?è?μoˉêy
{
unsigned char i,j;
P1=0x0f;//?ì2éê?·?óD?ü°′??
if(P1!=0x0f)//±íê?óD°′?ü°′??
{
delay(1); //�?
if(P1!=0x0f)
for(i = 0;i < 4;i++)
{
P1 = key_scannum;
if(P1 != key_scannum)//′?DDóD?ü°′??
for(j = 0;j < 16;j++)
{
if(P1 == table[j])
{
flag=1;
return(j);
}
}
}
}
while((P1 & 0x0f)<0x0f);
return(0);
}
void display(uint num)
{
uint ge,shi,bai,qian;
qian=num/1000;
P0=led[qian];
P2=0xf7;
delay(1);
P2=0xff;
bai=num%1000/100;
P0=led[bai];
P2=0xfb;
delay(1);
P2=0xff;
shi=num%100/10;
P0=led[shi] & 0x7f;
P2=0xfd;
delay(1);
P2=0xff;
ge=num%10;
P0=led[ge];
P2=0xfe;
delay(1);
P2=0xff;
}
void main(void)
{
uint que,num=0;
while(1)
{
que=keyscan();
if(flag==1)
{
num=num*10+que;
flag=~flag;
}
display(num);
}
}
是哪里有问题?各位大神帮忙看一下
不说问题现象,直接让人看代码,这也够让人累的
不好意思,第一次发,不知道怎样说好
估计是是想实现4*4按键扫描并实现按第一个数码管全部是0,第二个全部2…………
那你是显示有问题,按键有问题,还是只是无法显示按下的按键
谢谢你们,已解决,谢谢!