资源描述:
《按键实验指导书》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、按健实验实验一按下一个健,红色LED亮,绿色灭,按下另一•个键,红色LED灭,绿色亮一、新建项目key_1.prj,加入以下模块文件key_1.asm;定义变量gKeyValueEQU34Hb_PressKeyBITOOHb_KeyValidBIT01H;定义代码段org0000HReset:IjmpMainorg0050HMain:lcallInitSystemMainLoop:lcallSeanKeylcallReleaseKeylcallControlKeyjmpMainLoop;子程序InitSystem:clrb_PressKeyclrbKeyValidretScanKey:j
2、nbbPressKey,KeO;若键已按下,则无需扫描retKeO:movA,#03HorlP3,AmovA,P3anlA,#03Hcjnea,#03H,Ke2Kel:clrb_PressKeyretKe2:leal]LDelay_lmsmova,P3anla,#03Hcjnea,#03H,Ke3sjmpKclKe3:movg_KeyValue,asetbb_PressKeysetbbKeyValidretReleaseKey:jbb_PressKey,RK1retRK1:mova,P3anla,#03Hcjnea,#03H,RK2clrb_PressKey;键释放RK2:retCont
3、rolKcy:jbb_KeyValid,CK1retCKl:mova,g_KeyValuecjnea,#01H,CK2clrp3.2setbp3.3sjmpCK3CK2:clrp3.3setbp3.2CK3:clrb_KeyValidretDelay_lms:movr7,#200D_lmsl:nopdjnzr7,DlmslretEND二、编译,全速运行三、按下一个健,看其显示如何变化,再按另一个健,看其显示如何变化四、分析此程序如何实现按健功能五、修改源程序,原來红色亮健改成绿色亮健,原來绿色亮健改成红色亮健实验二按卞一个健,数码管显示增加一;按下另一个健,数码管显示减少一一、新建项目k
4、ey_1.prj,加入以下模块文件key_2.asm;定义变量gDisplayBuff1EQU3011g_DisplayBuff_2EQU31Hg_CounterEQU32HgKeyValueEQU34Hb_Pre$sKeyBITOOHbKeyValidBIT0111;定义代码段org0000HReset:1jmpMainorg0050HMain:lcallInitSystemMainLoop:lcallScanKeylcallReleaseKeylcallControlKeylcallDisplayCounterjmpMainLoop;子程序InitSystem:movgCounter
5、,#50clrb_PressKeyclrbKeyValidScanKey:retjbb_PressKey,KelmovA,#0311orlP3,AmovA,P3anlA,#03HKeO:cjnea,#0311,Ke2Kel:clrb_PressKeymovg_KeyValue,#0FFHKe2:retlcallDelay_lmsmova,P3anla,#03Hcjnea,#0311,Ke3Ke3:sjmpKcOmovg_KeyValue,asetbb_PressKeysetbbKeyValidretReleaseKey:jbb_PressKey,RK1retRKl:mova,P3anla
6、,#03Hcjnea,#03H,RK2clrb_PressKeyRK2:retControlKcy:jbb_KeyValid,CK1retCKl:mova,g_KeyValuecjnea,#01H,CK2decgCountersjmpCK3CK2:incgCounterCK3:clrbKeyVaiidretDisplayCounter:mova,gCountermovb,#10divabmovgDisplayBuff1,amovgDisplayBuff2,blcallDisplayretDisplay:movdptr,#charOnLEDmova,gDisplayBuff1movea,@
7、a+dptrmovpl,asetbpl.7lcallDelay」msmovpl,#OFFHlcallDelay1msmova,g_DisplayBuff_movea,@a+dptrmovpl,aclrpl.7lcallDelay1msmovpl,#71训lcallDelay_lmsretDelay_lms:movr7,#200D_lmsl:nopdjnzr7,Dlmslret定义数据段charOnLED:DBDBOCOH,0F9H,