📄 keyscan.c
字号:
#include<reg51.h>
#include<absacc.h>
#define uchar unsigned char
#define uint unsigned int
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
//unsigned char code dispbit1[]={0,1};
//unsigned char code dispbit2[]={1,0};
unsigned char dispbit[]={0xfe,0xfd};
unsigned char dispbuf[]={0,0};
unsigned char cnt;
sbit S1=P2^0;
sbit S2=P2^1;
void delays(void);
unsigned char kbscan(void);
void main(void)
{uchar key;
TMOD=0x01;
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
{key=kbscan();
delays();
dispbuf[0]=key/16;
dispbuf[1]=key%16;
}
}
void delays(void)
{
uchar i;
for(i=300;i>0;i--);
}
//
uchar kbscan(void)
{
uchar sccode,recode;
P3=0xf0;
if((P3&0xf0)!=0xf0)
{
delays();
if((P3&0xf0)!=0xf0)
{
sccode=0xfe;
while((sccode&0x10)!=0)
{
P3=sccode;
if((P3&0xf0)!=0xf0)
{
recode=(P3&0xf0)|0x0f;
return((~sccode)+(~recode));
}
else sccode=(sccode<<1)|0x01;
}
}
}
return(0);
}
void Timer0() interrupt 1 using 1
{
TH0=(65536-4000)/256;
TL0=(65536-4000)%256;
// S1=dispbit1[cnt];
// S2=dispbit2[cnt];
P2=dispbit[cnt];
P0=table[dispbuf[cnt]];
cnt++;
if(cnt==2)cnt=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -