资源描述:
《8051单片机倒计时器源程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、8051单片机倒计时器源程序说明:开机默认为15秒,p32启动键,p34个位调整,p35十位调整ORG0000H;程序入口地址LJMPMAINORG0003H;外部中断INT0入口地址LJMPINTT;转中断服务子程序ORG000BH;T0中断入口LJMPWT0;定时器T0入口地址ORG20HMAIN:MOVSP,#40H;设置栈指针MOV20H,#0H;把定时数据单元清零MOV21H,#0MOV22H,#0MOV23H,#15MOV24H,#0MOVTH0,#5;装入定时初值MOVTL0,#5MOVTMOD,#06H;设T0为方式2
2、SETBET0;允许T0中断CLRTR0;启动T0计数SETBIT0;设定INT0触发方式SETBEX0;INT0请求中断MOV34H,#1MOV35H,#5NOP;第二位显示数据│M:NOPLCALLLEDLCALLSONJNB00H,MMM:NOPLCALLZH1LCALLDSPLCALLLEDLJMPM;显示子程序DSP:MOVR7,#0AFHDSP0:MOVR0,#30HMOVDPTR,#TABNOPMOVA,@R0MOVCA,@A+DPTRRX1:MOVP0,ACLRP2.6DJNZR7,RX1MOVR7,#0AFHINCR
3、0MOVP0,#0FFHSETBP2.6MOVA,@R0MOVCA,@A+DPTRRX2:MOVP0,ACLRP2.5DJNZR7,RX2MOVR7,#8SETBP2.5DJNZ:R7,DSP0RETDSP1:MOVR7,#0FHDSP01:MOVR0,#34HMOVDPTR,#TABMOVA,@R0MOVCA,@A+DPTRRX01:MOVP0,ACLRP2.5DJNZR7,$MOVR7,#0FHINCR0SETBP2.5MOVA,@R0MOVCA,@A+DPTRMOVP0,ACLRP2.6DJNZR7,$SETBP2.6RETZH
4、1:MOVR2,#0MOVR3,23HACALLBCDMOVA,R6ANLA,#0FHMOV30H,AMOVA,R6ANLA,#0F0HSWAPAMOV31H,ARET十进制转换为二进制子程序DTOB:MOV32H,#0MOV33H,#0MOVR0,#32HMOVR2,#3ACALLIDTBMOVA,R4MOV23H,ARETIDTB:MOVR3,#0MOVA,@R0MOVR4,AIDTL:MOVA,R4MOVB,#10MULABMOVR4,AMOVB,#10XCHA,BXCHA,R3MULABADDA,R3XCHA,R4INCR0A
5、DDA,@R0XCHA,R4ADDCA,#0MOVR3,ADJNZR2,IDTLRETBCD:CLRA;二进制数转换为十进制数子程序MOVR4,AMOVR5,AMOVR6,AMOVR7,#16IBTL2:CLRCMOVA,R3RLCAMOVR3,AMOVA,R2RLCAMOVR2,AMOVA,R6ADDCA,R6DAAMOVR6,AMOVA,R5ADDCA,R5DAAMOVR5,AMOVA,R4ADDCA,R4DAAMOVR4,ADJNZR7,IBTL2RET;延时子程序DL:MOVR7,#02HDL1:MOVR6,#0FFHDL2:
6、DJNZR6,DL2DJNZR7,DL1RET;外部中断服务子程序INTT:CLREX0PUSHACCPUSHPSWSETBP1.0LCALLDSP1PK:JBP3.2,TOEXTPK0:ACALLDSP1JNBP3.2,PK0PK2:JBP3.5,PK3;判K2按下否,未按则转到判K3状态LCALLDSP1INC34HMOVA,34HCJNEA,#0AH,PK22MOV34H,#0PK22:ACALLDSP1;K2按下,30H加1JNBP3.5,PK22LJMPPK2PK3:ACALLDSP1JBP3.4,PK1;判K3按下否,未按
7、则转到判K1状态INC35HMOVA,35HCJNEA,#0AH,PK33MOV35H,#0PK33:LCALLDSP1JNBP3.4,PK33LJMPPK3PK1:LCALLDSP1JBP3.2,PK2;K1未按则转判K2和K3PK10:ACALLDSP1JNBP3.2,PK10LCALLDTOBSETB00HTOEXT:SETBEX0;开中断SETBTR0POPPSW;恢复现场POPACCRETILED:JB01H,LED0CLRP1.0RETLED0:SETBP1.0RETSON:JB02H,SON0CLRP3.3RETSON0
8、:SETBP3.3RETTAB:DB28h,7eh,0a2h,62h,74h,61h,21h,7ah,20h,60h;段码表;定时中断服务子程序WT0:PUSHACCPUSHPSWINC21H;0.5msMOVA,21H