《4×4矩阵式键盘识别关键技术.docx》由会员分享,可在线阅读,更多相关《4×4矩阵式键盘识别关键技术.docx(17页珍藏版)》请在第壹文秘上搜索。
1、14.4X4矩阵式键盘辨认技术1 .实验任务如图4.14.2所示,用AT89S51并行口Pl接4X4矩阵键盘,以P1.O-P1.3作输入线,以P1.4-P1.7作输出线;在数码管上显示每个按键“0-F”序号。相应按键序号排列如图4.14.1所示日口H图4.14.12 .硬件电路原理图.7R.Kn1A73 .系统板上硬件连线(1.把“单片机系统“区域中P3.0P3.7端口用8芯排线连接到“4X4行列式键盘”区域中Cl-C4R1-R4端口上;(2.把“单片机系统”区域中P0.0/AD0-P0.7/AD7端口用8芯排线连接到“四路静态数码显示模块”区域中任一种ah端口上;规定:P0.0/AD0相应着
2、a,PO.1/AD1相应着b,P0.7/AD7相应着h。4 .程序设计内容(1.4X4矩阵键盘辨认解决(2.每个按键有它行值和列值,行值和列值组合就是辨认这个按键编码。矩阵行线和列线分别通过两并行接口和CPU通信。每个按键状态同样需变成数字量“0”和“I”,开关一端(列线)通过电阻接VCC,而接地是通过程序输出数字“0”实现。键盘解决程序任务是:拟定有无键按下,判断哪一种键按下,键功能是什么;还要消除按键在闭合或断开时抖动。两个并行口中,一种输出扫描码,使按键逐行动态接地,另一种并行口输入按键状态,由行扫描值和回馈信号共同形成键编码而辨认按键,通过软件查表,查出该键功能。5 .程序框图6 .汇
3、编源程序KEYBUFEQU3011ORGOOHSTART:MOVKEYBUK#2WAIT:MOVP3,#OFFHC1.RP3.4MOV,P3AN1.A,#0FHXR1.A,#0FHJZNOKEYl1.CA1.1.DelyiomsMOVA,P3AN1.A,#0FHXR1.A,#0FHJZNOKEYlMOVA,P3AN1.A,#0FHCJNEA,#OEH,NKlMOVKEYBUF,#01.JMPDKlNK1:CJNEA,#ODH,NK2MOVKEYBUF,#11.JMPDKlNK2:CJNEA,#OBH,NK3MOVKEYBUF,#21.JMPDKlNK3:CJNEA,#07H,NK4MOVKEY
4、BUF,#31.JMPDKl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,#07H,NK16MOVKEYBUF,#151.JMPDK4NK16:NOPDK4:MOVA,KEYBUFMOVDPTR,STAB1.EMOVCA,A+DPTRMOVPO,ADK4A:MOVA,P3XR1.A,#OFHJNZDK4AN0KEY4:1.JMPWAI
8、TDE1.YIOMS:MOVR6,#10DI:MOVR7,#248DJNZR7,$DJNZR6,D1RETTAB1.E:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07HDB7FH,6FH,77H,7CH,39H,5EH,79H,71HEND7 .C语言源程序includeunsignedcharcodetable=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71;unsignedchartemp;unsignedcharkey;unsignedchari,j;void
9、main(void)while(l)P3=0xff;P3_4=0;temp=P3;temp=temp&OxOf;if(temp!=OxOf)for(i=50;i0;i)for(j=200;j0;j);temp=P3;temp=temp&OxOf;if(temp!=0x0f)temp=P3;temp=temp&OxOf;switch(temp)case0x0e:key=7;break;case0x0d:key=8;break;caseOxOb:key=9;break;case0x07:key=10;break;)temp=P3;P1_O=P1_O;PO=tablekey;temp=temp&Ox
10、Of;whiIe(temp!=OxOf)(temp=P3;temp=temp&OxOf;)P3=0xff;P3_5=0;temp=P3;temp=temp&OxOf;if(temp!=OxOf)for(i=50;i0;i一)for(j=200;j0;j);temp=P3;temp=temp&OxOf;if(temp!=OxOf)(temp=P3;temp=temp&OxOf;switch(temp)caseOxOe:key=4;break;caseOxOd:key=5;break;caseOxOb:key=6;break;case0x07:key=ll;break;temp=P3;P1_O=P
11、1_O;PO=tablekey;temp=temp&OxOf;while(temp!=OxOf)(temp=P3;temp=temp&OxOf;)P3=0xff;P3_6=0;temp=P3;temp=temp&OxOf;if(temp!=OxOf)(for(i=50;i0;i-)for(j=200;j0;j);temp=P3;temp=temp&OxOf;if(temp!=OxOf)(temp=P3;temp=temp&OxOf;switch(temp)caseOxOe:key=l;break;caseOxOd:key=2;break;caseOxOb:key=3;break;case0x0
12、7:key=12;break;)temp=P3;P1.O=P10;PO=tablekey;temp=temp&OxOf;while(temp!=OxOf)(temp=P3;temp=temp&OxOf;P3=0xff;P3_7=0;temp=P3;temp=temp&OxOf;if(temp!=OxOf)(for(i=50;i0;i)for(j=200;j0;j-);temp=P3;temp=temp&OxOf;if(temp!=OxOf)temp=P3;temp=temp&OxOf;switch(temp)case0x0e:key=0;break;caseOxOd:key=13;break;caseOxOb:key=14;break;case0x07:key=15;break;)temp=P3;Pl_0=l_0;P0=tablekey;temp=temp&OxOf;whiIe(temp!=OxOf)(temp=P3;temp=temp&OxOf;