|
请问下面这个程序定时器定时的时间是怎么算的,这是一个用模拟交通灯变化的程序。请高手指点一下,定时器的用法。
ORG 000BH
LJMP T0_INT
ORG 0100H
MAIN:
MOV SP, #60H
LCALL INIT
LCALL T0_INIT
LOOP:
JNB SECOND_FLAG,LOOP
LCALL STATUS_CHANGE
CLR SECOND_FLAG
SJMP LOOP
STATUS_CHANGE :
MOV A, STATUS_FLAG
ADD A,STATUS_FLAG
MOV DPTR,#STATUS_PROC_TABLE
JMP @A+DPTR
STATUS_PROC_TABLE:
AJMP STATUS1
AJMP STATUS2
AJMP STATUS3
AJMP STATUS4
AJMP STATUS5
AJMP STATUS6
STATUS1:
DJNZ SECOND_COUNT,STATUS1_EXIT
MOV SECOND_COUNT,#6
MOV STATUS_FLAG,#01H
STATUS1_EXIT:
RET
STATUS2:
DJNZ SECOND_COUNT, STATUS2_EXIT
MOV SECOND_COUNT,#4
MOV STATUS_FLAG,#02H
SETB SOUTH_RED
CLR SOUTH_YELLOW
SETB SOUTH_GREEN
CLR EAST_RED
SETB EAST_YELLOW
SETB EAST_GREEN
RET
STATUS2_EXIT:
CPL SOUTH_GREEN
RET
STATUS3:
DJNZ SECOND_COUNT, STATUS3_EXIT
MOV SECOND_COUNT,#40
MOV STATUS_FLAG,#03H
CLR SOUTH_RED
SETB SOUTH_YELLOW
SETB SOUTH_GREEN
SETB EAST_RED
SETB EAST_YELLOW
CLR EAST_GREEN
STATUS3_EXIT:
RET
STATUS4:
DJNZ SECOND_COUNT,STATUS4_EXIT
MOV SECOND_COUNT,#6
MOV STATUS_FLAG,#04H
STATUS4_EXIT:
RET
STATUS5:
DJNZ SECOND_COUNT, STATUS5_EXIT
MOV SECOND_COUNT,#4
MOV STATUS_FLAG,#05H
CLR SOUTH_RED
SETB SOUTH_YELLOW
SETB SOUTH_GREEN
SETB EAST_RED
CLR EAST_YELLOW
SETB EAST_GREEN
RET
STATUS5_EXIT:
CPL SOUTH_GREEN
RET
STATUS6:
DJNZ SECOND_COUNT, STATUS6_EXIT
MOV SECOND_COUNT,#40
MOV STATUS_FLAG,#06H
SETB SOUTH_RED
SETB SOUTH_YELLOW
CLR SOUTH_GREEN
CLR EAST_RED
SETB EAST_YELLOW
SETB EAST_GREEN
STATUS6_EXIT:
RET
INIT:
SETB SOUTH_RED
SETB SOUTH_YELLOW
CLR SOUTH_GREEN
CLR EAST_RED
SETB EAST_YELLOW
SETB EAST_GREEN
MOV TIME_COUNT0,#250
MOV TIME_COUNT1,#8
MOV SECOND_COUNT, #40
MOV STATUS_FLAG,#00H
CLR SECOND_FLAG
RET
T0_INT:
DJNZ TIME_COUNT0, T0_INT_EXIT
MOV TIME_COUNT0,#250
DJNZ TIME_COUNT1,T0_INT_EXIT
MOV TIME_COUNT1,#8
SETB SECOND_FLAG
T0_INT_EXIT:
RETI
T0_INIT:
MOV TMOD,#00000010B
MOV TL0,#06H
MOV TH0,#06H
MOV TCON,#00010000B
SETB EA
SETB ET0
RET
END
|
|