加载程序后数码管,无显示,30--32H存放秒。分。时。经BCD转化,秒数值放在40H,41H。分放在43,44.时放在46,47H。//42H,45H
放#10,对应表格DB第十一个数,数码管显示——,K1 ,K1调分和时,定时器1做整点报时,39H为定时报警一分钟计数,P2.4接蜂鸣器,P2.5LED一秒一下闪亮
K1 BIT P1.0
K2 BIT P1.1
ORG 0000H
AJMP START
ORG 000BH
AJMP DS0
ORG 001BH
AJMP DS1
ORG 0030H
START: CLR A
MOV R0,#7FH //初始化清零
CL: MOV @R0,A
DJNZ R1,CL
MOV TMOD,#11H
MOV TH0,#3CH
MOV TL0,#0B0H
MOV TH1,#0FEH
MOV TL1,#00H
SETB EA //开定时中断0
SETB ET0
SETB ET1
SETB TR0
MOV R2,#14H //计时次数
MOV 42H,#0AH // 显示--的DB位置
MOV 45H,#0AH // 显示--的DB位置
MOV 31H,#3BH
MAIN: LCALL KEY
LCALL ZH //转化
LCALL DIS //调显示
AJMP MAIN
KEY: JNB K1,KEY1 //分。时调时
JNB K2,KEY2
RET
KEY1: LCALL DEL
JB K1,KEYEND //分加一
JNB K1,$
INC 31H
MOV A,31H
CJNE A,#3CH,KEYEND
MOV 31H,#00H
KEYEND: RET
KEY2: LCALL DEL
JB K2,KEYEND //时加一
JNB K2,$
INC 32H
MOV A,32H
CJNE A,#18H,KEYEND
MOV 32H,#00H
RET
DIS: MOV R0,#40H //显示放置初地址
MOV 36H,#7FH //秒钟位码地址
MOV R4,#08H //显示次数
DIS1: MOV A,@R0
MOV DPTR,#DUAN
MOVC A,@A+DPTR
MOV P0,A
SETB P2.2
CLR P2.2
MOV A,36H
MOV P0,A
SETB P2.3
//LCALL DEL
CLR P2.3
LCALL DELL
INC R0
RR A
MOV 36H,A
DJNZ R4,DIS1
RET
ZH: MOV R0,#30H
MOV R3,#03H //时分秒转化,秒钟由30H转到40 41,分由31转到43 44,
MOV R1,#40H //时由32H转到46H 47H
ZH1: MOV A,@R0
MOV B,#10
DIV AB
XCH A,B
MOV @R1,A
INC R1
MOV @R1,B
INC R0
INC R1
INC R1
DJNZ R3 ,ZH1
RET
DS0: PUSH ACC
PUSH PSW
SETB P2.5
CLR ET0
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B3H
SETB TR0
DJNZ R2,TC
MOV R2,#14H
CLR P2.5
INC 30H
MOV A,30H
CJNE A,#3CH,TC
MOV 30H,#00H
INC 38H
MOV A,38H
MOV 39H,A
CJNE A,#02H,DS00
MOV 38H,#00H
DS00: INC 31H
MOV A,31H
CJNE A,#3CH,TC
MOV 31H,#00H
SETB TR1
INC 32H
MOV A,32H
CJNE A,#18H,TC
MOV 32H,#00H
MOV 31H,#00H
MOV 30H,#00H
TC: POP PSW
POP ACC
SETB ET0
RE
ti
DS1: CLR TR1
//CLR ET1
CLR P2.4
MOV TH1,#0FEH
MOV TL1,#00H
SETB TR1
SETB P2.4
MOV A,35H
MOV 35H,A
CJNE A,#02H,DS1END
MOV 35H,#00H
//SETB ET1
CLR TR1
DS1END: RETI
DUAN: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H
DEL: MOV R7,#50
DEL1: MOV R6,#100
DJNZ R6,$
DJNZ R7,DEL1
RET
DELL: MOV R7,#10
DELL1: MOV R6,#100
DJNZ R6,$
DJNZ R7,DELL1
RET
END
-
在变量使用上没发现问题,估计不用用定时器做报警
一周热门 更多>