資源描述:
《2012單片機(jī)程序及復(fù)習(xí)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、1清零實(shí)驗(yàn)1:將30H40H單元清零ORG0000AJMPMAINORG0030HMAIN:MOVSP,#60HMOVR0,#0MOVDPTR,#8000HMOVA,#0ABHLOOP:MOVX@DPTR,AINCDPTRDJNZR0,LOOPAJMP$END2拆字實(shí)驗(yàn)ORG0000HAJMPMAINORG0030HMAIN:MOVSP,#60HMOVDPTR,#0E100H//8155命令口(8155初始化開始)MOVA,#3//PAPB口輸出,PC口輸出MOVX@DPTR,A//(8155初始化完)MOV20H,#34H//將34H送20HMOVA,20H//讀出20H單元的數(shù)ACAL
2、LCHAI//調(diào)用拆字子程序//**顯示子程序送三個(gè)入口參數(shù)LOOP:MOVR0,#10H//顯示緩沖區(qū)首地址MOVR1,#2//數(shù)碼管顯示位數(shù)(2位)MOVR2,#1//顯示數(shù)碼管的低位地址;ACALLDISPLAY//調(diào)用顯示子程序AJMPLOOPDISPLAY:MOVA,@R0;讀顯示數(shù)MOV0FH,#8;164移位次數(shù)ACALLP164;字形碼輸出子程序ACALLPBIT;字位碼輸出子程序ACALLDELAY;延時(shí)2msMOVA,#0;熄滅顯示MOVX@DPTR,AINCR0;指向下一位顯示數(shù)DJNZR1,DISPLAY;沒有顯示完繼續(xù)RETP164:MOVDPTR,#TABMOV
3、CA,@A+DPTRP164_1:RRCAMOVR3,AMOVACC.0,CANLA,#0FDHMOVDPTR,#0E102HMOVX@DPTR,AORLA,#0FEHMOVX@DPTR,AMOVA,R3DJNZ0FH,P164_1MOV0FH,#8RETPBIT:MOVDPTR,#0E101HMOVA,R2MOVX@DPTR,ARLAMOVR2,ARETDELAY:MOVR6,#4DEL:MOVR7,#250DJNZR7,$DJNZR6,DELRETTAB:DB0FCH,60H,0DAH,0F2H,66H,0B6H,0BEH,0E0HDB0FEH,0F6H,0EEH,3EH,9CH,7A
4、H,9EH,8EH//拆字子程序CHAI:MOVB,#10H//立即數(shù)10H送BDIVAB//A/BMOV10H,B//B送10H單元(低4位)MOV11H,A//A送11H單元(高4位)RET//子程序返回END3閃爍燈實(shí)驗(yàn)ORG0000HAJMPMAINORG0030HMAIN:MOVSP,#60HMOVR4,#10LOOP1:CLRP3.3LOOP3:JBP3.5,LOOP1JBP3.4,LOOP2JNBP3.4,$DJNZR4,LOOP2MOVR4,#10LOOP2:CPLP3.3MOV5,4ACALLDELAYAJMPLOOP3MOVR5,#10DELAY:MOVR6,#200D
5、EL:MOVR7,#229DJNZR7,$DJNZR6,DELDJNZR5,DELAYRETEND4交通燈實(shí)驗(yàn)ORG0000HAJMPMAINORG0030HMAIN:MOVSP,#60HMOVDPTR,#0AC03HMOVA,#80HMOVX@DPTR,AMOVDPTR,#0AC00HMOVA,#0F0HMOVX@DPTR,AMOVR5,#20ACALLDELAYLOOP1:MOVA,#5AHMOVX@DPTR,AMOVR5,#100ACALLDELAYMOVR4,#3LOOP2:MOVA,#50HMOVX@DPTR,AMOVR5,#5ACALLDELAYMOVA,#0FAHMOVX@D
6、PTR,AMOVR5,#5ACALLDELAYDJNZR4,LOOP2MOVA,#0A5HMOVX@DPTR,AMOVR5,#100ACALLDELAYMOVR4,#3LOOP3:MOVA,#0A0HMOVX@DPTR,AMOVR5,#5ACALLDELAYMOVA,#0F5HMOVX@DPTR,AMOVR5,#5ACALLDELAYAJMPLOOP1DELAY:MOVR6,#200DEL:MOVR7,#229DJNZR7,$DJNZR6,DELDJNZR5,DELAYRETEND5定時(shí)器實(shí)驗(yàn)ORG0000HAJMPMAINORG001BHAJMPINT_1ORG0030HMAIN:MOV
7、SP,#60HMOVTMOD,#10HMOVTH1,#4BH//定時(shí)器初始化MOVTL1,#0FDHMOVR1,#20SETBEASETBET1SETBTR1MOVDPTR,#TABMOVR2,#0AJMP$INT_1:MOVTH1,#4BHMOVTL1,#0FDHDJNZR1,LP1MOVR1,#20MOVA,R2MOVCA,@A+DPTRMOVP1,AINCR2CJNER2,#8,LP1MOVR2,#0LP1:RET