资源描述:
《矩阵按键控制的电子时钟程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、源程序:FKEYEQU20H.0SHIEQU50HFENEQU51HMIAOEQU52HCOUNTEREQU4AHTEMPEQU30HKEY_NOEQU21HTEMP_NUMEQU22HORG0000HLJMPMAINORG000BHLJMPINTT0ORG0100HMAIN:MOVSP,#60HMOVCOUNTER,#00MOVSHI,#00MOVFEN,#00MOVMIAO,#00LCALLDISPLCALLKEY_SCANJBFKEY,WAIT_OFF0;若有按键就等待按键放开,无则继续扫描显示器和键盘AJMPMAINWAIT_O
2、FF0:ACALLDISPACALLKEY_SCANJBFKEY,WAIT_OFF0MOVR5,#5ACALLDELAY;延时1ms,清抖作用;按键松开后WAIT0:MOVA,KEY_NO;按键松开后CJNEA,#0AH,MAINSETBEASETBET0MOVTMOD,#01HMOVTL0,#0B0HMOVTH0,#3CHSETBTR0SCAN:CLRKEY_NOCLRFKEYSCAN0:LCALLDISP;调用扫描子程序ACALLKEY_SCAN;调用扫描子程序SCAN1:JBFKEY,WAIT_OFF;若有按键就等待按键放开,无则
3、继续扫描显示器和键盘AJMPSCANWAIT_OFF:ACALLDISPACALLKEY_SCANJBFKEY,WAIT_OFFMOVR5,#5ACALLDELAY;延时1ms,清抖作用;按键松开后WAIT:MOVA,KEY_NO;按键松开后NEXT:;键值判断,分支跳转CJNEA,#0AH,NEXT0ACALLSTOP;停止NEXT0:CJNEA,#0BH,NEXT1ACALLTIAOSHI;NEXT1:CJNEA,#0CH,NEXT2ACALLTIAOFEN;NEXT2:CJNEA,#0DH,NEXT3ACALLTIAOMIAO;N
4、EXT3:CJNEA,#0EH,NEXT4ACALLSTOP;NEXT4:CJNEA,#0FH,NEXT5ACALLSTOP;NEXT5:AJMPSCAN;******************************************STOP:AJMPMAINRET;*************************键盘扫描子程序****************************WWWWWWWWKEY_SCAN:MOVR3,#0EFH;加载扫描输出初始信号11101111BMOVR4,#0MOVR1,#4CLRPSW.5S1
5、:MOVA,R3;循环扫描16个按键MOVP1,AMOVR5,#1ACALLDELAYMOVA,P1;读取P1口数据判断按键是否有效ANLA,#0FHMOVR2,#4S2:JBACC.0,N1;判断有无按键,若为1则表示没按键按下MOVKEY_NO,R4SETBPSW.5N1:INCR4RRADJNZR2,S2;对一行进行扫描MOVA,R3RLA;移至下一行扫描MOVR3,ADJNZR1,S1BACK:JNBPSW.5,NO_KEYSETBFKEYRETNO_KEY:CLRFKEYRET;************************
6、****************************************************;******************************************数字对换***************************WWWWWWHUAN:MOVA,SHIMOVB,#10DIVABMOVTEMP,AMOVTEMP+1,BMOVTEMP+5,#10MOVA,FENMOVB,#10DIVABMOVTEMP+3,AMOVTEMP+4,BMOVTEMP+2,#10MOVA,MIAOMOVB,#10DIVABMO
7、VTEMP+6,AMOVTEMP+7,BRET;***********************************按键功能子程序****************************TIAOSHI:CLREACLRFKEYMOVA,#00HMOVKEY_NO,AM0:LCALLKEY_SCANLCALLDISPJBFKEY,WAIT_OFF1;若有按键就等待按键放开,无则继续扫描显示器和键盘AJMPM0WAIT_OFF1:ACALLDISPACALLKEY_SCANJBFKEY,WAIT_OFF1MOVR5,#5ACALLDELA
8、Y;延时1ms,清抖作用;按键松开后MOVA,KEY_NO;按键松开后CJNEA,#0BH,TIAN0LCALLQD0TIAN0:MOVA,KEY_NOCLRCSUBBA,#0AHJNCM0MOVA,KEY