資源描述:
《8位led電子時(shí)鐘設(shè)計(jì)設(shè)計(jì)的源程序清單》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、4程序源代碼本設(shè)計(jì)的匯編、C語(yǔ)言原程序清單如下:(1)匯編程序匯編語(yǔ)言源程序清單為:ORG0000HLJMPSTARTORG000BH;定時(shí)/計(jì)數(shù)器T0中斷程序入口LJMPINTT0;主程序START:MOVR0,#70H;70H~77H單元為L(zhǎng)ED數(shù)碼管的顯示緩沖區(qū)MOVR7,#0CH;78H,79H,7AH分別為秒、分、小時(shí)計(jì)數(shù)單元;7BH為50ms計(jì)數(shù)器,7CH為調(diào)時(shí)按鍵計(jì)數(shù)器INIT:MOV@R0,#00HINCR0DJNZR7,INIT;70H-7CH全部清0MOVTMOD,#01H;T0工作在方式1MOVTL0,#0B0H;T0定時(shí)50msMOVTH0,#3CHSET
2、BEASETBET0SETBTR0START1:LCALLSCAN;調(diào)用顯示子程序LCALLKEYSCAN;調(diào)用鍵盤(pán)子程序SJMPSTART1;延時(shí)1ms子程序DL1MS:MOVR6,#14H;1μsDL1:MOVR7,#19H;1μsDL2:DJNZR7,DL2;25次×2μs=50μsDJNZR6,DL1;2μsRET;2μs1μs+(25次×2μs+3μs)×20次+2μs=1063μs=1.063ms≈1ms;延時(shí)20ms子程序DL20MS:ACALLSCANACALLSCANACALLSCANRET;數(shù)碼管顯示程序SCAN:MOVA,78H;秒MOVB,#0AHDIVA
3、B;A-商,B-余數(shù)MOV71H,A;秒十位MOV70H,B;秒個(gè)位MOVA,79H;分MOVB,#0AHDIVABMOV74H,AMOV73H,BMOVA,7AH;時(shí)MOVB,#0AHDIVABMOV77H,AMOV76H,BMOVR1,#70H;循環(huán)掃描8位顯示MOVR5,#0FEH;位選碼初值MOVR6,#08H;8位顯示SCAN1:MOVA,R5MOVP2,AMOVA,@R1MOVDPTR,#TABMOVCA,@A+DPTR;遠(yuǎn)程查表MOVP0,A;段選碼MOVA,R5LCALLDL1MSINCR1MOVA,R5RRAMOVR5,ADJNZR6,SCANMOVP2,#0F
4、FHMOVP0,#0FFHRETTAB:DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H,0BFH;“0~9”,“-”的七段共陽(yáng)極字段碼;定時(shí)器/計(jì)數(shù)器T0中斷服務(wù)程序INTT0:PUSHACC;現(xiàn)場(chǎng)保護(hù)PUSHPSWCLRET0CLRTR0MOVTL0,#0B0H;T0定時(shí)50msMOVTH0,#3CHSETBTR0INC7BH;50ms定時(shí)到記數(shù)MOVA,7BHCJNEA,#14H,OUTT0;計(jì)20次(即1s)MOV7BH,#00INC78H;秒加1MOVA,78HCJNEA,#3CH,OUTT0;計(jì)60sMOV78H,#00IN
5、C79H;分加1MOVA,79HCJNEA,#3CH,OUTT0;不等跳,計(jì)60分MOV79H,#00INC7AH;時(shí)加1MOVA,7AHCJNEA,#18H,OUTT0;計(jì)24時(shí)MOV7AH,#00OUTT0:SETBET0RETI;按鍵處理程序KEYSCAN:CLREAJNBP1.0,KEYSCAN0;為0跳JNBP1.1,KEYSCAN1JNBP1.2,KEYSCAN2KEYOUT:SETBEARETKEYSCAN0:LCALLDL20MS;K0去抖JBP1.0,KEYOUT;為1跳WAIT0:JNBP1.0,WAIT0;P1.0=0跳INC7CH;K0松開(kāi)后7CH加1CL
6、RET0CLRTR0CJNEA,#03H,KEYOUT;不等跳;K0按1下或2下返回,按3下7CH清0,不能調(diào)秒MOV7CH,#00SETBET0SETBTR0SJMPKEYOUTKEYSCAN1:LCALLDL20MS;K1鍵去抖JBP1.1,KEYOUTWAIT1:JNBP1.1,WAIT1;P1.1=0跳,等待松開(kāi)K1MOVA,7CHCJNEA,#02H,KSCAN11;不等跳,K0按2下,調(diào)整分INC79H;分加1MOVA,79HCJNEA,#3CH,KEYOUT;為60分嗎?MOV79H,#00SJMPKEYOUTKSCAN11:INC7AH;時(shí)加1MOVA,7AHCJ
7、NEA,#18H,KEYOUT;為24時(shí)嗎?MOV7AH,#00SJMPKEYOUT;按1下調(diào)時(shí),按2下調(diào)分KEYSCAN2:LCALLDL20MS;K2去抖JBP1.2,KEYOUT;P1.2=1跳WAIT2:JNBP1.2,WAIT2;松開(kāi)K2MOVA,7CHCJNEA,#02H,KSCAN21;K2按2下嗎?按2下調(diào)整分DEC79H;分減1MOVA,79HCJNEA,#0FFH,KEYOUTMOV79H,#3BH;計(jì)59分SJMPKEYOUTKSCAN21:DEC7AH;時(shí)