;***************************************************** ONE初始化
ORG 0
SJMP ONE
ORG 0003H
LJMP ELEVEN
ORG 000BH
LJMP NINE
ORG 001BH
LJMP TEN
ONE:LED12 EQU 30H ;数码管12显示缓存
LED34 EQU 31H ;数码管34显示缓存
LED56 EQU 32H ;数码管56显示缓存
COUNT EQU 33H ;定时器T0(用来走时)计数值存储器(计数中断20次到1秒)
COUNTS EQU 34H ;定时器T1(用来预置)计数值存储器(计数中断15次到预置值加一)
HOUR EQU 40H
MIN EQU 41H
SECOND EQU 22H
YEAR EQU 50H
MONTH EQU 23H
DAY EQU 52H
RH EQU 60H ;闹铃小时
RM EQU 61H ;闹铃分
RE EQU 62H ;闹铃使能
BM EQU 71H ;生日-月份
BD EQU 72H ;生日-天
MOV LED12,#0
MOV LED34,#0
MOV LED56,#0
MOV COUNT,#0
MOV COUNTS,#0
MOV HOUR,#0
MOV MIN,#0
MOV SECOND,#0
MOV YEAR,#0
MOV MONTH,#1
MOV DAY,#1
MOV RH,#0
MOV RM,#0
MOV RE,#0
MOV BM,#6
MOV BD,#1
BS BIT 00H
SS BIT 01H
GS BIT 02H
FC BIT 03H
NB BIT 04H
CLR BS
CLR SS
CLR GS
CLR FC
CLR NB
SETB 05H ;生日有效标志位
MOV IP,#02H;中断优先级:T0>INT0>T1
MOV TMOD,#11H
MOV IE,#8BH
SETB IT0
MOV TH0,#3CH ;50ms
MOV TL0,#0B0H
SETB TR0
MOV R1,#50 ;显示延时用
MOV R0,#0 ;显示延时用
;**************************************************** TWO检测开关号
TWO:MOV P0,#0FFH
JB P0.5,TWO1
MOV RE,#0A0H
SJMP TWO2
TWO1:MOV RE,#0A1H
TWO2:JB P0.0,TWO4
JB P0.1,TWO3
MOV LED12,HOUR
MOV LED34,MIN
MOV LED56,SECOND
SJMP THREE
TWO3:MOV LED12,YEAR
MOV LED34,MONTH
MOV LED56,DAY
SJMP THREE
TWO4:JB P0.1,TWO5
MOV LED12,RH
MOV LED34,RM
MOV LED56,RE
SJMP THREE
TWO5:MOV LED12,BM
MOV LED34,BD
MOV LED56,#0BCH
SJMP THREE
;************************************** THREE显示主程序(同时包含了闹铃,预置闪烁,闹铃功能)
THREE:MOV P1,#0
MOV P0,#0FFH
MOV DPTR,#TAB3
JNB SS,THREEB
SJMP THREEA
THREEB:LJMP THREE11
THREEA:JNB P0.3,THREE1
JNB GS,THREE1
LCALL TWELVE
SJMP THREE4
THREE1:MOV A,LED34
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE2:SETB P1.3
NOP
DJNZ R0,THREE2
CLR P1.3
MOV A,LED34
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE3:SETB P1.2
NOP
DJNZ R0,THREE3
CLR P1.2
JNB P0.2,THREE4
JNB GS,THREE4
LCALL TWELVE
SJMP THREE7
THREE4:MOV A,LED12
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE5:SETB P1.1
NOP
DJNZ R0,THREE5
CLR P1.1
MOV A,LED12
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE6:SETB P1.0
NOP
DJNZ R0,THREE6
CLR P1.0
JB P0.0,THREE7
JNB P0.1,THREE7
JB P0.3,THREE7
JNB P0.4,THREE7
JNB GS,THREE7
LCALL TWELVE
SJMP THREE10
THREE7:MOV A,LED56
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE8:SETB P1.5
NOP
DJNZ R0,THREE8
CLR P1.5
MOV A,LED56
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE9:SETB P1.4
NOP
DJNZ R0,THREE9
CLR P1.4
THREE10:DJNZ R1,TWOA
SJMP TWOB
TWOA:LJMP TWO
TWOB:MOV R1,#50
CPL GS
LJMP TWO
;**************************正常显示
THREE11:LCALL EIGHT
JB NB,THREE12
JNB BS,THREE12
SJMP SEVEN
THREE12:CLR NB
MOV A,LED34
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE13:SETB P1.3
NOP
DJNZ R0,THREE13
CLR P1.3
MOV A,LED34
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE14:SETB P1.2
NOP
DJNZ R0,THREE14
CLR P1.2
LCALL EIGHT
MOV A,LED12
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE15:SETB P1.1
NOP
DJNZ R0,THREE15
CLR P1.1
MOV A,LED12
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE16:SETB P1.0
NOP
DJNZ R0,THREE16
CLR P1.0
LCALL EIGHT
MOV A,LED56
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE17:SETB P1.5
NOP
DJNZ R0,THREE17
CLR P1.5
MOV A,LED56
SWAP A
ANL A,#0FH
MOVC A,@A+DPTR
MOV P2,A
THREE18:SETB P1.4
NOP
DJNZ R0,THREE18
CLR P1.4
LJMP TWO
TAB3:DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H,7CH,5EH
;0.1.2.3.4.5.6.7.8.9.-.b.d,的字形表"bd"在显示生日时间时显示在LED56
*************************************************
SEVEN:MOV P1,#01H
MOV P2,#76H
DJNZ R0,SEVEN
SEVEN1:MOV P1,#02H
MOV P2,#77H
DJNZ R0,SEVEN1
SEVEN2:MOV P1,#04H
MOV P2,#73H
DJNZ R0,SEVEN2
BSEVEN3:MOV P1,#08H
MOV P2,#73H
DJNZ R0,SEVEN3
SEVEN4:MOV P1,#10H
MOV P2,#6EH
DJNZ R0,SEVEN4
LJMP TWO
;*******************************************
EIGHT:MOV A,RE
CJNE A,#0A1H,EIGHT1
MOV A,MIN
CJNE A,RM,EIGHT1
MOV A,HOUR
CJNE A,RH,EIGHT1
SJMP EIGHT4
EIGHT1:MOV A,MIN
CJNE A,#59H,EIGHT7
MOV A,SECOND
CJNE A,#59H,EIGHT5
EIGHT2:MOV A,COUNT
CJNE A,#10,EIGHT3
EIGHT3:JC EIGHT7
EIGHT4:CPL P1.6
SETB NB
SJMP EIGHT7
EIGHT5:MOV A,SECOND
CJNE A,#51H,EIGHT6
EIGHT6:JC EIGHT7
JNB 10H,EIGHT7
JB FC,EIGHT7
SJMP EIGHT2
EIGHT7:CPL FC
RET
;******** NINE中断(T0)
NINE:MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
INC COUNT
MOV A,COUNT
CJNE A,#20,INEAA
SJMP AAA
NEAA:LJMP NINE1
AAA:MOV COUNT,#0
MOV A,SECOND
ADD A,#01
DA A ;
MOV SECOND,A
CJNE A,#60H,INEAA
MOV SECOND,#0
MOV A,MIN
ADD A,#01
DA A
MOV MIN,A
CJNE A,#60H,INEAA
MOV MIN,#0
MOV A,HOUR
ADD A,#01
DA A
MOV HOUR,A
CJNE A,#24H,INEAA
MOV HOUR,#0
MOV A,DAY
ADD A,#01
DA A
MOV DAY,A
;************************
MOV A,MONTH
CJNE A,#02H,TEN6A
MOV A,YEAR
ANL A,#0F0H
SWAP A
MOV B,#10
MUL AB
MOV 24H,A
MOV A,YEAR
ANL A,#0FH
ADD A,24H
JB ACC.0,TEN5A
JB ACC.1,TEN5A
MOV 24H,#01
MOV A,DAY
CJNE A,#30H,NINE1
MOV DAY,#1
SJMP NINE0
EN5A:MOV A,DAY
CJNE A,#29H,NINE1
MOV DAY,#1
SJMP NINE0
;**************判断大小月;
TEN6A:MOV A,MONTH
CJNE A,#08H,TEN7A
TEN7A:JC TEN9A
JB 18H,TEN8A
MOV A,DAY
CJNE A,#32H,NINE1
MOV DAY,#1
SJMP NINE0
TEN8A:MOV A,DAY
CJNE A,#31H,NINE1
MOV DAY,#1
SJMP NINE0
TEN9A:JNB 18H,TEN10A
MOV A,DAY
CJNE A,#32H,NINE1
MOV DAY,#1
SJMP NINE0
TEN10A:MOV A,DAY
CJNE A,#31H,NINE1
MOV DAY,#1
;*******************
NINE0:MOV A,MONTH
ADD A,#01
DA A
MOV MONTH,A
SETB 05H
CJNE A,#13H,NINE1
MOV MONTH,#1
MOV A,YEAR
ADD A,#01
DA A
MOV YEAR,A
NINE1:MOV A,MONTH
CJNE A,BM,NINE2
MOV A,DAY
CJNE A,BD,NINE2
JNB 05H,NINE2
SETB BS
NINE2:RETI
;**********************************TEN中断(T1)
TEN:MOV TH1,#3CH
MOV TL1,#0B0H
SETB TR1
INC COUNTS
MOV A,COUNTS
CJNE A,#15,TENE
MOV COUNTS,#0
JB P0.0,RBRB
JB P0.1,DAT
SJMP TIME
DAT: LJMP DATE
RBRB:JB P0.1,BDAT
LJMP RTIME
BDAT:LJMP BDATE
TENE:RETI
;**********************预置时间
TIME: JNB P0.3,TEN1
MOV A,MIN
ADD A,#01
DA A
MOV MIN,A
CJNE A,#60H,TENA
MOV MIN,#0
SJMP TENA
TEN1:JNB P0.2,TENA
MOV A,HOUR
ADD A,#01
DA A
MOV HOUR,A
CJNE A,#24H,TENA
MOV HOUR,#0
TENA:RETI
;******************预置日期
DATE:JNB P0.3,TEN3
MOV A,MONTH
ADD A,#01
DA A
MOV MONTH,A
CJNE A,#13H,TENB
MOV MONTH,#1
SJMP TENB
TEN3:JNB P0.2,TEN4
MOV A,YEAR
ADD A,#01
DA A
MOV YEAR,A
SJMP TENB
TEN4:JNB P0.4,TENB
MOV A,DAY
ADD A,#01
DA A
MOV DAY,A
;***************判断平闰年
MOV A,MONTH
CJNE A,#02H,TEN6
MOV A,YEAR
ANL A,#0F0H
SWAP A
MOV B,#10
MUL AB
MOV 24H,A
MOV A,YEAR
ANL A,#0FH
ADD A,24H
JB ACC.0,TEN5
JB ACC.1,TEN5
MOV A,DAY
CJNE A,#30H,TENB
MOV DAY,#1
SJMP TENB
TEN5:MOV A,DAY
CJNE A,#29H,TENB
MOV DAY,#1
SJMP TENB
;**************判断大小月
TEN6:CJNE A,#08H,TEN7
TEN7:JC TEN9
JB 18H,TEN8
MOV A,DAY
CJNE A,#32H,TENB
MOV DAY,#1
SJMP TENB
TEN8:MOV A,DAY
CJNE A,#31H,TENB
MOV DAY,#1
SJMP TENB
TEN9:JNB 18H,TEN10
MOV A,DAY
CJNE A,#32H,TENB
MOV DAY,#1
SJMP TENB
TEN10:MOV A,DAY
CJNE A,#31H,TENB
MOV DAY,#1
TENB: RETI
;**************************预置闹铃时间
RTIME:JNB P0.3,TEN12
MOV A,RM
ADD A,#01
DA A
MOV RM,A
CJNE A,#60H,TENC
MOV RM,#0
SJMP TENC
TEN12:JNB P0.2,TENC
MOV A,RH
ADD A,#01
DA A
MOV RH,A
CJNE A,#24H,TENC
MOV RH,#0
TENC:RETI
;************************
BDATE:JNB P0.3,TEN14
MOV A,BD
ADD A,#01
DA A
MOV BD,A
MOV A,BM
CJNE A,#02H,TEN15
MOV A,BD
CJNE A,#30H,TEND
MOV BD,#1
SJMP TEND
TEN15:CJNE A,#08H,TEN16
TEN16:JC TEN18
JB 18H,TEN17
MOV A,BD
CJNE A,#32H,TEND
MOV BD,#1
SJMP TEND
TEN17:MOV A,BD
CJNE A,#31H,TEND
MOV BD,#1
SJMP TEND
TEN18:JNB 18H,TEN19
MOV A,BD
CJNE A,#32H,TEND
MOV BD,#1
SJMP TEND
TEN19:MOV A,BD
CJNE A,#31H,TEND
MOV BD,#1
SJMP TEND
TEN14:JNB P0.2,TEND
MOV A,BM
ADD A,#01
DA A
MOV BM,A
CJNE A,#13H,TEND
MOV BM,#1
TEND:SETB 05H
RETI
;*******************************ELEVEN中断
ELEVEN:JNB SS,ELEVEN1
CLR SS
CLR TR1
SJMP ELEVEN3
ELEVEN1:JNB BS,ELEVEN2
CLR 05H
CLR BS
SJMP ELEVEN3
ELEVEN2:SETB SS
MOV TH1,#3CH
MOV TL1,#0B0H
SETB TR1
ELEVEN3:RETI
;***************************************************TWELVE 延时程序
TWELVE:MOV P1,#0
MOV P2,#0
DJNZ R0,TWELVE
TWELVE1:MOV P1,#0
MOV P2,#0
DJNZ R0,TWELVE1
RET
此帖出自
小平头技术问答
欢迎你简单介绍一下原因和解决方法哦
一周热门 更多>