复位后数码管亮一会(时间极短),全灭。
什么原因?????
程序在此
#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();
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
谢谢指出错误,不好意思,移位显示程序(计算机式或计算器式)我编了三四天了,一直没思路,头都大了,程序乱了,重新整理了一下,switch用法确实错了,已改正。j我是想实现移位功能,但没用。移位程序在网上只搜到了一个汇编的
#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;
if(i<8)
{
i++;
P1=cbit;
P0=buffer;
P2=0xff;
temp=P2;
if(temp!=0xff)
{
delay(10);
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];
if(temp!=0xff);
delay(4);
}
}
}
}
void main()
{ while(1)
{
keyscan();
}
}
下载后只在第二位数码管显示键值
继续求移位程序
一周热门 更多>