📄 key.c
字号:
#include "reg52.h"
#include "absacc.h"
#define uchar unsigned char
#define word unsigned int
#define LedKey XBYTE[0x4000]
uchar code KeyVal[] =
{
'.', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '*', '<', '>', 13, 27
};
//uchar LedKeyData;
void Delay_Ms(uchar x) //
{
uchar i;
word j;
for (i = 0; i < x; i++)
{
for (j = 0; j < 333; j++)
;
}
}
uchar ReadKey()
{
uchar row, res, col;
for (row = 0; row < 4; row++)
{
LedKeyData &= 0xf0;
LedKeyData |= ~(1 << row);
LedKey = LedKeyData;
res = (~P1) & 0xf;
if (res)
{
break;
}
}
if (row == 4)
{
return 0;
}
col = (res >> 1);
if (col == 4)
{
col = 3;
}
Delay_Ms(80);
return KeyVal[(row << 2) + col];
}
//
uchar inputs(uchar *s, uchar x, uchar y, bit hide)
{
uchar i = 0;
uchar c;
ShowChar(x, y, ' ', 0);
Delay_Ms(500);
ShowChar(x, y, '_', 0);
ShowRow(y);
while (1)
{
c = 0;
while (!c)
{
c = ReadKey();
}
switch (c)
{
case '<':
if (i > 0)
{
i--;
ShowChar(x + i * 6, y, ' ', 0);
ShowRow(y);
}
break;
case '*':
LedKeyData ^= 0x10;
LedKey = LedKeyData;
break;
case '>':
break;
case 13:
s[i] = 0;
return (1);
case 27:
s[0] = 0;
return 0;
default:
if (i < 10)
{
if (hide)
{
ShowChar(x + i * 6, y, '*', 0);
}
else
{
ShowChar(x + i * 6, y, c, 0);
}
s[i] = c;
i++;
}
ShowRow(y);
break;
}
}
}
//
uchar selectN(uchar n)
{
uchar i, c, cn;
SelectMenuItem(1);
i = 0;
c = 0;
while (c != Cancle)
{
c = ReadKey();
if (c != 0)
{
cn = c - '0';
SelectMenuItem(i + 1);
if (c == '<')
{
i--;
}
else if (c == '>')
{
i++;
}
else if ((cn <= n) && (cn > 0))
{
i = cn - 1;
}
i = i % n;
SelectMenuItem(i + 1);
if (c == Enter)
{
return i;
}
else if (c == Cancle)
{
return 0;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -