2021-1-8 09:37
#include<reg52.h>
#include <absacc.h>
#define a8255_PA XBYTE[0xd900] /*PA 口地址 */
#define a8255_PB XBYTE[0xdb00] /*PB 口地址 */
#define a8255_PC XBYTE[0xD5FF] /*PC 口地址 */
#define a8255_CON XBYTE[0xde00] /*控制字地址 */
#define uchar unsigned char
#define uint unsigned long int
uint a,n,i,j,x=1,b=1,tt=0;
uint table[]={0x80,0x9B,0x42,0x0A,0x19,0x0C,0x04,0x9A,0x00,0x08};
void delay1(void)
{
unsigned char i;
for(i=250; i>0;i--);
}
uchar inkey()
{
uchar i,j=0x10,k;
uchar keytab[20]={0x18, /*0*/
0x28, /*1*/
0x48, /*2*/
0x88, /*3*/
0x14, /*4*/
0x24, /*5*/
0x44, /*6*/
0x84, /*7*/
0x12, /*8*/
0x22, /*9*/
0x42, /*10*/
0x82, /*11*/
0x11, /*12*/
0x21, /*13*/
0x41, /*14*/
0x81 /*15*/
};
a8255_CON=0x81;
a8255_PC=0x00;
for(i=0;i<4;i++)
{
a8255_PC=j;
a8255_PA=0xff;
a8255_PB=0xff;
k=a8255_PC;
k=k&0x0f;
if(k!=0)
{ delay1();
k=a8255_PC;
k=k&0x0f;
if(k!=0)
break;
}
j=j<<1;
delay1();
}
k=k+j;
for(i=0;i<16;i++)
{
if(keytab==k) break;
}
return i;
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=11;y>0;y--);
}
void display(uint a)
{
uint wan,qian,bai,shi,ge;
wan=a/10000;
qian=a%10000/1000;
bai=a%1000/100;
shi=a%100/10;
ge=a%10;
a8255_PA=0xfd;
a8255_PB=table[wan];
delay(1);
a8255_PA=0xfb;
a8255_PB=table[qian];
delay(1);
a8255_PA=0xf7;
a8255_PB=table[bai];
delay(1);
a8255_PA=0xef;
a8255_PB=table[shi];
delay(1);
a8255_PA=0xdf;
a8255_PB=table[ge];
delay(1);
}
void display1()
{
a8255_PA=0xdf;
a8255_PB=0x80;
delay(1);
a8255_PA=0xef;
a8255_PB=0x7f;
delay(1);
}
void init()
{ a8255_PA=0xff;
a8255_CON=0x81;
tt=0;
TMOD=0x01;
TH0=0x3c;
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
EX0=1;
IT1=1;
}
void main()
{
uchar n=0,k=0xdf;
init();
a=0;
while(1)
{
n=inkey();
switch(n)
{
case 0: a=99999; break;
case 1: a=9999; break;
case 2: a=999; break;
case 3: a=99; break;
case 4: a=9; break;
}
if(n==5)
{
do
{
display1();
n=inkey();
if((n!=5)&&(n!=16))
{
x=0;
}
}while(x);
x=1;
}
display(a);
}
}
void timer0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
tt++;
if(tt==20)
{
tt=0;
if(a)
{
a--;
}
}
}