多功能电子表
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
T2CON EQU 0C8H
TR2 BIT T2CON.2
TF2 BIT T2CON.7
EXF2 BIT T2CON.6
T2MOD EQU 0C9H
RCAP2L EQU 0CAH
RCAP2H EQU 0CBH
TL2 EQU 0CCH
TH2 EQU 0CDH
ET2 BIT IE.5
;时间日期部分单独用内存空间,尽量不要和其他程序交集
;所有标志位初始化为0
;常用数据及端口自定义
DAT0 EQU P0
DAT1 EQU P1
DAT2 EQU P2
DAT3 EQU P3
RS BIT P3.0
RW BIT P3.1
EN BIT P3.2
TTL0 DATA 10H; 约46MS
TTH0 DATA 4CH
TT0 DATA 14H
TTL2 DATA 0B0H;50ms
TTH2 DATA 03CH
TT2 DATA 3H
TTL1 DATA 0F0H;10ms
TTH1 DATA 0D8H
CLOCKTIME DATA 1
;以用的内存单元
;1DH,1EH,1FH
;3AH-3FH
;40H-47H
;
;
;20H.0,20H.1,20H.2,20H.3,20H.4,20H.5
;D0H用于堆栈
;程序开始
ORG 0000H
SJMP CHUSHI0
ORG 000BH
AJMP TIMER0
ORG 001BH
LJMP TIMER1
ORG 002BH
AJMP TIMER2
;初始化,包括液晶,堆栈,以及时间,标志位
ORG 0030H
CHUSHI0:
MOV SP,#0CFH
MOV 1DH,#57 ;秒
MOV 1EH,#59 ;分
MOV 1FH,#23 ;时
MOV 3BH,#0
MOV 3CH,#28
MOV 3DH,#2
MOV 3EH,#04
MOV 3FH,#20
MOV 45H,#0
MOV 46H,#0
MOV 47H,#0
;初始化标志位
MOV 20H,#0
MOV 21H,#0
;初始化液晶
ACALL DELAY5MS
ACALL DELAY5MS
ACALL DELAY5MS
MOV A,#38H
ACALL I_SEND
ACALL DELAY5MS
MOV A,#38H
ACALL I_SEND
ACALL DELAY5MS
MOV A,#38H
ACALL I_SEND
ACALL DELAY5MS
MOV A,#38H
ACALL I_SEND
MOV A,#08H
ACALL I_SEND
MOV A,#01H
ACALL I_SEND
MOV A,#06H
ACALL I_SEND
MOV A,#0CH
ACALL I_SEND
;开始显示
ACALL DISP0
ACALL DISP1
;打开定时计数器0
CHUSHI01:
MOV 3AH,#TT0
MOV TL0,#TTL0
MOV TH0,#TTH0
MOV TMOD,#11H
SETB ET0
SETB EA
SETB TR0
SETB ET2
SETB ET1
;主程序0
;电子表正常显示时间日期
;按键0进入下一状态
;闹铃判断
MAIN0:
JNB 20H.0,MAIN00 ;日期没变化的话不改变显示日期
MOV A,#01H
ACALL I_SEND
ACALL DISP0
CLR 20H.0
MAIN00:
ACALL DISP1
CLR 20H.1
;判断闹铃标志位时候开
JNB 21H.0,MAIN01
ACALL CLOCK
MAIN01:
JB 20H.1,MAIN0
MAIN02:;短按键0
JB DAT1.0,MAIN01;判断是否按键0
CLR 21H.1;关闭延时闹铃持续标志,防止R6被改变后程序错误
ACALL DELAY5MS
JNB DAT1.0,$
ACALL DELAY5MS
AJMP MAIN1;转跳主程序1
;闰年判断函数
RUNNIAN0:
MOV A,3EH
CJNE A,#0,RUNNIAN00
MOV A,3FH
RUNNIAN00:
MOV B,#4
DIV AB
MOV A,B
CLR 20H.4;非闰年为0
JNZ RUNNIAN01
SETB 20H.4;闰年为1
RUNNIAN01:
RET
;液晶屏写入指令及数据子程序(包括查忙)
DELAY5MS: ;30H,31H
MOV 40H,#50
DEL0: MOV 41H,#100
DJNZ 41H,$
DJNZ 40H,DEL0
RET
I_SEND:
ACALL BUSY
CLR RS
CLR RW
SETB EN
MOV DAT0,A
CLR EN
RET
D_SEND:
ACALL BUSY
SETB RS
CLR RW
SETB EN
MOV DAT0,A
CLR EN
RET
BUSY:
MOV DAT0,#0FFH
CLR RS
SETB RW
CLR EN
SETB EN
JB DAT0.7,BUSY
CLR EN
RET
;显示两位数
DISP:
MOV B,#10
DIV AB
ADD A,#30H
ACALL D_SEND
XCH A,B
ADD A,#30H
ACALL D_SEND
RET
;显示日
期
DISP0:
MOV A,#81H
ACALL I_SEND
MOV A,3FH
ACALL DISP
MOV A,3EH
ACALL DISP
MOV A,#2DH
ACALL D_SEND
MOV A,3DH
ACALL DISP
MOV A,#2DH
ACALL D_SEND
MOV A,3CH
ACALL DISP
MOV A,#20H
ACALL D_SEND
MOV A,3BH
MOV B,#3
MUL AB
MOV 42H,#4 ;42H显示星期计数
WEEK00:
DJNZ 42H,WEEK01
RET
WEEK01:
PUSH ACC
MOV DPTR,#TABLE0
MOVC A,@A+DPTR
ACALL D_SEND
POP ACC
INC A
SJMP WEEK00
TABLE0:DB 53H,55H,4EH,4DH,4FH,4EH,54H,55H,45H,57H,45H,44H,54H,48H,55H,46H,52H,49H,53H,41H,54H
;显示时间
DISP1:
MOV A,#0C4H
ACALL I_SEND
MOV A,1FH
ACALL DISP
MOV A,#3AH
ACALL D_SEND
MOV A,1EH
ACALL DISP
MOV A,#3AH
ACALL D_SEND
MOV A,1DH
ACALL DISP
RET
;定时计数器0中断服务函数
;包含秒分时,日期,标志位
TIMER0:
MOV TL0,#TTL0
MOV TH0,#TTH0
DJNZ 3AH,TIMER00;跳出
MOV 3AH,#TT0
SETB 20H.1;秒变化标志
PUSH ACC
PUSH PSW
PUSH DPL
PUSH DPH
SETB PSW.3
SETB PSW.4
INC R5
CJNE R5,#60,TIMER01
MOV R5,#0
SETB 20H.2;分钟变化标志
INC R6
CJNE R6,#60,TIMER01
MOV R6,#0
SETB 20H.3;整点变化标志
INC R7
CJNE R7,#24,TIMER01
MOV R7,#0
SETB 20H.0;日期变化标志
MOV R0,#3BH
INC @R0
CJNE @R0,#7,TIMER02
MOV @R0,#0
TIMER02:
INC R0
INC @R0
ACALL RUNNIAN0;判断闰年
MOV DPTR,#TABLE1;非闰年
JNB 20H.4,TIMER03
MOV DPTR,#TABLE2
TIMER03:
MOV A,3DH
MOVC A,@A+DPTR
MOV R4,A
INC R4;本月最大天数加1
MOV A,@R0
CJNE A,1CH,TIMER01
MOV @R0,#1
INC R0
INC @R0
CJNE @R0,#13,TIMER01
MOV @R0,#1
INC R0
INC @R0
CJNE @R0,#100,TIMER01
MOV @R0,#0
INC R0
INC @R0
CJNE @R0,#100,TIMER01
MOV @R0,#0
TIMER01:
POP DPH
POP DPL
POP PSW
POP ACC
TIMER00:
RETI
TABLE1:DB 0,31,28,31,30,31,30,31,31,30,31,30,31
TABLE2:DB 0,31,29,31,30,31,30,31,31,30,31,30,31
TABLE3:DB 32,32,84,73,77,69,32,83,69,84,84,73,78,71,32,32; TIME SETTING
TABLE4:DB 32,32,68,65,84,65,32,83,69,84,84,73,78,71,32,32; DATA SETTING
TABLE5:DB 32,67,76,79,67,75,32,83,69,84,84,73,78,71,49,32; CLOCK SETTING1
TABLE6:DB 32,32,32,32,83,84,79,80,87,65,84,67,72,32,32,32;STOPWATCH
TABLE7:DB 32,67,76,79,67,75,32,83,69,84,84,73,78,71,50,32; CLOCK SETTING2
TABLE8:DB 32,32,32,32,32,32,67,76,79,67,75,32,32,32,32,32;CLOCK
;显示一行文字,A预置显示位置DPTR预置显示的内容
DISPX:
ACALL I_SEND
MOV 42H,#17
DISPX01:
DJNZ 42H,DISPX00
RET
DISPX00:
MOV A,#0
MOVC A,@A+DPTR
ACALL D_SEND
INC DPTR
SJMP DISPX01
;主程序1
;主要是实现时间的调时功能
MAIN1:
MOV A,#01H ;显示TIME SETTING
ACALL I_SEND
MOV DPTR,#TABLE3
MOV A,#80H
ACALL DISPX
CLR 20H.7 ;为1时标志闹铃设置
;判断按键0
MAIN10: JB DAT1.0,MAIN11
ACALL DELAY5MS
;判断按键时间
CLR 20H.5
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10;按键延时0.5S为长
SETB TR2
JNB DAT1.0,$
ACALL DELAY5MS
JNB 20H.5,AAZMAIN2
;长按键0 跳回MAIN0
CLR 20H.5
SETB 20H.0;改变标志位,显示日期
AJMP MAIN0
AAZMAIN2:
JNB 20H.7,ZMAIN2
AJMP MAIN4;闹铃设置的下一个功能
ZMAIN2: AJMP MAIN2;JNB跳256,不够
;判断按键3
MAIN11: JB DAT1.3,MAIN10
ACALL DELAY5MS
JNB DAT1.3,$
ACALL DELAY5MS
;准备开始调时,复制时间信息并且效验
MAIN12:
JB 20H.7,AAMAIN12
CLR 20H.1
MOV R5,1DH
MOV R6,1EH
MOV R7,1FH
JB 20H.1,MAIN12;效验是否复制出错
SJMP MAIN120
;开始闪烁
AAMAIN12:
MOV R5,45H
MOV R6,46H
MOV R7,47H
MAIN120:
MOV R0,#07H
;CLR 20H.5;可以省略,前面有
CLR 20H.6;为1 R0地址不显示
MAIN14: MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10;延时0.5S为长
SETB TR2
ACALL DISP2;跟DISP1类似,可以精简为一个
MAIN15: JB 20H.5,MAIN13;0.5S到了
JNB 20H.6,MAIN16;跳向下一个按键判断
;闪烁
MOV A,R0
MOV B,#3
MUL AB
MOV B,A
MOV A,#0D9H
SUBB A,B
ACALL I_SEND
MOV A,#32
ACALL D_SEND
MOV A,#32
ACALL D_SEND
SJMP MAIN15
MAIN13:;改变标志位
CPL 20H.6
CLR 20H.5
SJMP MAIN14
;判断按键0,位选/返回主程序
MAIN16:
JB DAT1.0,MAIN17
ACALL DELAY5MS
CLR TR2
ACALL DISP2
CLR 20H.5
CLR 20H.6
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10;延时0.5S为长
SETB TR2
JNB DAT1.0,$
CLR TR2
ACALL DELAY5MS
JB 20H.5,MAIN160
DEC R0
CJNE R0,#4,MAIN14
MOV R0,#7
SJMP MAIN14
MAIN160: ;跳回主程序0
SETB 20H.0
AJMP MAIN0
;判断按键1,加1
MAIN17:
JB DAT1.1,MAIN18
ACALL DELAY5MS
MOV 43H,#10
MAIN173:
CLR 20H.5
CLR 20H.6
MOV TL2,#TTL2
MOV TH2,#TTH2
SETB TR2
INC @R0
CJNE R0,#7,MAIN170
CJNE @R0,#24,MAIN171
MOV @R0,#0
SJMP MAIN171
MAIN170:
CJNE @R0,#60,MAIN171
MOV @R0,#0
MAIN171:
ACALL DISP2
JNB 20H.5,MAIN172
MOV 43H,#TT2;其余操作在MAIN172
SJMP MAIN173
MAIN172:
JNB DAT1.1,MAIN171
ACALL DELAY5MS
AJMP MAIN14
;判断按键2,减1
MAIN18:
JB DAT1.2,MAIN19
ACALL DELAY5MS
MOV 43H,#10
MAIN183:
CLR 20H.5
CLR 20H.6
MOV TL2,#TTL2
MOV TH2,#TTH2
SETB TR2
DEC @R0
CJNE R0,#7,MAIN180
CJNE @R0,#255,MAIN181
MOV @R0,#23
SJMP MAIN181
MAIN180:
CJNE @R0,#255,MAIN181
MOV @R0,#59
MAIN181:
ACALL DISP2
JNB 20H.5,MAIN182
MOV 43H,#TT2;其余操作在MAIN182
SJMP MAIN183
MAIN182:
JNB DAT1.2,MAIN181
ACALL DELAY5MS
AJMP MAIN14
;判断按键3,确定
MAIN19:
JB DAT1.3,ZMAIN15
ACALL DELAY5MS
JNB DAT1.3,$
ACALL DELAY5MS
JB 20H.7,AAMAIN19
CLR TR0
MOV 1FH,07H
MOV 1EH,06H
MOV 1DH,05H
SETB 20H.0
AJMP CHUSHI01;保存返回
AAMAIN19:
MOV 45H,07H
MOV 46H,06H
MOV 47H,07H
AJMP MAIN30
ZMAIN15:
AJMP MAIN15
TIMER2:;每次中断完成后需重新打开中断
CLR TF2;关闭溢出标志位
MOV TL2,#TTL2
MOV TH2,#TTH2
DJNZ 43H,TIMER20
SETB 20H.5
CLR TR2
TIMER20:RETI
DISP2:
MOV A,#0C4H
ACALL I_SEND
MOV A,07H
ACALL DISP
MOV A,#3AH
ACALL D_SEND
MOV A,06H
ACALL DISP
MOV A,#3AH
ACALL D_SEND
MOV A,05H
ACALL DISP
RET
;短按键0 进入MAIN2
MAIN2:
MOV A,#01H
;显示DATA SETTING
ACALL I_SEND
MOV DPTR,#TABLE4
MOV A,#80H
ACALL DISPX
;判断按键0
MAIN20: JB DAT1.0,MAIN21
ACALL DELAY5MS
;判断按键时间
CLR 20H.5
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10;按键延时0.5S为长
SETB TR2
JNB DAT1.0,$
ACALL DELAY5MS
JNB 20H.5,ZMAIN3
;长按键0 跳回MAIN0
CLR 20H.5
SETB 20H.0;改变标志位,显示日期
AJMP MAIN0
ZMAIN3: AJMP MAIN3;JNB跳256,不够
;判断按键4
MAIN21:
JB DAT1.3,MAIN20
ACALL DELAY5MS
JNB DAT1.3,$
ACALL DELAY5MS
;准备开始调日期,复制时间信息并且效验
MAIN22:
CLR 20H.0
MOV R4,3CH
MOV R5,3DH
MOV R6,3EH
MOV R7,3FH
MOV 44H,3BH
JB 20H.0,MAIN22;效验是否复制出错
;开始闪烁
MOV R0,#06H
CLR 20H.5
CLR 20H.6
MAIN23:
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10
SETB TR2
ACALL DISP3;显示日期
MAIN24:
JB 20H.5,MAIN25;0.5S到了
JNB 20H.6,MAIN26;跳向下一个按键判断
;闪烁年补偿
CJNE R0,#6,MAIN240
MOV A,#0C1H
ACALL I_SEND
MOV A,#32
ACALL D_SEND
MOV A,#32
ACALL D_SEND
MAIN240:
MOV A,R0
MOV B,#3
MUL AB
MOV B,A
MOV A,#0D5H
SUBB A,B
ACALL I_SEND
MOV A,#32
ACALL D_SEND
MOV A,#32
ACALL D_SEND
SJMP MAIN24
;0.5秒改变标志位20H.6
MAIN25:
CPL 20H.6
CLR 20H.5
SJMP MAIN23
;判断按键0,位选/返回主程序
MAIN26: JB DAT1.0,MAIN27
ACALL DELAY5MS
CLR TR2
ACALL DISP3
CLR 20H.5
CLR 20H.6
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10;延时0.5S为长
SETB TR2
JNB DAT1.0,$
CLR TR2
ACALL DELAY5MS
JB 20H.5,MAIN260
DEC R0
CJNE R0,#3,MAIN23
MOV R0,#6
SJMP MAIN23
MAIN260: ;跳回主程序0
SETB 20H.0
AJMP MAIN0
;判断按键1,加1
MAIN27:
JB DAT1.1,MAIN28
ACALL DELAY5MS
MOV 43H,#10
MAIN276:
CLR 20H.5
CLR 20H.6
MOV TL2,#TTL2
MOV TH2,#TTH2
INC @R0
;年修正
CJNE R6,#100,MAIN270
MOV R6,#1
INC R7
MAIN270:
;月修正
CJNE R5,#13,MAIN271
MOV R5,#1
MAIN271:
;日修正
ACALL RUNNIAN1
MOV A,R5
MOVC A,@A+DPTR
CJNE A,04H,MAIN272
MAIN272:
;判断A>=@04H,Cy=0
JNC MAIN273
MOV R4,#1
MAIN273:
;修正星期
ACALL WEEKXIU
ACALL DISP3
SETB TR2
MAIN274:
JNB 20H.5,MAIN275
MOV 43H,#TT2
AJMP MAIN276
MAIN275:
JNB DAT1.1,MAIN274
ACALL DELAY5MS
AJMP MAIN23
;判断按键2
MAIN28:
JB DAT1.2,MAIN29
ACALL DELAY5MS
MOV 43H,#10
MAIN286:
CLR 20H.5
CLR 20H.6
MOV TL2,#TTL2
MOV TH2,#TTH2
DEC @R0
;年修正
CJNE R6,#0,MAIN280
MOV R6,#99
DEC R7
MAIN280:
;月修正
CJNE R5,#0,MAIN281
MOV R5,#12
MAIN281:
;日修正1,天数多了
ACALL RUNNIAN1
MOV A,R5
MOVC A,@A+DPTR
CJNE A,04H,MAIN282
MAIN282:
;判断A>=@04H,Cy=0
JNC MAIN287
MOV R4,#1
MAIN287:;日修正2,天数少了
CJNE R4,#0,MAIN283
MOV A,R5
MOVC A,@A+DPTR
MOV R4,A
MAIN283:
;修正星期
ACALL WEEKXIU
ACALL DISP3
SETB TR2
MAIN284:
JNB 20H.5,MAIN285
MOV 43H,#TT2
AJMP MAIN286
MAIN285:
JNB DAT1.2,MAIN284
ACALL DELAY5MS
AJMP MAIN23
;判断按键3
MAIN29:
JB DAT1.3,ZMAIN24
ACALL DELAY5MS
MAIN290:
CLR 20H.0
MOV 3BH,44H
MOV 3CH,04H
MOV 3DH,05H
MOV 3EH,06H
MOV 3FH,07H
JB 20H.0,MAIN290
SETB 20H.0
JNB DAT1.3,$
ACALL DELAY5MS
AJMP MAIN0
ZMAIN24:AJMP MAIN24
;闰年判断函数
RUNNIAN1:
MOV A,R6
CJNE R6,#0,RUNNIAN10
MOV A,R7
RUNNIAN10:
MOV B,#4
DIV AB
MOV A,B
MOV DPTR,#TABLE1
JNZ RUNNIAN11
MOV DPTR,#TABLE2
RUNNIAN11:
RET
;星期修正
WEEKXIU:
PUSH 05H
PUSH 06H
PUSH 07H
CJNE R5,#3,WEEKXIU0
WEEKXIU0:
JNC WEEKXIU1
MOV A,#12
ADD A,R5
MOV R5,A
DEC R6
CJNE R6,#0,WEEKXIU1
MOV R6,#99
DEC R7
WEEKXIU1:
MOV 44H,#0
MOV A,R7
MOV B,#4
DIV AB
ACALL QIUYU
MOV A,#203
CLR C
SUBB A,R7
SUBB A,R7
ACALL QIUYU
MOV A,R6
ACALL QIUYU
MOV A,R6
MOV B,#4
DIV AB
ACALL QIUYU
MOV A,R5
ADD A,R5
ACALL QIUYU
MOV A,R5
MOV B,#6
MUL AB
ADD A,#6
MOV B,#10
DIV AB
ACALL QIUYU
MOV A,R4
INC A
ACALL QIUYU
POP 07H
POP 06H
POP 05H
RET
QIUYU:
ADD A,44H
MOV B,#7
DIV AB
MOV 44H,B
RET
;显示日期
DISP3:
MOV A,#0C1H
ACALL I_SEND
MOV A,07H
ACALL DISP
MOV A,06H
ACALL DISP
MOV A,#45
ACALL D_SEND
MOV A,05H
ACALL DISP
MOV A,#45
ACALL D_SEND
MOV A,04H
ACALL DISP
MOV A,#32
ACALL D_SEND
MOV A,44H
MOV B,#3
MUL AB
MOV 42H,#4
ACALL WEEK00
RET
;主程序3,实现闹铃设置1
MAIN3:
MOV A,#01H ;显示CLOCK SETTING1
ACALL I_SEND
MOV DPTR,#TABLE5
MOV A,#80H
ACALL DISPX
SETB 20H.7
AJMP MAIN10
;主程序30,实现闹铃设置2
MAIN30:
MOV A,#01H ;显示CLOCK SETTING2
ACALL I_SEND
MOV DPTR,#TABLE7
MOV A,#80H
ACALL DISPX
;开始显示并且可以调整
MAIN301:
ACALL DISP4
;判断按键0
MAIN302:
JB DAT1.0,MAIN31
ACALL DELAY5MS
CLR 20H.5
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10
SETB TR2
JNB DAT1.0,$
ACALL DELAY5MS
JNB 20H.5,MAIN303
CLR 20H.5
SETB 20H.0
AJMP MAIN0
MAIN303:
CLR TR2
CLR 20H.5
CPL 21H.0
SJMP MAIN301
;判断按键1
MAIN31:
JB DAT1.1,MAIN32
ACALL DELAY5MS
MOV 43H,#10
MAIN310:
CLR 20H.5
MOV TL2,#TTL2
MOV TH2,#TTH2
SETB TR2
INC 48H
ACALL DISP4
MAIN311:
JNB 20H.5,MAIN312
MOV 43H,#TT2
SJMP MAIN310
MAIN312:
JNB DAT1.1,MAIN311
ACALL DELAY5MS
CLR TR2
CLR 20H.5
;此处直接运行下一句,即判断按键
;判断按键2
MAIN32:
JB DAT1.2,MAIN33
ACALL DELAY5MS
MOV 43H,#10
MAIN320:
CLR 20H.5
MOV TL2,#TTL2
MOV TH2,#TTH2
SETB TR2
DEC 48H
ACALL DISP4
MAIN321:
JNB 20H.5,MAIN322
MOV 43H,#TT2
SJMP MAIN320
MAIN322:
JNB DAT1.2,MAIN321
ACALL DELAY5MS
CLR TR2
CLR 20H.5
;此处直接运行下一句,即判断按键
;判断按键3
MAIN33:
JB DAT1.3,MAIN302
ACALL DELAY5MS
JNB DAT1.3,$
ACALL DELAY5MS
SETB 20H.0
AJMP MAIN0
;显示闹铃开关与闹铃时间
DISP4:
MOV A,#0C4H
ACALL I_SEND
JB 21H.0,DISP40
MOV A,#79
ACALL D_SEND
MOV A,#70
ACALL D_SE
ND
MOV A,#70
ACALL D_SEND
SJMP DISP41
DISP40:
MOV A,#79
ACALL D_SEND
MOV A,#78
ACALL D_SEND
MOV A,#32
ACALL D_SEND
DISP41:
MOV A,#0C9H
ACALL I_SEND
MOV A,48H
MOV B,#100
DIV AB
ADD A,#48
ACALL D_SEND
MOV A,B
MOV B,#10
DIV AB
ADD A,#48
ACALL D_SEND
MOV A,B
ADD A,#48
ACALL D_SEND
RET
;闹铃服务程序
CLOCK:
JB 21H.1,CLCOK1;持续响铃判断
MOV A,45H
CJNE A,1DH,CLOCK0
MOV A,46H
CJNE A,1EH,CLOCK0
MOV A,47H
CJNE A,1FH,CLOCK0
;判断正确
MOV R7,#0 ;推迟分钟
MOV R6,48H ;持续时间,秒
INC R6
SETB 21H.1 ;开始持续
CLR 20H.1
;时间正确
CLCOK1:
CJNE R7,#0,CLOCK2;判断是否推迟
;开闹铃
MOV A,#01H ;显示CLOCK
ACALL I_SEND
MOV A,#80H
MOV DPTR,#TABLE8
ACALL DISPX
ACALL DISP1
;按键0,关闭闹铃
CLOCK10:
JB DAT1.0,CLOCK11
ACALL DELAY5MS
JNB DAT1.0,$
ACALL DELAY5MS
CLR 21H.1
SJMP CLOCK02
;按键3,延迟几分钟
CLOCK11:
JB DAT1.3,CLOCK12
ACALL DELAY5MS
JNB DAT1.0,$
ACALL DELAY5MS
CLR 20H.2
MOV R7,#CLOCKTIME
SJMP CLOCK02
CLOCK12:
CLR DAT2.1
JNB 20H.1,CLOCK10
CLR 20H.1
ACALL DISP1
DJNZ R6,CLOCK10
CLR 21H.1
SJMP CLOCK02
CLOCK2:
JNB 20H.2,CLOCK0;判断是否过了1分钟
CLR 20H.2
DEC R7
CLOCK02:
ACALL DISP0
ACALL DISP1
CLOCK0:
SETB DAT2.1;关闹铃,退出
CLOCL01:
RET
;
MAIN4:
MOV A,#01H ;显示STOPWATCH
ACALL I_SEND
MOV DPTR,#TABLE6
MOV A,#80H
ACALL DISPX
AJMP MAIN431 ;按键4中清零函数
;按键0 退出
MAIN40:
JB DAT1.0,MAIN41
JB TR1,MAIN41 ;于2011 12 6 补充
ACALL DELAY5MS
JNB DAT1.0,$
ACALL DELAY5MS
SETB 20H.0
LJMP MAIN0
;按键1 开始/继续
MAIN41:
JB DAT1.1,MAIN42
JB TR1,MAIN42 ;2011 12 6 试验3 防止按键时一直按键1出现bug 成功
;SETB TR1 2011 12 6 试验,防止按键时一直按键1出现bug 但是失败了
; SETB 21H.2
ACALL DELAY5MS
SETB TR1
SETB 21H.2
JNB DAT1.1,$
ACALL DELAY5MS
ACALL DISP2
;按键2 记录/查看
MAIN42:
JB DAT1.2,MAIN43
ACALL DELAY5MS
JNB DAT1.2,$
ACALL DELAY5MS
JB 21H.2,MAIN420
CJNE R4,#0,MAIN422
SJMP MAIN42
MAIN422:
INC R0
MOV A,R4
MOV B,#3
MUL AB
ADD A,#80H
CJNE A,00H,MAIN421
MOV R0,#80H
MAIN421:
MOV A,#0C4H
ACALL I_SEND
MOV A,@R0
ACALL DISP
MOV A,#3AH
ACALL D_SEND
INC R0
MOV A,@R0
ACALL DISP
MOV A,#3AH
ACALL D_SEND
INC R0
MOV A,@R0
ACALL DISP
SJMP MAIN43
MAIN420:
MOV A,R4
MOV B,#3
MUL AB
ADD A,#80H
MOV R0,A
MOV @R0,07H
INC R0
MOV @R0,06H
INC R0
MOV @R0,05H
INC R4
;按键3 中止/清零
MAIN43:
JB DAT1.3,MAIN40
ACALL DELAY5MS
CLR 20H.5
MOV TL2,#TTL2
MOV TH2,#TTH2
MOV 43H,#10
SETB TR2
JNB DAT1.3,$
ACALL DELAY5MS
JNB 20H.5,MAIN430
MAIN431:
CLR 20H.5
CLR TR1
MOV TL1,#TTL1
MOV TH1,#TTH1
MOV R7,#0
MOV R6,#0
MOV R5,#0
MOV R4,#0
ACALL DISP2
MAIN430:
CLR TR2
CLR TR1
CLR 21H.2;秒表未工作
SJMP MAIN43
TIMER1:
M
OV TL1,#TTL1
MOV TH1,#TTH1
INC R5
CJNE R5,#100,TIMER10
MOV R5,#0
INC R6
CJNE R6,#60,TIMER10
MOV R6,#0
INC R7
TIMER10:
LCALL DISP2
RETI
END