矩阵键盘

Posted -AIR

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了矩阵键盘相关的知识,希望对你有一定的参考价值。

/* Main.c file generated by New Project wizard
*
* Created: ?? 5? 18 2017
* Processor: AT89C51
* Compiler: Keil for 8051
*/

#include <reg52.h>
#include <stdio.h>
#define uchar unsigned char
void delay()
{

uchar j = 1000;
while(j--);
}
void liushuideng(void)
{
uchar duan[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar kkk = 0;
uchar i = 0;
P2 = 0xfe;
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
delay();
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
i = P2;
switch(i)
{
case 0xee:kkk = 0;break;
case 0xde:kkk = 4;break;
case 0xbe:kkk = 8;break;
case 0x7e:kkk = 12;break;
}
P1 = duan[kkk];
while(i!=0xf0)
{
i = P2;
i = i&0xf0;
}
}

}
P2 = 0xfd;
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
delay();
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
i = P2;
switch(i)
{
case 0xed:kkk = 1;break;
case 0xdd:kkk = 5;break;
case 0xbd:kkk = 9;break;
case 0x7d:kkk = 13;break;
}
P1 = duan[kkk];
while(i!=0xf0)
{
i = P2;
i = i&0xf0;
}
}

}
P2 = 0xfb;
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
delay();
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
i = P2;
switch(i)
{
case 0xeb:kkk = 2;break;
case 0xdb:kkk = 6;break;
case 0xbb:kkk = 10;break;
case 0x7b:kkk = 14;break;
}
P1 = duan[kkk];
while(i!=0xf0)
{
i = P2;
i = i&0xf0;
}
}

}
P2 = 0xf7;
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
delay();
i = P2;
i = i&0xf0;
if(i!=0xf0)
{
i = P2;
switch(i)
{
case 0xe7:kkk = 3;break;
case 0xd7:kkk = 7;break;
case 0xb7:kkk = 11;break;
case 0x77:kkk = 15;break;
}
P1 = duan[kkk];
while(i!=0xf0)
{
i = P2;
i = i&0xf0;
}
}

}
}
void main(void)
{
while(1)
{
liushuideng();
}

}

以上是关于矩阵键盘的主要内容,如果未能解决你的问题,请参考以下文章

3.4 51单片机-矩阵键盘

按键消抖,矩阵键盘原理和矩阵键盘的仿真模型

按键消抖,矩阵键盘原理和矩阵键盘的仿真模型

进阶项目(11) 矩阵键盘程序设计讲解

51单片机C语言,电子密码的验证输入程序,矩阵键盘用作输入,密码正确时,向串口送1,否则送0

Proteus仿真矩阵键盘中断扫描