单片机流程图
S_CNTEQU10;0.1秒计数器初值ORG0000HLJMPSTARTORG000BHLJMPT0_INT_SVRORG0030HSTART:CLRP3.4;关继电器...
S_CNTEQU10;0.1秒计数器初值
ORG0000H
LJMPSTART
ORG000BH
LJMPT0_INT_SVR
ORG0030H
START:
CLRP3.4;关继电器
CLRF0
MOVR5,#S_CNT;秒计数器1CH(R5)置初值
MOV38H,#00H
MOV39H,#01H
MOVP3,#0FFH;读设定植
MOVA,P3
CPLA
ANLA,#0FH;屏蔽高4位,保留低4位
MOV30H,A
MOVP1,#0FFH
MOVA,P1
CPLA
MOV31H,A
MOVSP,#6FH;堆栈初始化
MOVTMOD,#01H;T0定时器工作方式1
MOVTH0,#-10000/256;置计数器初值高8位
MOVTL0,#-10000 MOD 256;置计数器初值低8位
SETBEA;CPU开中断
SETBET0;T0开中断
SETBTR0;启动定时器T0
WAIT:JBF0,WLP
CLRP3.4
WLP:SJMPWAIT;等待中断
TAB:DB0C0H,0F9H,0A4H,0B0H,99H,92H
DB82H,0F8H,80H,90H,0FFH
T0_INT_SVR:
MOVTH0,#55536/256;重置计数器初值高8位
MOVTL0,#55536 MOD 256;重置计数器初值低8位
JBF0,NEXT1
DJNZR5,NEXT1
MOVR5,#S_CNT;0.1秒计数器1CH(R5)重置初值
MOVR0,#31H
LCALLBCDDEC2B
NEXT1:MOVA,30H
ANLA,#0FH
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
CLRP3.7
LCALLDELAY1MS
SETBP3.7
MOVA,31H
SWAPA
ANLA,#0FH
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
CLRP3.6
LCALLDELAY1MS
SETBP3.6
MOVA,31H
ANLA,#0FH
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
CLRP3.5
LCALLDELAY1MS
SETBP3.5
MOVA,30H
CJNEA,#00H,INTRET
MOVA,31H
CJNEA,#00H,INTRET
SETBP3.4
SETBF0
INTRET:RETI
DELAY1MS:
MOVR7,#20H
DLP0:MOVR6,#00H
DLP1:DJNZR6,DLP1
DJNZR7,DLP0
RET
NOP
NOP
;**********************************************************************
;两字节BCD码+1子程序
;**********************************************************************
BCDINC2B:
MOV R2,#02H ;两字节BCD码+1子程序
MOV R1,#0A9H
BCDINC1:
CLR C
BCDINC2:
MOV A,@R0
ADDC A,@R1
DA A
MOV @R0,A
DEC R0
DEC R1
DJNZ R2,BCDINC2
NOP
NOP
RET
NOP
NOP
;**********************************************************************
;两子节BCD码-1子程序
;**********************************************************************
BCDDEC2B:
MOV R2,#02H ;两子节BCD码-1子程序
MOV R1,#039H
BCDDEC1:
SETB C
BCDDEC2:
CLR A
ADDC A,#99H
SUBB A,@R1
ADD A,@R0
DA A
MOV @R0,A
DEC R0
DEC R1
DJNZ R2,BCDDEC2
CPL C
NOP
NOP
RET
NOP
NOP
END 展开
ORG0000H
LJMPSTART
ORG000BH
LJMPT0_INT_SVR
ORG0030H
START:
CLRP3.4;关继电器
CLRF0
MOVR5,#S_CNT;秒计数器1CH(R5)置初值
MOV38H,#00H
MOV39H,#01H
MOVP3,#0FFH;读设定植
MOVA,P3
CPLA
ANLA,#0FH;屏蔽高4位,保留低4位
MOV30H,A
MOVP1,#0FFH
MOVA,P1
CPLA
MOV31H,A
MOVSP,#6FH;堆栈初始化
MOVTMOD,#01H;T0定时器工作方式1
MOVTH0,#-10000/256;置计数器初值高8位
MOVTL0,#-10000 MOD 256;置计数器初值低8位
SETBEA;CPU开中断
SETBET0;T0开中断
SETBTR0;启动定时器T0
WAIT:JBF0,WLP
CLRP3.4
WLP:SJMPWAIT;等待中断
TAB:DB0C0H,0F9H,0A4H,0B0H,99H,92H
DB82H,0F8H,80H,90H,0FFH
T0_INT_SVR:
MOVTH0,#55536/256;重置计数器初值高8位
MOVTL0,#55536 MOD 256;重置计数器初值低8位
JBF0,NEXT1
DJNZR5,NEXT1
MOVR5,#S_CNT;0.1秒计数器1CH(R5)重置初值
MOVR0,#31H
LCALLBCDDEC2B
NEXT1:MOVA,30H
ANLA,#0FH
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
CLRP3.7
LCALLDELAY1MS
SETBP3.7
MOVA,31H
SWAPA
ANLA,#0FH
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
CLRP3.6
LCALLDELAY1MS
SETBP3.6
MOVA,31H
ANLA,#0FH
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP2,A
CLRP3.5
LCALLDELAY1MS
SETBP3.5
MOVA,30H
CJNEA,#00H,INTRET
MOVA,31H
CJNEA,#00H,INTRET
SETBP3.4
SETBF0
INTRET:RETI
DELAY1MS:
MOVR7,#20H
DLP0:MOVR6,#00H
DLP1:DJNZR6,DLP1
DJNZR7,DLP0
RET
NOP
NOP
;**********************************************************************
;两字节BCD码+1子程序
;**********************************************************************
BCDINC2B:
MOV R2,#02H ;两字节BCD码+1子程序
MOV R1,#0A9H
BCDINC1:
CLR C
BCDINC2:
MOV A,@R0
ADDC A,@R1
DA A
MOV @R0,A
DEC R0
DEC R1
DJNZ R2,BCDINC2
NOP
NOP
RET
NOP
NOP
;**********************************************************************
;两子节BCD码-1子程序
;**********************************************************************
BCDDEC2B:
MOV R2,#02H ;两子节BCD码-1子程序
MOV R1,#039H
BCDDEC1:
SETB C
BCDDEC2:
CLR A
ADDC A,#99H
SUBB A,@R1
ADD A,@R0
DA A
MOV @R0,A
DEC R0
DEC R1
DJNZ R2,BCDDEC2
CPL C
NOP
NOP
RET
NOP
NOP
END 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询