tceic.com
学霸学习网 这下你爽了
赞助商链接
当前位置:首页 >> 信息与通信 >>

数字钟汇编程序


SEC EQU 30H ;时间:秒
MIN EQU 31H ;分
HOU EQU 32H ;时

YEAR1 EQU 33H ;日历:年1高两位
YEAR2 EQU 34H ;年2低两位
MONTH EQU 35H ;月
DAY EQU 36H ;日

NUM EQU 37H ;修改显示位
ALARM_RING EQU 38H ;闹钟RING标志位1叫,0不叫
NUM_KEY EQU 39H ;保存计算的键值
ALARM_X EQU 3AH ;保存闹钟的号码
ALARM_ON_OFF EQU 3BH;1为开,0关
YEAR_CHECK EQU 3CH ;0为闰年,1不是

DAY_MAX EQU 3DH ;每月最大时间
YES_RING EQU 3EH ;允许鸣叫标志位
ALARM_1_SEC EQU 40H ;闹钟1
ALARM_1_MIN EQU 41H
ALARM_1_HOU EQU 42H

ALARM_2_SEC EQU 43H ;闹钟2
ALARM_2_MIN EQU 44H
ALARM_2_HOU EQU 45H

ALARM_3_SEC EQU 46H ;闹钟3
ALARM_3_MIN EQU 47H
ALARM_3_HOU EQU 48H

ALARM_4_SEC EQU 49H ;闹钟4
ALARM_4_MIN EQU 4AH
ALARM_4_HOU EQU 4BH

ALARM_5_SEC EQU 4CH ;闹钟5
ALARM_5_MIN EQU 4DH
ALARM_5_HOU EQU 4EH

SECX EQU 50H ;显示闹钟时间中秒暂存
MINX EQU 51H
HOUX EQU 52H

ALARM_SEC EQU 53H ;比较时闹钟时分秒暂存
ALARM_MIN EQU 54H
ALARM_HOU EQU 55H

NUM_D1 EQU 58H ;定时器1,1秒循环20次
SEC_XOUT EQU 59H ;秒溢出判断
MIN_XOUT EQU 5AH
HOU_XOUT EQU 5BH

NUM_SHIA EQU 60H ;闹钟十位个位暂存
NUM_GEA EQU 61H

NUM_ALARM EQU 70H ;KEY14标记移位

NUM_KEYBACK EQU 71H ;算键值标志位,为1为有键值

NUM_L EQU 72H ;行值
NUM_Q EQU 73H ;列值

NUM_SHI EQU 75H ;显示高位低位保存十位数
NUM_GE EQU 76H ;保存个位数
LOC_PLACE EQU 77H ;TIME查表保存位值
NUM_ENTER EQU 78H ;保存输入时间键值的个数
MODE EQU 79H ;外部中断0,1判断
NUM_ENTER_ALARM EQU 7AH ;闹钟输入键值个数
LOC_ALARM EQU 7BH ;闹钟查表保存值
NUM_KEY14 EQU 7CH ;14键按下标志
NUM_KEY15 EQU 7DH ;15键按下标志位,1按下

ORG 0000H
LJMP MAIN
ORG 000BH
LJMP SERVE_TIMER0
ORG 001BH
LJMP SERVE_TIMER1
ORG 0003H
LJMP SERVE_PLACE
ORG 0013H
LJMP SERVE_ALARM
ORG 0020H

MAIN:
MOV TMOD,#11H
MOV NUM_D1,#20

MOV SEC,#59 ;时间初始化
MOV MIN,#59
MOV HOU,#12

MOV NUM,#0
MOV NUM_KEY,#0
MOV ALARM_X,#0

MOV YEAR1,#19 ;日历初始化
MOV YEAR2,#89
MOV MONTH,#06
MOV DAY,#06

MOV ALARM_1_SEC,#00 ;闹钟1
MOV ALARM_1_MIN,#01
MOV ALARM_1_HOU,#13

MOV ALARM_2_SEC,#00 ;闹钟2
MOV ALARM_2_MIN,#58
MOV ALARM_2_HOU,#12

MOV ALARM_3_SEC,#00 ;闹钟3
MOV ALARM_3_MIN,#05
MOV ALARM_3_HOU,#13

MOV ALARM_4_SEC,#00 ;闹钟4
MOV ALARM_4_MIN,#10
MOV ALARM_4_HOU,#13

