菜鸟求帮忙 感激不尽~~
时间:10-02
整理:3721RD
点击:
自己编了一个程序,具体功能如下: 按下独立键盘第一个键,每按一次数码管加1,知道加到255然后归零。为什么数码管的百位和十位显示闪一下就灭了,而个位正常。 程序如下:
#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,0x76,0x79,0x38,0x3f,0x00};
sbit key=P3^0;
sbit dula=P2^0;
sbit wela=P2^1;
uchar num,bai,shi,ge;
void display(uchar bai,uchar shi,uchar ge);
void delay(uint z);
void main()
{
num=0;
P3=0xff;
while(1)
{
bai=num/100;
shi=num%100/10;
ge=num%10;
if(key==0)
{ delay(10);
if(key==0)
{ while(!key);
num++;
if(num==255)
num=0;
display(bai,shi,ge);
}
}
}
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>1;x--)
for(y=110;y>0;y--);
}
#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,0x76,0x79,0x38,0x3f,0x00};
sbit key=P3^0;
sbit dula=P2^0;
sbit wela=P2^1;
uchar num,bai,shi,ge;
void display(uchar bai,uchar shi,uchar ge);
void delay(uint z);
void main()
{
num=0;
P3=0xff;
while(1)
{
bai=num/100;
shi=num%100/10;
ge=num%10;
if(key==0)
{ delay(10);
if(key==0)
{ while(!key);
num++;
if(num==255)
num=0;
display(bai,shi,ge);
}
}
}
}
void display(uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(5);
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(5);
dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(5);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>1;x--)
for(y=110;y>0;y--);
}
你这是动态显示,要把display函数放在while(1)中,不要放在if语句里,否则只有在按键的一瞬间有显示
恩啊 是的是的 非常感谢~