#include <STC15.H>
sbit STCP=P1^0;
sbit SHCP=P1^1;
sbit DS=P1^2;
unsigned char code DisplayHex[]={0xC0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
unsigned char disp[4];
unsigned char key,keytemp,keyres,keycount,keyrelease;
void Delay(unsigned int i )
{
unsigned char j;
while (i)
{
i--;
for(j=255;j>0;j--)
{
}
}
}
void Send(unsigned char a)
{
unsigned char i,j;
j=0x80;
for(i=0;i<8;i++)
{
if(a&j) DS=1;
else DS=0;
SHCP=0;
SHCP=1;
j>>=1;
}
}
void Dispshuma()
{
unsigned char i;
for(i=0;i<4;i++)
{
Send(DisplayHex[disp[i]]);
}
STCP=0;
STCP=1;
}
unsigned char keyscan()
{
unsigned char keyvalue,p;
P1=P1|0xF0;
keyvalue=P1&0xF0;
if(keyvalue!=0xf0)
{
if(keyvalue==0x70)p=0;
else if(keyvalue==0xb0)p=1;
else if(keyvalue==0xd0)p=2;
else if(keyvalue==0xe0)p=3;
else p=25;
}
else
{
p=25;
keyrelease=1;
}
}
void main()
{
P0M0=0XFF;P0M1=0;
P1M0=0XFF;P1M1=0;
TMOD=0X01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
Dispshuma();
P1=P1|0xF0;
}
}
void T0_time() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
key=keyscan();
if(keyrelease)
{
if(key!=25)
{
keycount++;
if(keytemp==0)keytemp=key;
else
{
if(keytemp=key)
{
if(keycount>40)keycount=40;
}
}
if(keycount>2)
{
if(keyres==0)
{
keyres=1;
keyrelease=0;
/***************/
disp[0]=key;
disp[1]=16;
disp[2]=16;
disp[3]=16;
/***************/
}
}
}
else
{
keycount=0;
keytemp=0;
keyres=0;
}
}
}
|