📄 martix_keyboard_samea.c
字号:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
sbit choose_du=P2^6;
sbit choose_we=P2^7;
/*uchar code table[]={ //0-9的共阴极代码
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};*/
uchar code table[]={ //0-9的共阴极代码
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e
};
uchar temp,num;
void delay(uchar);
void display(uchar);
void main()
{
while(1)
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(22);
if(temp!=0xf0)
{
switch(temp)
{
case 0xe0:num=0;
break;
case 0xd0:num=1;
break;
case 0xb0:num=2;
break;
case 0x70:num=3;
break;
}
}
while(temp!=0xf0)//键盘松开去抖动
{
temp=P3;
temp=temp&0xf0;
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(22);
if(temp!=0xf0)
{
switch(temp)
{
case 0xe0:num=4;
break;
case 0xd0:num=5;
break;
case 0xb0:num=6;
break;
case 0x70:num=7;
break;
}
}
while(temp!=0xf0)//键盘松开去抖动
{
temp=P3;
temp=temp&0xf0;
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(22);
if(temp!=0xf0)
{
switch(temp)
{
case 0xe0:num=8;
break;
case 0xd0:num=9;
break;
case 0xb0:num=10;
break;
case 0x70:num=11;
break;
}
}
while(temp!=0xf0)//键盘松开去抖动
{
temp=P3;
temp=temp&0xf0;
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(22);
if(temp!=0xf0)
{
switch(temp)
{
case 0xe0:num=12;
break;
case 0xd0:num=13;
break;
case 0xb0:num=14;
break;
case 0x70:num=15;
break;
}
}
while(temp!=0xf0)//键盘松开去抖动
{
temp=P3;
temp=temp&0xf0;
}
}
display(num);
}
}
void delay(uchar x)
{
uchar i,j;
for(i=x;i>0;i--)
for(j=205;j>0;j--);
}
void display(uchar y)
{
P0=0xff;
choose_we=1;
choose_we=0;
P0=table[y];
choose_du=1;
choose_du=0;
P0=0xc0;
choose_we=1;
choose_we=0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -