📄 key_t1.c
字号:
#include<at89x51.h>
unsigned int KEY_ID = 0;
void delay_ms(unsigned int count)
{
int i,j;
for(i= 0; i<=count; i++)
{
for(j=0;j<=120;j++)
{;}
}
}
void Key_Init(void)
{
TMOD = 0x10;
TH1 = 0x20;
TL1 = 0x40;
ET1 = 1;
EA = 1;
TR1 = 1;
}
void KEY_GET(void) interrupt 3 using 2
{
ET1 = 0;
P2_1 = 0;
delay_ms(10);
if(P2_4 == 0) KEY_ID = 5;
if(P2_5 == 0) KEY_ID = 6;
if(P2_6 == 0) KEY_ID = 7;
if(P2_7 == 0) KEY_ID = 8;
P2_1 = 1;
P2_0 = 0;
delay_ms(10);
if(P2_4 == 0) KEY_ID = 1;
if(P2_5 == 0) KEY_ID = 2;
if(P2_6 == 0) KEY_ID = 3;
if(P2_7 == 0) KEY_ID = 4;
P2_0 = 1;
P2_2 = 0;
delay_ms(10);
if(P2_4 == 0) KEY_ID = 9;
if(P2_5 == 0) KEY_ID = 10;
if(P2_6 == 0) KEY_ID = 11;
if(P2_7 == 0) KEY_ID = 12;
P2_2 = 1;
P2_3 = 0;
delay_ms(10);
if(P2_4 == 0) KEY_ID = 13;
if(P2_5 == 0) KEY_ID = 14;
if(P2_6 == 0) KEY_ID = 15;
if(P2_7 == 0) KEY_ID = 16;
P2_3 = 1;
P0 = (KEY_ID / 10) * 16 + KEY_ID %10;
delay_ms(50);
TH1 = 0x20;
TL1 = 0x40;
ET1 = 1;
}
main()
{
Key_Init();
while(1)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -