LOCAL ZZ
INC U16+1
MOV A,U16+1
JNZ ZZ
MOV U16+1,#0
INC U16
ZZ:
ENDM
U16MOV MACRO U16,VAL ;;16位无符号型变量赋值
MOV U16+1,#LOW(VAL)
MOV U16,#HIGH(VAL)
ENDM
U16DAYV MACRO U16,VAL, ;;16位无符号型变量判断大小,最后根据Cy判断
MOV A,U16+1
CLR C
SUBB A,#LOW(VAL)
MOV A,U16
SUBB A,#HIGH(VAL)
ENDM
WX1 EQU P2.0
WX2 EQU P2.1
WX3 EQU P2.2
WX4 EQU P2.3
S4 EQU P1.3
S5 EQU P1.4
LED1 EQU P1.6 ;;两个LED
LED2 EQU P1.7
JDQ EQU P1.5 ;;继电器
SMGBZ1 EQU 0X30
DS1 EQU 0X31
ZT EQU DS1+4
JSBZ1 EQU ZT+1 ;0-39的计数
JSBZ2 EQU ZT+2 ;计时标志,用于闪烁和计时
JSBZ3 EQU JSBZ2+2 ;;继电器通断两次的计时和计数
ORG 0
JMP MAIN
ORG 0XB
JMP TimeInterupt
MAIN:
MOV SP,#0X70
MOV R0,#0x70
CLR A
MA1: MOV @R0,A ;数据全清0
DJNZ R0,MA1
CALL JDQLC_STOP
CALL Time0Init
;主循环
LOOP: CALL AJPD
CALL RUN
JMP lOOP
;主运行函数
RUN: MOV A,ZT
CJNE A,#1,RR1
JMP RUN1
RR1: CJNE A,#2,RR2
JMP RUN2
RR2: RET
;;0-39循环
RUN1:
MOV DS1+0,#0X10
MOV DS1+1,#0X10
MOV A,JSBZ1
MOV B,#10
DIV AB
MOV DS1+2,A
MOV DS1+3,B
U16DAYV JSBZ2,1000
JC RUN1_1
U16MOV JSBZ2,0
INC JSBZ1
MOV A,JSBZ1
CJNE A,#39+1,RUN1_1
MOV JSBZ1,#0
RUN1_1:
RET
;;FFFF闪烁
RUN2: U16DAYV JSBZ2,500
JC RUN2_1
MOV DS1+0,#0X10
MOV DS1+1,#0X10
MOV DS1+2,#0X10
MOV DS1+3,#0X10
SETB LED1
SETB LED2
U16DAYV JSBZ2,1000
JC RUN2_2
U16MOV JSBZ2,0
JMP RUN2_2
RUN2_1:
MOV DS1+0,#0X0F
MOV DS1+1,#0X0F
MOV DS1+2,#0X0F
MOV DS1+3,#0X0F
CLR LED1
CLR LED2
RUN2_2:
CALL JDQLC
RET
;按键判断
AJPD:
JNB S4,AJ1
JNB S5,AJ2
RET
AJ1: JNB S4,$
MOV ZT,#2
CALL JDQLC_START
RET
AJ2: CALL JDQLC_STOP
SETB LED1
SETB LED2
JNB S5,$
MOV ZT,#1
MOV JSBZ1,#0
U16MOV JSBZ2,0
RET
JDQLC_START:
U16MOV JSBZ3,0
RET
JDQLC_STOP:
U16MOV JSBZ3,30000
SETB JDQ
RET
;继电器通断两次
JDQLC:
U16DAYV JSBZ3,1000
JNC JDQ_1
CLR JDQ ;通1s
RET
JDQ_1: U16DAYV JSBZ3,1500
JNC JDQ_2
SETB JDQ ;断0.5s
RET
JDQ_2: U16DAYV JSBZ3,1500+1000
JNC JDQ_3
CLR JDQ ;通1s
RET
JDQ_3: U16DAYV JSBZ3,3000
JNC JDQ_4
SETB JDQ ;断
JDQ_4: RET
;;定时器初始化
Time0Init:
MOV TMOD,#0X01
MOV TH0,#HIGH(65536-1000)
MOV TL0,#LOW(65536-1000)
SETB TR0
SETB ET0
SETB EA
RET
;;数码显示
SMXS:
INC SMGBZ1
MOV A,SMGBZ1
SUBB A,#4
JC SMXS1
MOV SMGBZ1,#0
SMXS1:
MOV P2,#0XF0
MOV A,SMGBZ1
ADD A,#DS1
MOV R0,A
MOV A,@R0
MOV DPTR,#TABD
MOVC A,@A+DPTR
MOV P0,A
MOV DPTR,#TABW
MOV A,SMGBZ1
MOVC A,@A+DPTR
MOV P2,A
RET
TABD:;段码
DB 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90
DB 0X88,0X83,0XC6,0XA1,0X86,0X8E,0XFF,0XBF
TABW:;位码
DB 0xF1,0xF2,0xF4,0xF8
;;定时器0中断
TimeInterupt:
PUSH PSW
PUSH ACC
MOV TH0,#HIGH(65536-1000)
MOV TL0,#LOW(65536-1000)
CALL SMXS
U16INC JSBZ2
U16DAYV JSBZ3,30000
JNC TimeOut
U16INC JSBZ3
TimeOut:
POP ACC
POP PSW
RETI
END