MOV ALARM_5_SEC,#00 ;闹钟5
MOV ALARM_5_MIN,#20
MOV ALARM_5_HOU,#13
MOV NUM_ENTER,#0
MOV MODE,#0
MOV NUM_ALARM,#0
MOV ALARM_RING,#1 ;闹钟鸣叫

MOV NUM_ENTER_ALARM,#0
MOV YES_RING,#0
MOV NUM_KEY15,#0
;
SETB IT0
SETB IT1
SETB EX0 ;外部中断0
SETB EX1 ;外部中断1
SETB ET1 ;允许T1中断
SETB EA


MOV TH1,#3CH
MOV TL1,#0BH
SETB TR1

/*****************T0定时时运行******************/
HERE:
LCALL COMPAREANDRING
MOV A,MODE
JZ SHOW
LCALL SET_ALARM
LCALL DISPLAY_ALARM
LJMP HERE
SHOW:
MOV A,NUM
CLR C
SUBB A,#4
JC SHOW_TIME
LCALL TIME_CHANGE_KEY ;按矩阵键盘输入
LCALL DISPLAY_CALENDAR
LJMP HERE
SHOW_TIME:
LCALL CHANGE_ADD ;按P3.4加一
LCALL CHANGE_SUB ;按P3.5减一

LCALL TIME_CHANGE_KEY ;按矩阵键盘输入
LCALL DISPLAY_TIME ;显示时间
LJMP HERE

/*****************定时器1******************/
ORG 0100H
SERVE_TIMER1:
MOV TH1,#3CH
MOV TL1,#0BH
DJNZ NUM_D1,RETURN1 ;20H不为0跳转
MOV NUM_D1,#20
INC SEC ;计时间
MOV A,SEC
CJNE A,#60,RETURN1
MOV SEC,#0
INC MIN
MOV A,MIN
CJNE A,#60,RETURN1
MOV MIN,#0
INC HOU
MOV A,HOU
CJNE A,#24,RETURN1
MOV HOU,#0

INC DAY ;计日期
LCALL DAYMAX
MOV A,DAY_MAX ;与对应的月份最大日相比
ADD A,#1
MOV DAY_MAX,A
MOV A,DAY
CLR C
SUBB A,DAY_MAX
JC RETURN1
MOV DAY,#01

INC MONTH
MOV A,MONTH
CJNE A,#13,RETURN1
MOV MONTH,#01
INC YEAR2
MOV A,YEAR2
CJNE A,#100,RETURN1
MOV YEAR2,#00
INC YEAR1
MOV A,YEAR1
CJNE A,#000,RETURN1
MOV YEAR1,#19
RETURN1:
RETI
/*****************定时器0--蜂鸣器**********************/
SERVE_TIMER0:
SETB P1.0
MOV TH0,#0FEH
MOV TL0,#0CH
CPL P1.0
RETURN4:
RETI
/******************外部中断0重置秒分时位置选择************/
ORG 0200H
SERVE_PLACE:
MOV MODE,#0 ;标记为外部中断0
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY

INC NUM
MOV A,NUM
CJNE A,#9,RETURN2
MOV NUM,#0
RETURN2:
MOV A,NUM ;跑马灯指示位
MOV DPTR,#TABLE_PAO
MOVC A,@A+DPTR
MOV P1,A
MOV NUM_ENTER,#0
CLR IE0
MOV ALARM_X,#0
MOV NUM_ALARM,#3
RETI

/*******************外部中断1设置闹钟********************/
SERVE_ALARM:
MOV MODE,#1
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY
LCALL DELAY

INC ALARM_X ;切换不同的闹钟
MOV A,ALARM_X
CJNE A,#6,RETURN3
MOV ALARM_X,#0
RETURN3:
MOV NUM_ALARM,#0 ;闹钟移位置0

MOV A,#0 ;跑马灯熄灭
MOV DPTR,#TABLE_PAO
MOVC A,@A+DPTR
MOV P1,A
CLR IE1
MOV NUM,#8
RETI



/*********************设置闹钟**********************/
SET_ALARM:
MOV A,ALARM_X
CJNE A,#1,SET_ALARM_BACK
SET_ALARM1:
MOV SECX,40H
MOV MINX,41H
MOV HOUX,42H
LCALL CHECK_KEY14
MOV A,NUM_ALARM
CJNE A,#1,SET_ALARM1_2
SET_ALARM1_1:
LCALL ALARM_CHANGE_KEY
MOV SECX,40H
LJMP SET_ALARM_BACK
SET_ALARM1_2:
MOV A,NUM_ALARM
CJNE A,#2,SET_ALARM1_3
LCALL ALARM_CHANGE_KEY
MOV MINX,41H
LJMP SET_ALARM_BACK
SET_ALARM1_3:
MOV A,NUM_ALARM
CJNE A,#3,SET_ALARM_BACK
LCALL ALARM_CHANGE_KEY
MOV HOUX,42H
LJMP SET_ALARM_BACK
SET_ALARM_BACK:
RET
/*SET_ALARM2:
MOV A,ALARM_X
CJNE A,#2,SET_ALARM3
LCALL CHECK_KEY14
; MOV A,NUM_KEY14
; JZ SET_ALARM_BACK
LCALL ALARM_CHANGE_KEY
LCALL DELAY1
MOV SECX,43H
MOV MINX,44H
MOV HOUX,45H
LJMP SET_ALARM_BACK
SET_ALARM_BACK:
RET
SET_ALARM3:
MOV A,ALARM_X
CJNE A,#3,SET_ALARM4
LCALL CHECK_KEY14
MOV A,NUM_KEY14
JZ SET_ALARM_BACK
LCALL ALARM_CHANGE_KEY
LCALL DELAY1
MOV SECX,46H
MOV MINX,47H
MOV HOUX,48H
LJMP SET_ALARM_BACK
SET_ALARM4:
MOV A,ALARM_X
CJNE A,#4,SET_ALARM5
LCALL CHECK_KEY14
MOV A,NUM_KEY14
JZ SET_ALARM_BACK
LCALL ALARM_CHANGE_KEY
LCALL DELAY1
MOV SECX,49H
MOV MINX,4AH
MOV HOUX,4BH
LJMP SET_ALARM_BACK
SET_ALARM5:
MOV A,ALARM_X
CJNE A,#5,SET_ALARM_BACK
LCALL CHECK_KEY14
MOV A,NUM_KEY14
JZ SET_ALARM_BACK
LCALL ALARM_CHANGE_KEY
LCALL DELAY1
MOV SECX,4CH
MOV MINX,4DH
MOV HOUX,4EH
LJMP SET_ALARM_BACK */



/*CHECK_ALARM_ON_OFF: ;判断闹钟是否开启,1开,0关
LCALL KEYNUM
MOV A,KEYNUM_BACK
JZ CHECK_ALARM_ON_OFF_BACK
MOV A,NUM_KEY
CJNE A,#15,CHECK_ALARM_ON_OFF_BACK
MOV ALARM_RING,#1
LJMP CHECK_ALARM_ON_OFF_BACK
CHECK_ALARM_ON_OFF1:
MOV ALARM_RING,#0
CHECK_ALARM_ON_OFF_BACK:
RET */

CHECK_KEY14: ;设置闹钟时14按下则移位
LCALL KEYNUM
MOV A,NUM_KEYBACK
JZ CHECK_KEY14_BACK
MOV A,NUM_KEY
CJNE A,#14,CHECK_KEY14_BACK
INC NUM_ALARM
LCALL DELAY
; MOV NUM_KEY14,#1
MOV NUM_ENTER_ALARM,#0
MOV A,NUM_ALARM
CJNE A,#4,CHECK_KEY14_BACK
MOV NUM_ALARM,#0
CHECK_KEY14_BACK:
MOV A,NUM_ALARM ;跑马灯指示位
MOV DPTR,#TABLE_PAO
MOVC A,@A+DPTR
MOV P1,A
RET

ALARM_CHANGE_KEY: ;闹钟改变键值*************************/
MOV A,NUM_ENTER_ALARM
JZ KEYNUM_11
LJMP KEYNUM_22
KEYNUM_11:
LCALL CHECK_KEY
JZ ALARM_CHANGE_KEY_BACK
LCALL CHECK_NUM_KEY
MOV NUM_SHIA,NUM_KEY
MOV NUM_ENTER_ALARM,#1
LCALL DELAY1
LCALL CHANGE_SHI_ALARM
LJMP ALARM_CHANGE_KEY_BACK
KEYNUM_22:
LCALL CHECK_KEY
JZ ALARM_CHANGE_KEY_BACK
LCALL CHECK_NUM_KEY
MOV NUM_GEA,NUM_KEY
LCALL DELAY1
MOV NUM_ENTER_ALARM,#0
LCALL CHANGE_GE_ALARM
ALARM_CHANGE_KEY_BACK:
RET

CHANGE_SHI_ALARM: ;改变十位
MOV A,NUM_ALARM
LCALL CHOOSE_TABLE_ALARM
MOV A,NUM_ALARM
MOVC A,@A+DPTR
MOV LOC_ALARM,A
MOV R0,A
MOV A,@R0
MOV B,#10
DIV AB
MOV R5,B
MOV A,NUM_SHIA
MOV B,#10
MUL AB
ADD A,R5
MOV R1,A
MOV R0,LOC_ALARM
MOV A,R1
MOV @R0,A
RET

CHANGE_GE_ALARM: ;改变个位
MOV A,NUM_ALARM
LCALL CHOOSE_TABLE_ALARM
MOV A,NUM_ALARM
MOVC A,@A+DPTR
MOV LOC_ALARM,A
MOV R0,A
MOV A,@R0
MOV B,#10
DIV AB
MOV B,#10
MUL AB
ADD A,NUM_GEA
MOV R1,A
MOV R0,LOC_ALARM
MOV A,R1
MOV @R0,A
RET

CHOOSE_TABLE_ALARM:
MOV A,ALARM_X
CJNE A,#1,A_2
MOV DPTR,#TABLE_ALARM1
LJMP CHOOSE_TABLE_ALARM_BACK
A_2:
CJNE A,#2,A_3
MOV DPTR,#TABLE_ALARM2
LJMP CHOOSE_TABLE_ALARM_BACK
A_3:
CJNE A,#3,A_4
MOV DPTR,#TABLE_ALARM3
LJMP CHOOSE_TABLE_ALARM_BACK
A_4:
CJNE A,#4,A_5
MOV DPTR,#TABLE_ALARM4
LJMP CHOOSE_TABLE_ALARM_BACK
A_5:
CJNE A,#5,A_0
MOV DPTR,#TABLE_ALARM5
A_0:
NOP
CHOOSE_TABLE_ALARM_BACK:
RET

TABLE_ALARM1:
DB 00H,40H,41H,42H
TABLE_ALARM2:
DB 00H,43H,44H,45H
TABLE_ALARM3:
DB 00H,46H,47H,48H
TABLE_ALARM4:
DB 00H,49H,4AH,4BH
TABLE_ALARM5:
DB 00H,4CH,4DH,4EH

/**************设置闹钟与当前时间的比较并鸣叫*****************/
COMPAREANDRING:
MOV A,ALARM_X
CJNE A,#1,CR2
CR1:
MOV ALARM_SEC,40H
MOV ALARM_MIN,41H
MOV ALARM_HOU,42H
LCALL COMPARE_RING
LJMP COMPAREANDRING_BACK
CR2:
MOV A,ALARM_X
CJNE A,#2,CR3
MOV ALARM_SEC,43H
MOV ALARM_MIN,44H
MOV ALARM_HOU,45H
LCALL COMPARE_RING
LJMP COMPAREANDRING_BACK
CR3:
MOV A,ALARM_X
CJNE A,#2,CR4
MOV ALARM_SEC,46H
MOV ALARM_MIN,47H
MOV ALARM_HOU,48H
LCALL COMPARE_RING
LJMP COMPAREANDRING_BACK
CR4:
MOV A,ALARM_X
CJNE A,#2,CR5
MOV ALARM_SEC,49H
MOV ALARM_MIN,4AH
MOV ALARM_HOU,4BH
LCALL COMPARE_RING
LJMP COMPAREANDRING_BACK
CR5:
MOV A,ALARM_X
CJNE A,#2,COMPAREANDRING_BACK
MOV ALARM_SEC,4CH
MOV ALARM_MIN,4DH
MOV ALARM_HOU,4EH
LCALL COMPARE_RING
COMPAREANDRING_BACK:
RET

COMPARE_RING:
MOV A,YES_RING ;为0比较是否鸣叫
JNZ STOP_RING
RING_CHECK:
LCALL COMPARE
LJMP COMPARE_RING_BACK
STOP_RING:
LCALL CHECK_KEY15
MOV A,NUM_KEY15
JNZ COMPARE_RING_BACK
MOV A,ALARM_HOU
CJNE A,HOU,COMPARE_RING_BACK
MOV A,ALARM_MIN
ADD A,#1
CJNE A,MIN,COMPARE_RING_BACK
MOV YES_RING,#0
CLR TR0
COMPARE_RING_BACK:
RET

COMPARE:
MOV A,ALARM_HOU
CJNE A,HOU,COMPARE_BACK
MOV A,ALARM_MIN
CJNE A,MIN,COMPARE_BACK
SETB ET0
SETB EA
MOV TH0,#0FEH
MOV TL0,#0CH
SETB TR0
MOV YES_RING,#1
COMPARE_BACK:
RET

CHECK_KEY15: ;设置闹钟时15按下则移位
LCALL KEYNUM
MOV A,NUM_KEYBACK
JZ CHECK_KEY15_BACK
MOV A,NUM_KEY
CJNE A,#15,CHECK_KEY15_BACK1
CLR TR0
; MOV YES_RING,#0
MOV NUM_KEY15,#1
LJMP CHECK_KEY15_BACK
CHECK_KEY15_BACK1:
MOV NUM_KEY15,#0
CHECK_KEY15_BACK:
RET
/******************改变时间和日期*******************/
TIME_CHANGE_KEY:
MOV A,NUM_ENTER
JZ KEYNUM_1
LJMP KEYNUM_2
KEYNUM_1:
LCALL CHECK_KEY
JZ TIME_CHANGE_KEY_BACK
LCALL CHECK_NUM_KEY
MOV NUM_SHI,NUM_KEY
INC NUM_ENTER
LCALL DELAY1
LCALL CHANGE_SHI
LJMP TIME_CHANGE_KEY_BACK
KEYNUM_2:
LCALL CHECK_KEY
JZ TIME_CHANGE_KEY_BACK
LCALL CHECK_NUM_KEY
MOV NUM_GE,NUM_KEY
LCALL DELAY1
MOV NUM_ENTER,#0
LJMP CHANGE_GE
TIME_CHANGE_KEY_BACK:
RET

/********************查键值**************************/
CHECK_KEY:
LCALL KEYNUM ;读键值
MOV A,NUM_KEYBACK
RET

/*********************改变十位和个位*********************/
CHANGE_SHI: ;改变十位
MOV A,NUM
MOV DPTR,#TABLE_PLACE
MOVC A,@A+DPTR
MOV LOC_PLACE,A
MOV R0,A
MOV A,@R0
MOV B,#10
DIV AB
MOV R5,B
MOV A,NUM_SHI
MOV B,#10
MUL AB
ADD A,R5
MOV R1,A
MOV R0,LOC_PLACE
MOV A,R1
MOV @R0,A
RET

CHANGE_GE: ;改变个位
MOV A,NUM
MOV DPTR,#TABLE_PLACE
MOVC A,@A+DPTR
MOV LOC_PLACE,A
MOV R0,A
MOV A,@R0
MOV B,#10
DIV AB
MOV B,#10
MUL AB
ADD A,NUM_GE
MOV R1,A
MOV R0,LOC_PLACE
MOV A,R1
MOV @R0,A
RET
TABLE_PLACE:
DB 00H,SEC,MIN,HOU,00H,DAY,MONTH,YEAR2,YEAR1

/***************计算键值****************************/
KEYNUM:
MOV NUM_L,#0
MOV R4,#0FEH
JUDGE:
LCALL DELAY
MOV DPTR,#8000H
MOV A,#00H
MOVX @DPTR,A ;行置低
MOVX A,@DPTR ;读列
ANL A,#0FH
CJNE A,#0FH,RKEY ;不等跳转
MOV NUM_KEYBACK,#0
LJMP KEYNUM_BACK
RKEY: ;NUM_Q列值
LCALL DELAY
ROW0:
JB ACC.0,ROW1 ;等于1跳转
MOV NUM_Q,#0
ROW1:
JB ACC.1,ROW2
MOV NUM_Q,#1
ROW2:
JB ACC.2,ROW3
MOV NUM_Q,#2
ROW3:
JB ACC.3,LKEY
MOV NUM_Q,#3
LKEY:
MOV DPTR,#8000H
MOV A,R4
MOVX @DPTR,A
MOVX A,@DPTR
ORL A,#0F0H
CPL A
JNZ KEYS ;A不为0跳
INC NUM_L
MOV A,R4
RL A
MOV R4,A ;NUM_L存行值
LJMP LKEY
KEYS:
MOV A,NUM_L
MOV B,#4
MUL AB
ADD A,NUM_Q
MOV NUM_KEY,A ;算出键值
MOV NUM_KEYBACK,#1
KEYNUM_BACK:
RET

/******************检查键值是否大于9********************/
CHECK_NUM_KEY:
MOV A,NUM_KEY
CLR C
SUBB A,#10
JC CHECK_NUM_KEY_BACK
MOV NUM_KEY,#00
CHECK_NUM_KEY_BACK:
RET


/*****************显示闹钟时间***************************/
DISPLAY_ALARM:
MOV A,#7FH
LCALL LED_SEL
MOV A,ALARM_X
LCALL LED_SEG
LCALL DELAY

/* MOV A,ALARM_ON_OFF
JZ DISPLAY_TIME_ALARM
MOV A,#0BFH
LCALL LED_SEL
MOV DPTR,#TABLE
MOV A,#40H
MOVX @DPTR,A
LCALL LED_SEG
LCALL DELAY */
DISPLAY_TIME_ALARM:
MOV SEC_XOUT,SECX
LCALL SEC_OUT
MOV SECX,SEC_XOUT ;检测秒是否溢出
MOV A,SECX ;显示秒
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0FDH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0FEH
LCALL LED_SEL
LCALL DELAY

MOV MIN_XOUT,MINX
LCALL MIN_OUT ;检测分是否溢出
MOV MINX,MIN_XOUT
MOV A,MINX ;显示分
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0F7H
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0FBH
LCALL LED_SEL
LCALL DELAY

MOV HOU_XOUT,HOUX
LCALL HOU_OUT ;检测时是否溢出
MOV HOUX,HOU_XOUT
MOV A,HOUX ;显示时
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0DFH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0EFH
LCALL LED_SEL
LCALL DELAY
RET
/*********************显示时间*********************/
DISPLAY_TIME:
MOV SEC_XOUT,SEC
LCALL SEC_OUT ;检测秒是否溢出
MOV SEC,SEC_XOUT
MOV A,SEC ;显示秒
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0FDH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0FEH
LCALL LED_SEL
LCALL DELAY

MOV MIN_XOUT,MIN
LCALL MIN_OUT ;检测分是否溢出
MOV MIN,MIN_XOUT
MOV A,MIN ;显示分
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0F7H
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0FBH
LCALL LED_SEL
LCALL DELAY

MOV HOU_XOUT,HOU
LCALL HOU_OUT ;检测时是否溢出
MOV HOU,HOU_XOUT
MOV A,HOU ;显示时
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0DFH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0EFH
LCALL LED_SEL
LCALL DELAY
RET
/****************显示日期*************************/
DISPLAY_CALENDAR:
MOV A,YEAR1 ;显示年1
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#07FH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0BFH
LCALL LED_SEL
LCALL DELAY

MOV A,YEAR2 ;显示年2
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0DFH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0EFH
LCALL LED_SEL
LCALL DELAY

LCALL MONTH_OUT
MOV A,MONTH ;显示月
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0F7H
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0FBH
LCALL LED_SEL
LCALL DELAY

LCALL DAY_OUT
MOV A,DAY ;显示天
MOV B,#10
DIV AB
LCALL LED_SEG
MOV A,#0FDH
LCALL LED_SEL
LCALL DELAY
MOV A,B
LCALL LED_SEG
MOV A,#0FEH
LCALL LED_SEL
LCALL DELAY
RET

/*********************溢出检查**********************/
SEC_OUT: ;秒检查
MOV A,SEC_XOUT
CLR C
SUBB A,#60
JC SEC_OUT_BACK
MOV SEC_XOUT,#0
SEC_OUT_BACK:
RET

MIN_OUT: ;分检查
MOV A,MIN_XOUT
CLR C
SUBB A,#60
JC MIN_OUT_BACK
MOV MIN_XOUT,#0
MIN_OUT_BACK:
RET

HOU_OUT: ;小时检查
MOV A,HOU_XOUT
CLR C
SUBB A,#24
JC HOU_OUT_BACK
MOV HOU_XOUT,#0
HOU_OUT_BACK:
RET
;日检查
DAY_OUT:
MOV A,DAY
CJNE A,#00,DAY_OUT1
LJMP DAY_OUT2
DAY_OUT1:
LCALL DAYMAX
MOV A,DAY_MAX
ADD A,#1
MOV R0,A
MOV A,DAY
CLR C
SUBB A,R0
JC DAY_OUT_BACK
DAY_OUT2:
MOV DAY,#01
DAY_OUT_BACK:
RET


DAYMAX: ;日检查
LCALL YEAR_OUT
MOV A,YEAR_CHECK
JZ YES_LEAP_DAY1
NO_LEAP_DAY1:
MOV DPTR,#TABLE_NO_LEAP_DAY
LJMP DAY_MAX1
YES_LEAP_DAY1:
MOV DPTR,#TABLE_YES_LEAP_DAY
LJMP DAY_MAX2
DAY_MAX1:
MOV A,MONTH
MOVC A,@A+DPTR
MOV DAY_MAX,A
LJMP DAY_MAX_BACK
; ADD A,#1
; MOV R0,A
; MOV A,DAY
; CLR C
; SUBB A,R0
; JC DAY_OUT2
; MOV DAY,#30
DAY_MAX2:
MOV A,MONTH
MOVC A,@A+DPTR
MOV DAY_MAX,A
DAY_MAX_BACK:
RET

MONTH_OUT: ;月检查
CLR C
MOV A,MONTH
SUBB A,#13
JC MONTH_OUT1
MOV MONTH,#01
MONTH_OUT1:
MOV A,MONTH
JNZ MONTH_OUT_BACK
MOV MONTH,#01
MONTH_OUT_BACK:
LCALL DAY_OUT
RET

YEAR_OUT: ;闰年检查
MOV A,YEAR2
MOV B,#4
DIV AB
MOV A,B
JNZ NO_LEAP ;不能被4整除
MOV A,YEAR2
JNZ YES_LEAP
MOV A,YEAR1
MOV B,#4
DIV AB
MOV A,B
JZ YES_LEAP
NO_LEAP:
MOV YEAR_CHECK,#1
LJMP YEAR_OUT_BACK
YES_LEAP:
MOV YEAR_CHECK,#0
YEAR_OUT_BACK:
RET

TABLE_NO_LEAP_DAY:
DB 100,31,28,31,30,31,30,31,31,30,31,30,31
TABLE_YES_LEAP_DAY:
DB 100,31,29,31,30,31,30,31,31,30,31,30,31

/**************数码管的位选和段选*******************/
LED_SEL:
MOV DPTR,#8300H
MOVX @DPTR,A
RET
LED_SEG:
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV DPTR,#8200H
MOVX @DPTR,A
RET

/*******************延迟**********************/
DELAY:
MOV R6,#80
L1:
MOV R7,#8
L2:
DJNZ R7,L2
DJNZ R6,L1
RET

DELAY1:
MOV R6,#250
L11:
MOV R7,#250
L22:
DJNZ R7,L22
DJNZ R6,L11
RET

TABLE:
DB 3FH,06H,5BH,4FH
DB 66H,6DH,7DH,07H
DB 7FH,6FH
TABLE_PAO:
DB 0FFH,0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,7FH

/**************增加主函数****************/
CHANGE_ADD:
MOV A,NUM
CJNE A,#1,LP1

CHANGE_ADDSEC: ;秒加1
JB P3.4,LOOP
LP_ADDSEC:
LCALL DELAY
JNB P3.4,LP_ADDSEC
INC SEC
LCALL DELAY
MOV A,SEC
ADD A,NUM_KEY
SEC1:
MOV A,SEC
CJNE A,#60,LOOP
MOV SEC,#0
LJMP LOOP
LP1:
MOV A,NUM
CJNE A,#2,LP2

CHANGE_ADDMIN: ;分加1
JB P3.4,LOOP
LP_ADDMIN:
LCALL DELAY
JNB P3.4,LP_ADDMIN
INC MIN
MOV A,MIN
CJNE A,#60,LOOP
MOV MIN,#0
LJMP LOOP
LP2:
MOV A,NUM
CJNE A,#3,LOOP

CHANGE_ADDHOU: ;时加1
JB P3.4,LOOP
LP_ADDHOU:
LCALL DELAY
JNB P3.4,LP_ADDHOU
INC HOU
MOV A,HOU
CJNE A,#24,LP3
MOV HOU,#0
LP3:
MOV A,NUM
CJNE A,#4,LOOP
LOOP:
RET

