|
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^6;
sbit wela=P2^7;
sbit been=P2^4;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uint num1,num,count;
void delay(uint x)
{
uint i,j;
for(i=x;i>0;i--)
for(j=110;j>0;j--);
}
uchar jianpan1()
{
uint temp;
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num1=1;
break;
case 0xde:num1=2;
break;
case 0xbe:num1=3;
break;
case 0x7e:num1=4;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num1=5;
break;
case 0xdd:num1=6;
break;
case 0xbd:num1=7;
break;
case 0x7d:num1=8;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num1=9;
break;
case 0xdb:num1=10;
break;
case 0xbb:num1=11;
break;
case 0x7b:num1=12;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:num1=13;
break;
case 0xd7:num1=14;
break;
case 0xb7:num1=15;
break;
case 0x77:num1=16;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
return num1;
}
void display()
{
uint shi,ge;
shi=num/10;
ge=num%10;
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(10);
dula=1;
P0=table[ge];
dula=0;
P0=0xff; ;
wela=1;
P0=0xfd;
wela=0;
delay(10);
}
void main(void)
{
uint count=0,num=0;
EA=1;
EX0=1;
IT0=1;
while(1)
{
jianpan1();
display();
}
}
void INT0_num() interrupt 0
{
num=num*10+num1;
if(num>99)
{num=0;
been=0;}
}
|
|