『壹』 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個鍵,一般筆記本代工廠測試鍵盤就是那樣掃描的。。