单片机STC89C52RC实现时钟(汇编语言)
基于STC89C52制作时钟(汇编)7.27
完整代码:
;REGISTER_GROUP0:R0,R1,R2,R3,R4,R5 R6->M R7->S
;REGISTER_GROUP2:R0->H R3计数=20D R5R6:延时
ORG 0000H
LJMP 0030H
ORG 000BH
LJMP T0INTERUPT
ORG 0030H
INI_TIME: ;开机初始化时间
SETB RS1
MOV R0,#00D;H
CLR RS1
MOV R6,#00D;M
MOV R7,#00D;S
LED_INIT:
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#38H
CLR P2.5
LCALL DELAY
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#08H
CLR P2.5
LCALL DELAY
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#01H
CLR P2.5
LCALL DELAY
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#06H
CLR P2.5
LCALL DELAY
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#0CH
CLR P2.5
LCALL DELAY
T0INIT:
MOV TMOD,#01H;50MS
MOV TH0,#4CH
MOV TL0,#00H
SETB EA
SETB ET0
SETB TR0
DISPLAY:
;LCALL TRANSFER
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#83H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,R0;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#84H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,R1;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#85H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,#68H;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#86H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,R2;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#87H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,R3;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#88H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,#6DH;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#89H;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,R4;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#8AH;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,R5;CHAR
CLR P2.5
LCALL BUSY
CLR P1.0
CLR P1.1
SETB P2.5
MOV P0,#8BH;#0C0H
CLR P2.5
LCALL BUSY
SETB P1.0
CLR P1.1
SETB P2.5
MOV P0,#73H;CHAR
CLR P2.5
LJMP DISPLAY
BUSY:
MOV P0,#0FFH
CLR P1.0
SETB P1.1
SETB P2.5
NOP
NOP
NOP
NOP
NOP
MOV A,P0
ANL A,#80H
JNZ BUSY
RET
DELAY:
SETB RS1
MOV R6,#0FH
DL0:
MOV R5,#98H
DJNZ R5,$
DJNZ R6,DL0
CLR RS1
RET
T0INTERUPT:
MOV TH0,#4CH
MOV TL0,#00H
SETB RS1
DJNZ R3,C1
MOV R3,#20D
CLR RS1
INC R7
CJNE R7,#60D,C1;不相等转移
MOV R7,#00D
INC R6
CJNE R6,#60D,C1
MOV R6,#00H
SETB RS1
INC R0
CJNE R0,#24D,C1
MOV R0,#00D
C1: LCALL TRANSFER
CLR RS1
RETI
TRANSFER:
SETB RS1
MOV A,R0
MOV B,#10D
DIV AB
CLR RS1
MOV R0,A
MOV A,B
MOV R1,A
MOV A,R6
MOV B,#10D
DIV AB
MOV R2,A
MOV A,B
MOV R3,A
MOV A,R7
MOV B,#10D
DIV AB
MOV R4,A
MOV A,B
MOV R5,A
MOV A,R0
ADD A,#30H
MOV R0,A
MOV A,R1
ADD A,#30H
MOV R1,A
MOV A,R2
ADD A,#30H
MOV R2,A
MOV A,R3
ADD A,#30H
MOV R3,A
MOV A,R4
ADD A,#30H
MOV R4,A
MOV A,R5
ADD A,#30H
MOV R5,A
RET
END