键盘扫描及显示设计实验

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

【实验内容】将8255单元与键盘及数码管显示单元连接,编写实验程序,扫描键盘输入,并将扫描结果送数码管显示。键盘采用4×4键盘,每个数码管显示值可为0~F共16个数。实验具体内容如下:将键盘进行编号,记作0~F,当按下其中一个按键时,将该按键对应的编号在一个数码管上显示出来,当再按下一个按键时,便将这个按键的编号在下一个数码管上显示出来,数码管上可以显示本次按键的按键编号。8255键盘及显示实验参考接线图如图1所示。【实验步骤】1.按图1连接线路图;2.编写实验程序,检查无误后编译、连接并装入系统;3.运行程序,按下按键,观察数码管的显示,验证程序功能。【程序代码】MY8255_AEQU0600HMY8255_BEQU0602HMY8255_CEQU0604HMY8255_CONEQU0606HSSTACKSEGMENTSTACKDW16DUP(?)SSTACKENDSDATASEGMENTDTABLEDB3FH,06H,5BH,4FHDB66H,6DH,7DH,07HDB7FH,6FH,77H,7CHDB39H,5EH,79H,71Htable1db0dfh,0efh,0f7h,0fbh,0fdh,0fehcountdb0hDATAENDODESEGMENTASSUMECS:CODE,DS:DATASTART:MOVAX,DATAMOVDS,AXMOVSI,3000HMOVAL,03HMOV[SI],AL;清显示缓冲MOV[SI+1],ALMOV[SI+2],ALMOV[SI+3],ALMOV[SI+4],ALMOV[SI+5],ALMOVDI,3005HMOVDX,MY8255_CON;写8255控制字MOVAL,81HOUTDX,ALBEGIN:CALLDIS;调用显示子程序CALLCLEAR;清屏CALLCCSCAN;扫描JNZINK1JMPBEGININK1:CALLDISCALLDALLYCALLDALLYCALLCLEARCALLCCSCANJNZINK2;有键按下,转到INK2JMPBEGIN;========================================;确定按下键的位置;========================================INK2:MOVCH,0FEHMOVCL,00HCOLUM:MOVAL,CHMOVDX,MY8255_AOUTDX,ALMOVDX,MY8255_CINAL,DXL1:TESTAL,01H;isL1?JNZL2MOVAL,00H;L1JMPKCODEL2:TESTAL,02H;isL2?JNZL3MOVAL,04H;L2JMPKCODEL3:TESTAL,04H;isL3?JNZL4MOVAL,08H;L3JMPKCODEL4:TESTAL,08H;isL4?JNZNEXTMOVAL,0CH;L4KCODE:ADDAL,CLCALLPUTBUFPUSHAXKON:CALLDISCALLCLEARCALLCCSCANJNZKONPOPAXNEXT:INCCLMOVAL,CHTESTAL,08HJZKERRROLAL,1MOVCH,ALJMPCOLUMKERR:JMPBEGIN;========================================;键盘扫描子程序;========================================CCSCAN:MOVAL,00HMOVDX,MY8255_AOUTDX,ALMOVDX,MY8255_CINAL,DXNOTALANDAL,0fh;callDISRET;========================================;清屏子程序;========================================CLEAR:MOVDX,MY8255_BMOVAL,00HOUTDX,ALRET;========================================;显示子程序;========================================DIS:PUSHAXMOVSI,3000HMOVDL,0DFHMOVAL,DLmovcount,0hAGAIN:PUSHDXMOVDX,MY8255_AOUTDX,ALMOVAL,[SI]MOVBX,OFFSETDTABLEANDAX,00FFHADDBX,AXMOVAL,[BX]MOVDX,MY8255_BOUTDX,ALCALLDALLYINCSIPOPDXMOVAL,DLTESTAL,01HJZOUT1RORAL,1MOVDL,ALJMPAGAINOUT1:POPAXRET;======延时子程序======DALLY:PUSHCXMOVCX,0006HT1:MOVAX,009FHT2:DECAXJNZT2LOOPT1POPCXRET;========================================;存键盘值到相应位的缓冲中;========================================PUTBUF:pushdimovdi,3000hmovsi,diMOV[SI],10h;清显示缓冲MOV[SI+1],10hMOV[SI+2],10hMOV[SI+3],10hMOV[SI+4],10hMOV[SI+5],10hpopdiMOVSI,DIMOV[SI],ALDECDICMPDI,2FFFHJNZGOBACKMOVDI,3005HGOBACK:RETCODEENDSENDSTART

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功