矩阵键盘显示动态数码管,麻烦能帮我看一下,怎么改能.....
时间:10-02
整理:3721RD
点击:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,10000000};
uchar a[];
//uchar wei[]={ 0xff,
//0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar num;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display()
{
while(1){
dula=1;
P0=a[0];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(500);
dula=1;
P0=a[1];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(500);
dula=1;
P0=a[2];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(500);
dula=1;
P0=a[3];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(500);
dula=1;
P0=a[4];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(500);
dula=1;
P0=a[5];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(500);
}
}
int key_num(uint key)
{
uchar temp;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
/* num2++;
if(num2==2)
wl1=num;
else if(num==3)
wl2=num;
else if(num==4)
wl3=num;
else if(num==5)
wl4=num;
else
num2=0;*/
switch(temp)
{
case 0xee:key=table[0];
break;
case 0xde:key=table[1];
break;
case 0xbe:key=table[2];
break;
case 0x7e:key=table[3];
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
return key;
}
}
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:key=table[4];
break;
case 0xdd:key=table[5];
break;
case 0xbd:key=table[6];
break;
case 0x7d:key=table[7];
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
return key;
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
/* num2++;
if(num2==2)
wl1=num;
else if(num==3)
wl2=num;
else if(num==4)
wl3=num;
else if(num==5)
wl4=num;
else
num2=0; */
switch(temp)
{
case 0xeb:key=table[8];
break;
case 0xdb:key=table[9];
break;
case 0xbb:key=table[10];
break;
case 0x7b:display();
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
return key;
}
}
}
void main()
{
int x,i;
//init();
P0=0xff;
dula=1;
dula=0;
P0=0xc0;
wela=1;
wela=0;
for(i=0;i<7;i++){
key_num(x);
a[i]= x;
} }
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,10000000};
uchar a[];
//uchar wei[]={ 0xff,
//0xfe,0xfd,0xfb,0xf7,0xef,0xdf};
uchar num;
void delay(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void display()
{
while(1){
dula=1;
P0=a[0];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(500);
dula=1;
P0=a[1];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(500);
dula=1;
P0=a[2];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(500);
dula=1;
P0=a[3];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(500);
dula=1;
P0=a[4];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(500);
dula=1;
P0=a[5];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(500);
}
}
int key_num(uint key)
{
uchar temp;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
/* num2++;
if(num2==2)
wl1=num;
else if(num==3)
wl2=num;
else if(num==4)
wl3=num;
else if(num==5)
wl4=num;
else
num2=0;*/
switch(temp)
{
case 0xee:key=table[0];
break;
case 0xde:key=table[1];
break;
case 0xbe:key=table[2];
break;
case 0x7e:key=table[3];
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
return key;
}
}
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:key=table[4];
break;
case 0xdd:key=table[5];
break;
case 0xbd:key=table[6];
break;
case 0x7d:key=table[7];
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
return key;
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
/* num2++;
if(num2==2)
wl1=num;
else if(num==3)
wl2=num;
else if(num==4)
wl3=num;
else if(num==5)
wl4=num;
else
num2=0; */
switch(temp)
{
case 0xeb:key=table[8];
break;
case 0xdb:key=table[9];
break;
case 0xbb:key=table[10];
break;
case 0x7b:display();
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
return key;
}
}
}
void main()
{
int x,i;
//init();
P0=0xff;
dula=1;
dula=0;
P0=0xc0;
wela=1;
wela=0;
for(i=0;i<7;i++){
key_num(x);
a[i]= x;
} }
看不明白,帮补了你
小编,现在是什么问题?
郭天祥那个开发板的代码吧