📄 矩阵式键盘的识别(一).c
字号:
/*********************************************************************************
4x4 矩阵键盘的识别
**********************************************************************************/
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
uchar j;
uchar t;
uint n;
const uchar tab[]={0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,/*0~7*/
0X7F,0X6F,0X77,0X7C,0X39,0X5E,0X79,0x71};/*8~F*/
/****************************延时函数*********************************************/
void delay(uint n)
{ uint i;
for(i=0;i<n;i++);
}
/********************************主函数******************************************/
void main(void)
{
uchar a,b,c;
P2=0x00;
while(1)
{
P3=0x0f;
a=P3;
delay(10);
P3=0xf0;
b=P3;
delay(10);
c=a+b;
if(c==0xee)
P2=tab[0]; // 0
if(c==0xde)
P2=tab[1]; // 1
if(c==0xbe)
P2=tab[2]; // 2
if(c==0x7e)
P2=tab[3]; // 3
if(c==0xed)
P2=tab[4]; // 4
if(c==0xdd)
P2=tab[5]; // 5
if(c==0xbd)
P2=tab[6]; // 6
if(c==0x7d)
P2=tab[7]; // 7
if(c==0xeb)
P2=tab[8]; // 8
if(c==0xdb)
P2=tab[9]; // 9
if(c==0xbb)
P2=tab[10]; // a
if(c==0x7b)
P2=tab[11]; // b
if(c==0xe7)
P2=tab[12]; // c
if(c==0xd7)
P2=tab[13]; // d
if(c==0xb7)
P2=tab[14]; // e
if(c==0x77)
P2=tab[15]; // f
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -