#include <reg51.h>
#include <intrins.h>
unsigned char temp, key, keynum, current_num, end_num, offset, t, x;
void delay(int num)
{
int m, n;
for(m = 0; m < num; m++)
for(n = 0; n < 100; n++)
;
}
unsigned char table[]={
0x00, 0x66, 0x99, 0x81, 0x42, 0x24, 0x18, 0x00,//
0x08, 0x18, 0x38, 0x18, 0x18, 0x18, 0x3c, 0x00,//1
0x3c, 0x7e, 0x46, 0x0c, 0x18, 0x3e, 0x7e, 0x00,//2
0x3c, 0x66, 0x06, 0x3c, 0x06, 0x66, 0x3c, 0x00,//3
0x0c, 0x1c, 0x3c, 0x6c, 0x7e, 0x7e, 0x0c, 0x00,//4
0x7e, 0x7e, 0x70, 0x7c, 0x06, 0x7e, 0x7e, 0x00,//5
0x3c, 0x7e, 0x60, 0x7c, 0x66, 0x66, 0x3c, 0x00,//6
0x7e, 0x7e, 0x0c, 0x0c, 0x18, 0x18, 0x18, 0x00,//7
0x3c, 0x66, 0x66, 0x3c, 0x66, 0x66, 0x3c, 0x00,//8
0x3c, 0x66, 0x66, 0x3e, 0x06, 0x7e, 0x3c, 0x00};//9
unsigned char key_table[]={
0xee, 0xde, 0xbe, 0x7e,
0xed, 0xdd, 0xbd, 0x7d,
0xeb, 0xdb, 0xbb, 0x7b,
0xe7, 0xd7, 0xb7, 0x77};
void display_t0() interrupt 1
{
int i, j;
TH0 = -4000/256;
TL0 = -4000%256;
P1 = 0xf0;
if (P1 != 0xf0)
{
// delay(100);
// if(P1!= 0xf0)
// {
temp = P1;
P1 = 0x0f;
key = temp|P1;
for(i = 0; i < 16; i++)
{
if(key == key_table[i])
{
keynum = i;
break;
}
}
// }
}
P2 = _crol_(P2 , 1);
j = current_num * 8 + t + offset;
P0 = ~table[j];
if (current_num < keynum)
{
if( ++t == 8)
{
t = 0;
if (++x == 4)
{
x = 0;
if (++offset == 8)
{
offset = 0;
current_num++;
end_num = current_num;
}
}
}
}
else if (current_num > keynum )
{
if( ++t == 8)
{
t = 0;
if (++x == 4)
{
x = 0;
if (--offset == -8)
{
offset = 0;
current_num--;
end_num = current_num;
}
}
}
}
else
{
if( ++t == 8)
t = 0;
}
}
void main()
{
TMOD = 0x01;
TH0 = -4000/256;
TL0 = -4000%256;
TR0 = 1;
ET0 = 1;
EA = 1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
PX0=1;
P2 = 0x80;
keynum = 1;
current_num = 1;
t = 0;
x = 0;
led = 1;
BEEP = 1;
while(1);
}
https://www.zhihu.com/question/413339019