/**************减少主函数**********************/
CHANGE_SUB:
MOV A,NUM
CJNE A,#1,LOP1

CHANGE_SUBSEC: ;秒减1
JB P3.5,LOOP1
LP_SUBSEC:
LCALL DELAY
JNB P3.5,LP_SUBSEC
MOV A,SEC
JZ LK1
DEC SEC
LJMP LOOP1
LK1:
MOV SEC,#59
LJMP LOOP1
LOP1:
MOV A,NUM
CJNE A,#2,LOP2

CHANGE_SUBMIN: ;分减1
JB P3.5,LOOP1
LP_SUBMIN:
LCALL DELAY
JNB P3.5,LP_SUBMIN
MOV A,MIN
JZ LK2
DEC MIN
LJMP LOOP1
LK2:
MOV MIN,#59
LJMP LOOP1
LOP2:
MOV A,NUM
CJNE A,#3,LOP3

CHANGE_SUBHOU: ;时减1
JB P3.5,LOOP1
LP_SUBHOU:
LCALL DELAY
JNB P3.5,LP_SUBHOU
MOV A,HOU
JZ LK3
DEC HOU
LJMP LOOP1
LK3:
MOV HOU,#23
LJMP LOOP1
LOP3:
MOV A,NUM
CJNE A,#0,LOOP1
LOOP1:
RET
END


推荐相关:

运用汇编语言设计的数字钟

运用汇编语言设计的数字钟运用汇编语言设计的数字钟隐藏>> 微机原理课程设计 题目名称: 姓名: 学号: 专业: 指导老师: 同组者: 数字钟 江汉大学物理与信息工程学院...


汇编数字钟_8位数码管显示

汇编数字钟 (8 位数码管显示) 这款数字钟是笔者亲自试验过的作品,电路图和程序都经过优化,供爱好者制作参考。 显示格式依然是 23-59-59(同样是小时十位如果为...


基于汇编语言的数字时钟

基于汇编语言数字时钟 - 一 摘要 单片计算机即单片微型计算机。(Single-Chip Microcomputer ),是集CPU ,RAM ,ROM , 定时,计数和多种接口于一体的微控...


基于51单片机汇编语言的数字钟课程设计

基于51单片机汇编语言数字钟课程设计 - 目录 一:概述………1 二:设计基本原理简介………...


可校时数字钟的汇编程序设计

可校时数字钟汇编程序设计_信息与通信_工程科技_专业资料。可校时数字钟汇编程序设计 毕业论文 分类号 (宋体小五号) 宋体小五号) UDC 密级 — 毕业设计可...


数字钟基于51单片机汇编语言设计

数字钟基于51单片机汇编语言设计 - 单片机数字时钟》 《51 单片机数字时钟》 课程设计报告 专班姓 业:电气工程及自动化 级:08 电气技师本科班 名: 指导教师: ...


基于51单片机汇编语言的数字钟课程设计报告(含有闹钟万...

基于51单片机汇编语言数字钟课程设计报告(含有闹钟万年历) - 单片微型计算机课程设计报告 多功能电子数字钟 姓名学号班级 指导教师 许伟敏 060301021124 电气二班 ...


数字时钟的汇编程序(2)

8位8段数码管做时钟汇编... 1页 1下载券 数字电子钟汇编程序 4页 2下载券...汇编源程序: INTCSR_BYTE0 EQU 9438H INTCSR_BYTE1 EQU 9439H INTCSR_BYTE...


基于51单片机汇编语言的数字钟课程设计报告(含有闹钟万...

28 word 文档 可自由复制编辑 单片微型计算机课程设计 基于汇编语言的电子数字钟 概述 一、概述 课程设计题目:电子数字钟 应用知识简介: ? 51 单片机 单片机又称...


汇编数字钟 8位数码管显示

汇编数字钟 8位数码管显示 - 位数码管显示 显示) 汇编数字钟 (8 位数码管显示 这款数字钟是笔者亲自试验过的作品,电路图和程序都经过优化,供爱好者制作参考。...

网站首页 | 网站地图
All rights reserved Powered by 学霸学习网 www.tceic.com
copyright ©right 2010-2021。
文档资料库内容来自网络,如有侵犯请联系客服。zhit325@126.com