首页 > 代码库 > 矩阵键盘
矩阵键盘
/* 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();
}
}
矩阵键盘