|
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit d0=P3^0;
sbit d1=P3^1;
sbit d2=P3^2;
sbit d3=P3^3;
sbit d4=P3^4;
sbit d5=P3^5;
sbit d6=P3^6;
sbit d7=P3^7;
sbit le0=P0^1;
sbit le1=P0^2;
uchar code a[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void delay() //延时10ms程序
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
void delay3() //误差 0us
{
unsigned char a,b;
for(b=111;b>0;b--)
for(a=12;a>0;a--);
}
int scankey(){
int i,jg;
uchar cc;
while(1){
cc=0xfe;
for(i=0;i<4;i++){
P1=cc;
if(d4==0){
delay();
if(d4==0){
jg=i*4+1;
while(!d4);
delay();
while(!d4);
return(jg);
}
}
if(d5==0){
delay();
if(d5==0){
jg=i*4+2;
while(!d5);
delay();
while(!d5);
return(jg);
}
}
if(d6==0){
delay();
if(d6==0){
jg=i*4+3;
while(!d6);
delay();
while(!d6);
return(jg);
}
}
if(d7==0){
delay();
if(d7==0){
jg=i*4+3;
while(!d7);
delay();
while(!d7);
return(jg);
}
}
cc=_crol_(cc,1);
}
}
}
void display(int hh){
int sw,gw;
sw=hh/10;
gw=hh%10;
le1=1;
le0=0;
P1=a[gw];
delay3();
P1=0x00;
le0=1;
le1=0;
P1=a[sw];
delay3();
P1=0x00;
}
main(){
int ss=0;
while(1){
ss=scankey();
display(ss);
}
}
|
|