#include<reg52.h>
#include<intrins.h>
#define uint unsigned int
#define uchar unsigned char
uchar code deng[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
void delay1s(void) //误差 0us
{
unsigned char a,b,c;
for(c=167;c>0;c--)
for(b=171;b>0;b--)
for(a=16;a>0;a--);
_nop_(); //if Keil,require use intrins.h
}
void delay10ms(void) //误差 0us
{
unsigned char a,b,c;
for(c=1;c>0;c--)
for(b=38;b>0;b--)
for(a=130;a>0;a--);
}
sbit keyk=P1;
sbit LSA=P2^2;
sbit LSB=P2^3;
sbit LSC=P2^4;
int keyz;
void keydown()
{
int a;
{
keyk=0x0f;
if(keyk!=0x0f)
{
delay10ms();
if(keyk!=0x0f)
{
keyk=0x0f;
switch(keyk)
{
case(0x07):keyz=0; break;
case(0x0b): keyz=1 ;break;
case(0x0d):keyz=2;break;
case(0x0e):keyz=3 ;break;
}
keyk=0xf0;
switch(keyk)
{
case(0x70): keyz=keyz; break;
case(0xb0):keyz=keyz+4;break;
case(0xd0):keyz=keyz+8;break;
case(0xe0):keyz=keyz+12;break;
}
}
}
while((a<50)&&(keyk!=0x0f))
{delay10ms();
a++;
}
}
}
void main()
{
LSA=0;
LSB=0;
LSC=0;
keydown();
P0=deng[keyz];
delay1s();
}
|