『壹』 4*4矩阵键盘控制6位数码管电路图及程序
^#include<reg51.h>
#defineuintunsignedint
#defineucharunsignedchar
sbitla=P2^6;
sbitwela=P2^7;
sbitkey1=P3^4;
ucharcodetable[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0};
ucharnum,temp,num1;
voiddelay(uintz)
{
uintx,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
ucharkeyscan();
voiddisplay(ucharaa);
voidmain()
{
num=17;
la=1;
P0=0;
la=0;
wela=1;
P0=0xc0;
wela=0;
while(1)
{
display(keyscan());
}
}
voiddisplay(ucharaa)
{
la=1;
P0=table[aa-1];
la=0;
}
ucharkeyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case0xee:num=1;
break;
case0xde:num=2;
break;
case0xbe:num=3;
break;
case0x7e:num=4;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case0xed:num=5;
break;
case0xdd:num=6;
break;
case0xbd:num=7;
break;
case0x7d:num=8;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case0xeb:num=9;
break;
case0xdb:num=10;
break;
case0xbb:num=11;
break;
case0x7b:num=12;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case0xe7:num=13;
break;
case0xd7:num=14;
break;
case0xb7:num=15;
break;
case0x77:num=16;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
returnnum;
}
『贰』 键盘输入电路有哪些
独立键盘直接是一个脚接地一个脚接单片机IO口,4*4矩阵键盘如下图:
电脑键盘一般时通过门电路控制8个引脚可以控制128个键,一般笔记本代工厂测试键盘就是那样扫描的。。