#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
sbit ge=P0^0;
sbit shi=P0^1;
sbit key0 = P1^5;
sbit key1 = P1^6;
sbit key2 = P1^7;
uint num = 0;
bit key0_enter=0;
bit key1_enter=0;
bit key2_enter=0;
void init(void)
{
ge = 0;
shi = 0;
EA = 1;
IT0 = 1;
}
void delay(uchar ms)
{
uchar i ,j;
for (i=0;i<ms;i++)
for(j=101;j>0;j--);
}
void key_loop()
{
if ((key0==0)&&(key0_enter==0))
{
key0_enter=1;
EX0=1;
}
if(key0==1)
{
key0_enter=0;
}
if ((key1==0)&&(key1_enter==0))
{
key1_enter=1;
EX0=0;
}
if(key1==1)
{
key1_enter=0;
}
if ((key2==0)&&(key2_enter==0))
{
key2_enter=1;
num = 0;
}
if(key2==1)
{
key2_enter=0;
}
}
void display()
{
static uchar nms=0;
static bit wei=0;
uchar ges=0;
uchar shis=0;
nms++;
if(nms>5)
{
nms=0;
if(wei)
{
shis=(num/10)%10;
ge=1;
shi=1;
P2=table[shis];
shi=0;
wei=0;
}
else
{
ges=num%10;
ge=1;
shi=1;
P2=table[ges];
ge=0;
wei=1;
}
}
}
void main()
{
init();
for(;;)
{
key_loop();
display();
delay(1);
}
}
void waibu() interrupt 0
{
num++;
}
|