数字钟.docx
《数字钟.docx》由会员分享,可在线阅读,更多相关《数字钟.docx(16页珍藏版)》请在冰豆网上搜索。
![数字钟.docx](https://file1.bdocx.com/fileroot1/2023-7/21/243438f5-bda3-47eb-b23e-62d50d1c8fba/243438f5-bda3-47eb-b23e-62d50d1c8fba1.gif)
数字钟
SECONDEQU30H
MINITEEQU31H
HOUREQU32H
DAYEQU33H
MONTHEQU34H
YEAREQU35H
AlarmSECONDEQU36H
AlarmMINITEEQU37H
AlarmHOUREQU38H/*秒、分、时、日、月、年以及闹铃秒、分时存储单元定*/
DAYMAXEQU3BH/*月最大天数存储单元定义*/
DATABUFEQU40H/*显示码存储单元定义*/
DISPBITEQU48H/*位选码存储单元定义*/
StopTimeEQU49H/*暂停时间储单元定义*/
FlashTimeEQU50H/*按键调整时当前位闪烁时间储单元定义*/
AlarmSoundEQU51H/*闹铃声音变量储单元定义*/
AlarmTimeEQU52H/*闹铃持续时间储单元定义*/
ADDKBITP1.0
DECKBITP1.2
MovebitKBITP1.4
ExchangTDAKBITP1.6/*秒,分,时和日期按键接口定义*/
;********************主程序***********************************
ORG00H
LJMPSTART
ORG0BH/*定时器0中断入口地址*/
LJMPINT_T0/*定时器0中断程序入口*/
ORG100H
START:
MOVSECOND,#55
MOVMINITE,#55
MOVHOUR,#23
MOVDAY,#27
MOVMONTH,#2
MOVYEAR,#96
MOVAlarmSECOND,#59
MOVAlarmMINITE,#55
MOVAlarmHOUR,#23/*秒,分,时,日,月,年以及闹铃秒,分,时初值*/
MOVAlarmTime,#10/*闹铃持续时间,单位:
秒*/
MOVStopTime,#0FFH/*时间暂停变量初值*/
ACALLBCD/*开机立即显示初值*/
MOVDISPBIT,#00H/*位选初值*/
MOVMOD,#01H/*定义TO中断,方式0*/
MOVTH0,#(65536-50000)/256
MOVTL0,#(65536-50000)MOD256/*中断初值*/
SETBEA/*CPU开中断*/
SETBET0/*允许T0中断*/
SETBTR0/*启动T0定时*/
HERE1:
ACALLButtonADD
ACALLDISPLAY
ACALLAlarming
LJMPHERE1/*循环调用按键、显示和闹铃子程序等待中断*/
;**************中断程序********************************
INT_T0:
MOVTH0,#(65536-50000)/256
MOVTL0,#(65536-50000)MOD256/*中断初值*/
INCR5
INCAlarmSound
MOVA,AlarmSound
CJNEA,#5,Continue1
MOVAlarmSound,#0/*每秒闹铃响铃时间设置*/
Continue1:
INCFlashTime
MOVA,FlashTime
CJNEA,#5,Continue2
MOVFlashTime,#0/*调整时间某位时数码管闪烁设置*/
Continue2:
CJNER5,#20,OUT0
MOVR5,#0/*中断20次定时1秒设置*/
JNBF0,Continue3
DECAlarmTime
MOVA,#0
CJNEA,AlarmTime,Continue3
CLRF0
SETBP3.7
MOVAlarmTime,#10/*闹铃持续时间设置*/
Continue3:
MOVA,StopTime/*时间暂停设置*/
CJNEA,#0FFH,OUT0
INCSECOND
MOVA,SECOND
CJNEA,#60,OUT0
MOVSECOND,#0/*秒60进制设置*/
INCMINITE
MOVA,MINITE
CJNEA,#60,OUT0
MOVMINITE,#0/*分60进制设置*/
INCHOUR
MOVA,HOUR
CJNEA,#24,OUT0
MOVHOUR,#0/*时24进制设置*/
C1:
INCDAY
MOVDPTR,#MonthmaxTab/*指针变量指向月份最大天数表*/
MOVA,YEAR
MOVB,#4
DIVAB
MOVA,B
CJNEA,#00,C2
MOVA,#13/*当为闰年时,2月为29天*/
LJMPC3
C2:
MOVA,MONTH
C3:
DECA
MOVCA,@A+DPTR
MOVDAYMAX,A/*查表得到每月最大天数*/
MOVA,DAY
CJNEA,DAYMAX,OUT0/*日按闰年或非闰年的月份最大天数进制设置*/
MOVDAY,#01
INCMONTH
MOVA,MONTH
CJNEA,#13,OUT0
MOVMONTH,#01/*月12进制设置*/
INCYEAR
MOVA,YEAR
CJNEA,#99,OUT0
MOVMONTH,#00/*年99进制设置*/
OUT0:
MOVA,SECOND
CJNEA,AlarmSECOND,OUT1
MOVA,MINITE
CJNEA,AlarmMINITE,OUT1
MOVA,HOUR
CJNEA,AlarmHOUR,OUT1
SETBF0
OUT1:
ACALLBCD
RETI
;*************闹铃程序****************
Alarming:
JNBF0,OUT/*以用户自定义位F0为闹铃标志位,F0置位时启动闹铃*/
MOVA,R5
CJNEA,AlarmSound,OUT2
CLRP3.7/*将P3.7清零则闹铃响铃*/
LJMPOUT
OUT2:
SETBP3.7
OUT:
RET
;*************按键程序*****************
ButtonADD:
/*按键加设置*/
JBADDK,JumpMark1
ACALLDELY10MS/*延时10MS去抖动*/
JBADDK,JumpMark1
CLRP3.6/*按键指示灯设置,按键按下时灯亮*/
CJNER2,#1,ADD1
CJNER3,#0,A1
INCHOUR
MOVA,#24
CJNEA,HOUR,A1
MOVHOUR,#00/*加时变量设置*/
A1:
CJNER3,#1,A2
INCYEAR
MOVA,#100
CJNEA,YEAR,A2
MOVYEAR,#00/*加年变量设置*/
A2:
CJNER3,#2,ADD1
INCAlarmHOUR
MOVA,#24
CJNEA,AlarmHOUR,ADD1
MOVAlarmHOUR,#00/*加闹铃时变量设置*/
ADD1:
CJNER2,#2,ADD2
CJNER3,#0,A3
INCMINITE
MOVA,#60
CJNEA,MINITE,A3
MOVMINITE,#00/*加分变量设置*/
A3:
CJNER3,#1,A4
INCMONTH
MOVA,#13
CJNEA,MONTH,A4
MOVMONTH,#00/*加月变量设置*/
A4:
CJNER3,#2,ADD2
INCAlarmMINITE
MOVA,#60
CJNEA,AlarmMINITE,ADD2
MOVAlarmMINITE,#00/*加闹铃分变量设置*/
AJMPADD2
JumpMark1:
LJMPButtonDEC
ADD2:
CJNER2,#3,L1
CJNER3,#0,A5
INCSECOND
MOVA,#60
CJNEA,SECOND,A5
MOVSECOND,#00/*加秒变量设置*/
A5:
CJNER3,#1,A8
INCDAY
MOVDPTR,#MonthmaxTab
MOVA,YEAR
MOVB,#4
DIVAB
MOVA,B
CJNEA,#00,A6
MOVA,#13
LJMPA7
A6:
MOVA,MONTH
A7:
DECA
MOVCA,@A+DPTR
MOVDAYMAX,A
MOVA,DAYMAX
CJNEA,DAY,L1
MOVDAY,#01/*加天变量设置*/
A8:
CJNER3,#2,L1
INCAlarmSECOND
MOVA,#60
CJNEA,AlarmSECOND,L1
MOVAlarmSECOND,#00/*加闹铃秒变量设置*/
L1:
ACALLBCD
L2:
ACALLDISPLAY
JNBADDK,L2/*按键调整完立即调用数据处理和显示程序*/
SETBP3.6/*松开按键时灭显示灯*/
ButtonDEC:
/*减按键设置*/
JBDECK,JumpMark2
ACALLDELY10MS
JBDECK,JumpMark2
CPLP3.6
CJNER2,#1,DEC1
CJNER3,#0,A9
DECHOUR
MOVA,HOUR
CJNEA,#-1,A9
MOVHOUR,#00/*减时变量设置*/
A9:
CJNER3,#1,A10
DECYEAR
MOVA,YEAR
CJNEA,#-1,A10
MOVYEAR,#00/*减年变量设置*/
A10:
CJNER3,#2,DEC1
DECAlarmHOUR
MOVA,AlarmHOUR
CJNEA,#-1,DEC1
MOVAlarmHOUR,#00/*减闹铃时变量设置*/
LJMPDEC1
JumpMark2:
LJMPMovebit
DEC1:
CJNER2,#2,DEC2
CJNER3,#0,A11
DECMINITE
MOVA,MINITE
CJNEA,#-1,A11
MOVMINITE,#00/*减分变量设置*/
A11:
CJNER3,#1,A12
DECMONTH
MOVA,MONTH
CJNEA,#-1,A12
MOVMONTH,#00/*减月变量设置*/
A12:
CJNER3,#2,DEC2
DECAlarmMINITE
MOVA,AlarmMINITE
CJNEA,#-1,DEC2
MOVAlarmMINITE,#00/*减闹铃分变量设置*/
DEC2:
CJNER2,#3,L3
CJNER3,#0,A13
DECSECOND
MOVA,SECOND
CJNEA,#-1,A13
MOVSECOND,#00/*减秒变量设置*/
A13:
CJNER3,#1,A14
DECDAY
MOVA,DAY
CJNEA,#-1,A14
MOVDAY,#00/*减天变量设置*/
A14:
CJNER3,#2,L3
DECAlarmSECOND
MOVA,AlarmSECOND
CJNEA,#-1,L3
MOVAlarmSECOND,#00/*减闹铃秒变量设置*/
L3:
ACALLBCD
L4:
ACALLDISPLAY/*按键调整完立即调用数据处理和显示程序*/
JNBDECK,L4
CPLP3.6
Movebit:
/*调整时间移位程序*/
JBMovebitK,ButtonExchangTDA
ACALLDELY10MS
JBMovebitK,ButtonExchangTDA
CLRP3.6
CJNER3,#00H,GOON
MOVStopTime,#00H
GOON:
INCR2
CJNER2,#4,B1
MOVR2,#0
MOVStopTime,#0FFH
B1:
ACALLBCD
B2:
ACALLDISPLAY
JNBMovebitK,B2
SETBP3.6
ButtonExchangTDA:
/*切换时间、日期和闹铃程序*/
JBExchangTDAK,Done4
LCALLDELY10MS
JBExchangTDAK,Done4
CLRP3.6
INCR3
CJNER3,#03H,B3
MOVR3,#00H
B3:
ACALLBCD
B4:
ACALLDISPLAY
JNBExchangTDAK,B4
SETBP3.6
Done4:
RET
;*******************显示码调整*********************
BCD:
CJNER3,#00H,LOOP1
MOVR0,#HOUR
LJMPLOOP3
LOOP1:
CJNER3,#01H,LOOP2
MOVR0,#YEAR
LJMPLOOP3
LOOP2:
MOVR0,#AlarmHOUR
LOOP3:
MOVA,#DATABUF/*以40H为显示首地址分别存储拆分后的数据码*/
ADDA,#8
DECA/*存储单元为40H-47H*/
MOVR1,A
MOVA,@R0/*将时或者年数进行拆分*/
MOVB,#10
DIVAB
MOV@R1,A/*将时或者年数的十位存入47H*/
DECR1
MOVA,B
MOV@R1,A/*将时或者年数的个位存入46H*/
DECR1
DECR0
MOVA,#10/*间隔符号存入45H*/
MOV@R1,A
DECR1
MOVA,@R0/*将分或者月数进行拆分*/
MOVB,#10
DIVAB
MOV@R1,A/*将分或者月数的十位存入44H*/
DECR1
MOVA,B
MOV@R1,A/*将分或者月数的十位存入43H*/
DECR1
DECR0
MOVA,#10/*间隔符号存入42H*/
MOV@R1,A
DECR1
MOVA,@R0/*将秒或者日数进行拆分*/
MOVB,#10
DIVAB
MOV@R1,A/*将秒或者日数的十位存入41H*/
DECR1
MOVA,B
MOV@R1,A/*将秒或者日数的个位BCD码存入40H*/RET
;***************显示程序*********************************
DISPLAY:
MOVA,#0FFH
MOVP2,A/*将位选信号清零*/
MOVA,#DATABUF
ADDA,DISPBIT
MOVR0,A
MOVA,@R0/*显示以DATABUF=40H为首地址,位选DISPBIT为变量的数据*/
MOVDPTR,#TABLE/*将指针变量指向数据码表*/
MOVCA,@A+DPTR
MOVP0,A/*将显示数据送至P1口输出*/
CJNER2,#1,DIS1
MOVA,R5
CJNEA,FlashTime,DIS3/*若不在调整时间,则调用正常显示位选码表*/
MOVDPTR,#BITTAB1/*若在调整时间,则调用各个位闪烁位选码表*/
LJMPDIS4
DIS1:
CJNER2,#2,DIS2
MOVA,R5
CJNEA,FlashTime,DIS3
MOVDPTR,#BITTAB2
LJMPDIS4
DIS2:
CJNER2,#3,DIS3
MOVA,R5
CJNEA,FlashTime,DIS3
MOVDPTR,#BITTAB3
LJMPDIS4
DIS3:
MOVDPTR,#BITTAB0
DIS4:
MOVA,DISPBIT
MOVCA,@A+DPTR
MOVP2,A/*将位选信号送至P3口输出*/
INCDISPBIT/*将位选信号自加一,显示下一位数*/
MOVA,DISPBIT
CJNEA,#08,OUT3
MOVDISPBIT,#0/*若显示完8位,将位选信号清零进行循环动态显示*/
OUT3:
RET
;******************延时程序以及码表**************************
DELY10MS:
MOVR6,#10/*按键10MS去抖动延时程序*/
D1:
MOVR7,#248
DJNZR7,$
DJNZR6,D1
RET
TABLE:
DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H,00H/*数据码表*/
BITTAB0:
DB0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH/*位选码表*/
BITTAB1:
DB0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0FFH,0FFH
BITTAB2:
DB0FEH,0FDH,0FBH,0FFH,0FFH,0DFH,0BFH,07FH
BITTAB3:
DB0FFH,0FFH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
MonthmaxTab:
DB20H,1DH,20H,1FH,20H,1FH,20H,20H,1FH,20H,1FH,20H,1EH/*月最大天数码表*/
END