复位后数码管亮一会(时间极短),全灭。
什么原因?????
程序在此
#include<reg52.h>
char key,num,temp;
char table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07
};
char cbit[]={
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
};
char buffer[]={
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40
};
/*******************************************delay*****************************/
void delay(int x)
{
int a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
/*void display(num)
{
P0=table[num];
P1=0xfe;
} */
/**********************************************keyscan*********************/
void keyscan()
{
int i,j;
i=8;
while(i--)
{
P1=cbit[i];
P0=buffer[i];
}
P2=0xff;
temp=P2;
if(temp!=0xff)
delay(10);
temp=P2;
if(temp!=0xff)
{
j++;
/* if(temp==0xfe)key=0;
else if(temp==0xfd)key=1;
else if(temp==0xfb)key=2;
else if(temp==0xf7)key=3;
else if(temp==0xef)key=4;
else if(temp==0xdf)key=5;
else if(temp==0xbf)key=6;
else if(temp==0x7f)key=7; */
switch(temp!=0xff)
{
case 0xfe:
key=0;
break;
case 0xfd:
key=1;
break;
case 0xfb:
key=2;
break;
case 0xf7:
key=3;
break;
case 0xef:
key=4;
break;
case 0xdf:
key=5;
break;
case 0xbf:
key=6;
break;
case 0x7f:
key=7;
break;
}
buffer[j]=table[key];
if(temp!=0xff);
delay(4);
}
}
void main()
{ while(1)
{
keyscan();
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
#include<reg52.h>
char key,num,temp;
char table[]=
{
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07
};
char cbit[]=
{
0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f
};
char buffer[]=
{
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40
};
void delay(int x)
{
int a,b;
for(a=x;a>0;a--)
for(b=110;b>0;b--);
}
void keyscan()
{
int i=0;
int j=0;
for(i=0;i<8;i++)
{
P1=cbit[i];
P0=buffer[i];
delay(2);}
P2=0xff;
temp=P2;
if(temp!=0xff)
{
delay(5);
temp=P2;
if(temp!=0xff)
{
j++;
switch(temp)
{
case 0xfe:
key=0;
break;
case 0xfd:
key=1;
break;
case 0xfb:
key=2;
break;
case 0xf7:
key=3;
break;
case 0xef:
key=4;
break;
case 0xdf:
key=5;
break;
case 0xbf:
key=6;
break;
case 0x7f:
key=7;
break;
}
buffer[j]=table[key];
//while(temp!=0xff)
// buffer[j]=table[key];
}
}
}
void main()
{ while(1)
{
keyscan();
}
}
一周热门 更多>