发布网友 发布时间:2022-04-23 21:38
共3个回答
热心网友 时间:2023-10-10 15:27
这个实现是很容易的,定义两个键,一个为加,一个为减,数码管因为只有一个,所以可以用静态显示。程序和仿真图如下:
#include<reg51.h>
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
sbit keyup=P3^0;
sbit keydn=P3^1;
main()
{
uchar i;
i=0;
while(1)
{
P1=table[i];
if(keyup==0)
{
i++;
while(keyup==0);
}
if(keydn==0)
{
if(i>0)i--;
while(keydn==0);
}
i%=10;
}
}
热心网友 时间:2023-10-10 15:28
#include<reg51.h>
#define Duan P0
#define Wei P1
unsigned char CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
//unsigned char PLACE[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned int num,shi,ge;
sbit K3=P3^0; //K3中断加一
sbit K4=P3^1; //K4中断减一
void delay(unsigned int z);
//void display(unsigned int z);
void main()
{
Duan=0x3f;
Wei=0x7f;
while(1)
{
if(K3==0)
{
delay(10);
if(K3==0)
{
num++;
Wei=0x7f;
Duan=CODE[num];
delay(5000);
}
}
if(K4==0)
{
delay(10);
if(K4==0)
{
if(num--)
{
Wei=0x7f;
Duan=CODE[num];
delay(5000);
}
else {
num=0;
Wei=0x7f;
Duan=CODE[num];
}
}
}
}
}
void delay(unsigned int z)
{
unsigned int y;
for(;z>0;z--)
for(y=10;y>0;y--);
}
/*void display(unsigned int z)
{
shi=z/10;
ge=z%10;
while(shi==0)
{
Wei=0x7f;
Duan=CODE[ge];
}
while(shi!=0)
{
Wei=0x7F;
Duan=CODE[ge];
delay(1);
Duan=0;
Wei=0xbf;
Duan=CODE[shi];
delay(1);
Duan=0x00;
}
} */
/*void int0() interrupt 0
{
if(K3==0)
Key=1;
}
void int1() interrupt 2
{
if(K4==0)
Key=1;
} */
热心网友 时间:2023-10-10 15:28
没有人回答?