资源描述:
《[精品]按键实验指导书.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、[精品]按键实验指导书 按健实验实验一按下一个健,红色LED亮,绿色灭,按下另一个键,红色LED灭,绿色亮 一、新建项目key_1.prj,加入以下模块文件key_1.asm;定义变量g_KeyValueEQU34Hb_PressKeyBIT00Hb_KeyValidBIT01H;定义代码段org0000HReset:ljmpMainorg0050HMain:lcallInitSystemMainLoop:lcallScanKeylcallReleaseKeylcallControlKeyjmpMainLoop;子程序----------
2、----------------InitSystem:clrb_PressKeyclrb_KeyValidretScanKey:jnbb_PressKey,Ke0;若键已按下,则无需扫描retKe0:movA,#03HorlP3,AmovA,P3anlA,#03Hcjnea,#03H,Ke2Ke1:clrb_PressKeyretKe2:lcallDelay_1msmova,P3anla,#03Hcjnea,#03H,Ke3sjmpKe1Ke3:movg_KeyValue,asetbb_PressKeysetbb_KeyValidret;--
3、----------------------------------ReleaseKey:jbb_PressKey,RK1retRK1:mova,P3anla,#03Hcjnea,#03H,RK2clrb_PressKey;键释放RK2:ret;--------------------------------------ControlKey:jbb_KeyValid,CK1retCK1:mova,g_KeyValuecjnea,#01H,CK2clrp3.2setbp3.3sjmpCK3CK2:clrp3.3setbp3.2CK3:clrb_
4、KeyValidret;-----------------------------------------------Delay_1ms:movr7,#200D_1ms1:nopdjnzr7,D_1ms1retEND 二、编译,全速运行 三、按下一个健,看其显示如何变化,再按另一个健,看其显示如何变化 四、分析此程序如何实现按健功能 五、修改源程序,原来红色亮健改成绿色亮健,原来绿色亮健改成红色亮健实验二按下一个健,数码管显示增加一;按下另一个健,数码管显示减少 一一、新建项目key_1.prj,加入以下模块文件key_2.asm;
5、定义变量g_DisplayBuff_1EQU30Hg_DisplayBuff_2EQU31Hg_CounterEQU32Hg_KeyValueEQU34Hb_PressKeyBIT00Hb_KeyValidBIT01H;定义代码段org0000HReset:ljmpMainorg0050HMain:lcallInitSystemMainLoop:lcallScanKeylcallReleaseKeylcallControlKeylcallDisplayCounterjmpMainLoop;子程序------------------------
6、--InitSystem:movg_Counter,#50clrb_PressKeyclrb_KeyValidretScanKey:jbb_PressKey,Ke1movA,#03HorlP3,AmovA,P3anlA,#03Hcjnea,#03H,Ke2Ke0:clrb_PressKeyKe1:movg_KeyValue,#0FFHretKe2:lcallDelay_1msmova,P3anla,#03Hcjnea,#03H,Ke3sjmpKe0Ke3:movg_KeyValue,asetbb_PressKeysetbb_KeyValidr
7、et;------------------------------------ReleaseKey:jbb_PressKey,RK1retRK1:mova,P3anla,#03Hcjnea,#03H,RK2clrb_PressKeyRK2:ret;--------------------------------------ControlKey:jbb_KeyValid,CK1retCK1:mova,g_KeyValuecjnea,#01H,CK2decg_CountersjmpCK3CK2:incg_CounterCK3:clrb_KeyVa
8、lidret;-----------------------------------------DisplayCounter:mova,g_Countermovb,