6位共阴数码管,可作时钟也可作秒表(估计没人用这么多位的秒表哟)
时、分和秒可分别调整,有开始、暂停和清零键。
程序清单: ;12M晶振 2010 01 14 调试完成 03 15 修改 2011 03 03 注释 STRT EQU P2.6
STP EQU P2.7
CLRR EQU P3.0
SEC EQU P3.5
MIN EQU P3.6
HOUR EQU P3.7 ORG 00H
SJMP MAIN
ORG 0BH
AJMP T0INT0
ORG 30H MAIN: MOV SP,#60H
MOV R4,#20
MOV TMOD,#01H
MOV TH0,#03CH ;#9EH 12M晶振时定时初值取#3CB0H,还可细调,如 TL=#0B7H,可以更准
MOV TL0,#0B0H ;#58H
SETB ET0
SETB EA
;MOV 28H,#12 kS: LCALL DISP ;秒调整按键
JB SEC,KM
LCALL DISP
JNB SEC,$-3
AJMP SINC kM: JB MIN,KH ;分调整按键
LCALL DISP
JNB MIN,$-3
AJMP MINC KH: JB HOUR,K1 ;时调整按键
LCALL DISP
JNB HOUR,$-3
AJMP HINC SINC: INC 26H ;秒调整
MOV A,26H
CJNE A,#60,SINC0
MOV 26H,#0
SINC0: AJMP KS MINC: INC 27H ;分调整
MOV A,27H
CJNE A,#60,MINC0
MOV 27H,#0
MINC0: AJMP KM HINC: INC 28H ;时调整
MOV A,28H
CJNE A,#24,HINC0
MOV 28H,#0
HINC0: AJMP KH
k1: LCALL DISP ;开始键
JB STRT,K2
LCALL DISP
JNB STRT,$-3
AJMP START k2: JB STP,K3 ;暂停键
LCALL DISP
JNB STP,STOP
K3: JB CLRR,KS
LCALL DISP
JNB CLRR,CLEAR ;清零键
AJMP KS START: SETB TR0 ;开始
AJMP K1
STOP: CLR TR0 ;暂停
AJMP K2 CLEAR: CLR TR0 ;清零
MOV A,#0
MOV 26H,A
MOV 27H,A
MOV 28H,A
AJMP KS DISP:
MOV A,26H
MOV B,#10
DIV AB
MOV 20H,B ;余数(秒个位数)
MOV 21H,A ;商(秒十位数)
MOV A,27H
MOV B,#10
DIV AB
MOV 22H,B ;余数(分个位数)
MOV 23H,A ;商(分十位数)
MOV A,28H
MOV B,#10
DIV AB
MOV 24H,B ;余数(时个位数)
MOV 25H,A ;商(时十位数)
MOV A,20H ;秒个位
ACALL SEG7
MOV P0,A
CLR P2.0
ACALL DLY
SETB P2.0
MOV A,21H ;秒十位
ACALL SEG7
MOV P0,A
CLR P2.1
ACALL DLY
SETB P2.1
MOV A,22H ;分个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.2
ACALL DLY
SETB P2.2
MOV A,23H ;分十位
ACALL SEG7
MOV P0,A
CLR P2.3
ACALL DLY
SETB P2.3
MOV A,24H ;时个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.4
ACALL DLY
SETB P2.4
MOV A,25H ;时十位
ACALL SEG7
MOV P0,A
CLR P2.5
ACALL DLY
SETB P2.5
RET
T0INT0: MOV TH0,#03CH;#9EH ;定时中断子程序。重装定时常数
MOV TL0,#0B0H;#58H
DJNZ R4,T0INTR ;50msX20=1S,未满20次,跳出中断子程序
MOV R4,#20
INC 26H ;1S,秒存储单元内数+1
MOV A,26H
CJNE A,#60,T0INTR ;未满60S,跳出中断。
MOV 26H,#0 ;满60S,秒单元清零
INC 27H ;分+1
MOV A,27H
CJNE A,#60,T0INTR
MOV 27H,#0
INC 28H
MOV A,28H
CJNE A,#24,T0INTR
MOV 28H,#0
T0INTR: RETI
DLY10: MOV R3,#30
D0: ACALL DLY
DJNZ R3,D0
RET
DLY: MOV R7,#2
D1: MOV R6,#40
DJNZ R6,$
DJNZ R7,D1
RET SEG7: INC A
MOVC A,@A+PC
RET DB 03FH ;0 共阴
DB 006H ;1
DB 05BH ;2
DB 04FH ;3
DB 066H ;4
DB 06DH ;5
DB 07DH ;6
DB 007H ;7
DB 07FH ;8
DB 06FH ;9 END
;2011 11 25 更新。加上闹铃 ,按键功能稍作改动 E:\DPJ\CLOCK\CLOCK-MX\CLOCKADJCC-MX.ASM STRT EQU P2.6
STP EQU P2.7
CLRR EQU P3.0
SEC EQU P3.5
MIN EQU P3.6
HOUR EQU P3.7 ORG 00H
AJMP MAIN
ORG 0BH
AJMP T0INT
ORG 1BH
AJMP T1INT
ORG 30H MAIN:
MOV SP,#60H
MOV R4,#20
MOV TMOD,#11H
MOV TH0,#03CH;#9EH 12M晶振时定时初值取#3CB0H,还可细调如 TL=#0B7H,可以更准
MOV TL0,#0B0H;#58H
MOV TH1,#0FEH
MOV TL1,#0CH
SETB EA
SETB ET0
SETB ET1 kS:
ACALL DISP
ACALL ALARM JB SEC,KM ;秒调整按键
ACALL DISP
JNB SEC,$-2
AJMP SINC kM:
JB MIN,KH ;分调整按键
ACALL DISP
JNB MIN,$-2
AJMP MINC KH:
JB HOUR,K1 ;时调整按键
ACALL DISP
JNB HOUR,$-2
AJMP HINC SINC:
JB 7FH,SINC_A
INC 26H ;秒调整
MOV A,26H
CJNE A,#60,SINC0
MOV 26H,#0
AJMP SINC0
SINC_A:
INC 36H ;闹秒调整
MOV A,36H
CJNE A,#60,SINC0
MOV 36H,#0
SINC0: AJMP KS MINC:
JB 7FH,MINC_A
INC 27H ;分调整
MOV A,27H
CJNE A,#60,MINC0
MOV 27H,#0
MINC_A:
INC 37H ;闹分调整
MOV A,37H
CJNE A,#60,MINC0
MOV 37H,#0
MINC0:
AJMP KM HINC:
JB 7FH,HINC_A
INC 28H ;时调整
MOV A,28H
CJNE A,#24,HINC0
MOV 28H,#0
HINC_A:
INC 38H ;闹时调整
MOV A,38H
CJNE A,#24,HINC0
MOV 38H,#0
HINC0:
AJMP KH
k1:
ACALL DISP ;开始键
JB STRT,K2
ACALL DISP
JNB STRT,$-2
AJMP START k2:
JB STP,K3 ;暂停键
ACALL DISP
JNB STP,$-2
AJMP CL_AL
K3:
JB CLRR,KS0
ACALL DISP
JNB CLRR,CLEAR ;清零键
KS0:
AJMP KS START:
CPL TR0 ;开始/暂停
CPL 7DH ;7DH为开始键按下标志,此作为允许闹铃标志
AJMP K1
CL_AL:
CPL 7FH ;7FH作时钟和闹铃标志位?
AJMP K2 CLEAR:
CLR TR0 ;清零
MOV A,#0
MOV 26H,A
MOV 27H,A
MOV 28H,A
MOV 36H,A
MOV 37H,A
MOV 38H,A
AJMP KS DISP:
JB 7FH,DISP_A
MOV 29H,26H ;秒送秒显示缓存
MOV 2AH,27H
MOV 2BH,28H
AJMP DISP1
DISP_A:
MOV 29H,36H
MOV 2AH,37H
MOV 2BH,38H
DISP1:
MOV A,29H
MOV B,#10
DIV AB
MOV 20H,B ;余数(秒个位数)
MOV 21H,A ;商(秒十位数)
MOV A,2AH
MOV B,#10
DIV AB
MOV 22H,B ;余数(分个位数)
MOV 23H,A ;商(分十位数)
MOV A,2BH
MOV B,#10
DIV AB
MOV 24H,B ;余数(时个位数)
MOV 25H,A ;商(时十位数)
MOV A,20H ;秒个位
ACALL SEG7
MOV P0,A
CLR P2.0
ACALL DLY
SETB P2.0
MOV A,21H ;秒十位
ACALL SEG7
MOV P0,A
CLR P2.1
ACALL DLY
SETB P2.1
MOV A,22H ;分个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.2
ACALL DLY
SETB P2.2
MOV A,23H ;分十位
ACALL SEG7
MOV P0,A
CLR P2.3
ACALL DLY
SETB P2.3
MOV A,24H ;时个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.4
ACALL DLY
SETB P2.4
MOV A,25H ;时十位
ACALL SEG7
MOV P0,A
CLR P2.5
ACALL DLY
SETB P2.5
RET
ALARM:
JNB 7DH,ALRT
MOV A,28H ;比较小时
CJNE A,38H,RT ;不等返回。 相等,转分钟比较
MOV A,27H ;比较分钟
CJNE A,37H,RT
MOV A,26H ;比较秒
CJNE A,36H,RT
SETB TR1
MOV R0,#0 ;闹铃时间到,闹铃计时清零
ALRT:
RET RT:
RET T0INT: MOV TH0,#03CH;#9EH ;定时中断子程序。重装定时常数
MOV TL0,#0B0H #58H
DJNZ R4,T0INTR ;50msX20=1S,未满20次,跳出中断子程序
MOV R4,#20
INC 26H ;1S,秒存储单元内数+1
INC R0 ;响铃时间
MOV A,26H
CJNE A,#60,T0INTR ;未满60S,跳出中断。
MOV 26H,#0 ;满60S,秒单元清零
INC 27H ;分+1
MOV A,27H
CJNE A,#60,T0INTR
MOV 27H,#0
INC 28H
MOV A,28H
CJNE A,#24,T0INTR
MOV 28H,#0
T0INTR:
RETI T1INT:
MOV TH1,#0FEH
MOV TL1,#0CH
CPL P1.0
CJNE R0,#5,T1RTI ;闹铃时间设为5秒
CLR TR1 ;关闹铃
T1RTI:
RETI DLY:
MOV R7,#20
MOV R6,#25
DJNZ R6,$
DJNZ R7,$-4
RET
SEG7:
INC A
MOVC A,@A+PC
RET
DB 03FH ;0 共阴
DB 006H ;1
DB 05BH ;2
DB 04FH ;3
DB 066H ;4
DB 06DH ;5
DB 07DH ;6
DB 007H ;7
DB 07FH ;8
DB 06FH ;9 END
;12M晶振 2010 01 14 调试完成 3.15 修改 2011 03 03 注释
;2011 11 25 加上闹铃 E:\DPJ\CLOCK\CLOCK-MX\CLOCKADJCC-MX.ASM
;2011 12 03 加上整点提醒,响1S 闹铃响3 S E:\DPJ\CLOCK\CLOCK-定时整点\CLOCKADJCC-ZDNL.ASM
STRT EQU P2.6
STP EQU P2.7
CLRR EQU P3.0
SEC EQU P3.5
MIN EQU P3.6
HOUR EQU P3.7
ORG 00H
AJMP MAIN
ORG 0BH
AJMP T0INT
ORG 1BH
AJMP T1INT
ORG 30H MAIN:
MOV SP,#60H
MOV R4,#20
MOV TMOD,#11H
MOV TH0,#03CH;#9EH 12M晶振时定时初值取#3CB0H,还可细调如 TL=#0B7H,可以更准
MOV TL0,#0B0H;#58H
MOV TH1,#0FEH
MOV TL1,#0CH
SETB EA
SETB ET0
SETB ET1 kS:
ACALL DISP
ACALL ALARM JB SEC,KM ;秒调整按键
ACALL DISP
JNB SEC,$-2
AJMP SINC kM:
JB MIN,KH ;分调整按键
ACALL DISP
JNB MIN,$-2
AJMP MINC KH:
JB HOUR,K1 ;时调整按键
ACALL DISP
JNB HOUR,$-2
AJMP HINC SINC:
JB 7FH,SINC_A
INC 26H ;秒调整
MOV A,26H
CJNE A,#60,SINC0
MOV 26H,#0
AJMP SINC0
SINC_A:
INC 36H ;闹秒调整
MOV A,36H
CJNE A,#60,SINC0
MOV 36H,#0
SINC0: AJMP KS MINC:
JB 7FH,MINC_A
INC 27H ;分调整
MOV A,27H
CJNE A,#60,MINC0
MOV 27H,#0
MINC_A:
INC 37H ;闹分调整
MOV A,37H
CJNE A,#60,MINC0
MOV 37H,#0
MINC0:
AJMP KM HINC:
JB 7FH,HINC_A
INC 28H ;时调整
MOV A,28H
CJNE A,#24,HINC0
MOV 28H,#0
HINC_A:
INC 38H ;闹时调整
MOV A,38H
CJNE A,#24,HINC0
MOV 38H,#0
HINC0:
AJMP KH
k1:
ACALL DISP ;开始键
JB STRT,K2
ACALL DISP
JNB STRT,$-2
AJMP START k2:
JB STP,K3 ;暂停键
ACALL DISP
JNB STP,$-2
AJMP CL_AL
K3:
JB CLRR,KS0
ACALL DISP
JNB CLRR,CLEAR ;清零键
KS0:
AJMP KS START:
CPL TR0 ;开始/暂停
SETB 7DH ;7DH为开始键按下标志,此作为允许闹铃标志
AJMP K1
CL_AL:
CPL 7FH ;7FH作时钟和闹铃标志位
AJMP K2 CLEAR:
CLR TR0 ;清零
MOV A,#0
MOV 26H,A
MOV 27H,A
MOV 28H,A
MOV 36H,A
MOV 37H,A
MOV 38H,A
AJMP KS DISP:
JB 7FH,DISP_A
MOV 29H,26H ;秒送秒显示缓存
MOV 2AH,27H
MOV 2BH,28H
AJMP DISP1
DISP_A:
MOV 29H,36H
MOV 2AH,37H
MOV 2BH,38H
DISP1:
MOV A,29H
MOV B,#10
DIV AB
MOV 20H,B ;余数(秒个位数)
MOV 21H,A ;商(秒十位数)
MOV A,2AH
MOV B,#10
DIV AB
MOV 22H,B ;余数(分个位数)
MOV 23H,A ;商(分十位数)
MOV A,2BH
MOV B,#10
DIV AB
MOV 24H,B ;余数(时个位数)
MOV 25H,A ;商(时十位数)
MOV A,20H ;秒个位
ACALL SEG7
MOV P0,A
CLR P2.0
ACALL DLY
SETB P2.0
MOV A,21H ;秒十位
ACALL SEG7
MOV P0,A
CLR P2.1
ACALL DLY
SETB P2.1
MOV A,22H ;分个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.2
ACALL DLY
SETB P2.2
MOV A,23H ;分十位
ACALL SEG7
MOV P0,A
CLR P2.3
ACALL DLY
SETB P2.3
MOV A,24H ;时个位
ACALL SEG7
MOV P0,A
SETB P0.7
CLR P2.4
ACALL DLY
SETB P2.4
MOV A,25H ;时十位
ACALL SEG7
MOV P0,A
CLR P2.5
ACALL DLY
SETB P2.5
RET
ALARM:
JNB 7DH,RT ;开始键未按下跳出
MOV A,28H ;开机时,时分秒都 为0,跳出
JZ AL0M
AJMP ALARM1
AL0M:
MOV A,27H
JZ AL0S
AJMP ALARM1
AL0S:
MOV A,26H
JZ RT
ALARM1:
MOV A,28H ;比较小时
CJNE A,38H,AL ;不等返回,相等,转分钟比较
MOV A,27H ;比较分钟?
CJNE A,37H,AL
MOV A,26H ;比较秒
CJNE A,36H,AL
AJMP ALARM2 ;转闹铃 AL: ;整点提醒
MOV A,28H
JZ RT ;小时不是00,判分是不是00
MOV A,27H
JNZ RT ;分不是00,跳出
MOV A,26H
JNZ RT
AJMP ALARM3 ;秒不为00,跳出。为00,整点提醒
ALARM2: ;闹铃3 S
SETB TR1
MOV R0,#0
AJMP RT
ALARM3: ;整点提醒1S
SETB TR1
MOV R0,#2
RT:
RET T0INT:
MOV TH0,#03CH;定时中断子程序。重装定时常数
MOV TL0,#0B0H
DJNZ R4,T0INTR ;50msX20=1S,未满20次,跳出中断子程序
MOV R4,#20
INC 26H ;1S,秒存储单元内数+1
INC R0 ;响铃时间
MOV A,26H
CJNE A,#60,T0INTR ;未满60S,跳出中断。
MOV 26H,#0 ;满60S,秒单元清零
INC 27H ;分+1
MOV A,27H
CJNE A,#60,T0INTR
MOV 27H,#0
INC 28H
MOV A,28H
CJNE A,#24,T0INTR
MOV 28H,#0
T0INTR:
RETI T1INT:
MOV TH1,#0FEH
MOV TL1,#0CH
CPL P1.0
CJNE R0,#3,T1RTI ;闹铃时间设为5秒
CLR TR1 ;关闹铃
T1RTI:
RETI DLY:
MOV R7,#20
MOV R6,#25
DJNZ R6,$
DJNZ R7,$-4
RET
SEG7:
INC A
MOVC A,@A+PC
RET
DB 03FH ;0 共阴
DB 006H ;1
DB 05BH ;2
DB 04FH ;3
DB 066H ;4
DB 06DH ;5
DB 07DH ;6
DB 007H ;7
DB 07FH ;8
DB 06FH ;9 END
|