FLAG BIT 00H
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP MS100
ORG 0030H
MAIN:MOV R7,#10D;R7 is 1s/100ms=10D
CLR FLAG;initiallize
MOV TMOD,#01H
SETB ET0
MOV TL0,#5EH
MOV TH0,#1BH
SETB EA
LOOP:ACALL CY1;the main loop which lights up different light
ACALL CY2
ACALL CY3
ACALL CY2
SJMP LOOP
CY1:MOV P1,#11011011B;P1.2&P1.5light up while others faint
MOV R0,#30D;In R0 is how many seconds CY1 need
INLOOP1:MOV 40H,R0
ACALL SEGM
ACALL S1;CALL the 1s Delay program S1
DJNZ R0,INLOOP1
MOV R0,#30D;reset R0
RET
CY2:MOV P1,#11101101B;P1.1&P1.4light up while others faint
MOV R1,#10D;In R1 is how many seconds CY2 need
INLOOP2:MOV 40H,R1
ACALL SEGM
ACALL S1;CALL the 1s Delay program S1
DJNZ R1,INLOOP2
MOV R1,#10D;reset R1
RET
CY3:MOV P1,#11110110B;P1.0&P1.3light up while others faint
MOV R2,#30D;In R2 is how many seconds CY3 need
INLOOP3:MOV 40H,R2
ACALL SEGM
ACALL S1;CALL the 1s Delay program S1
DJNZ R2,INLOOP3
MOV R2,#30D;reset R2
RET
S1:SETB TR0;open the timer
S11:MOV P2,#40H
MOV P0,41H
NOP
NOP
MOV P0,#0FFH
MOV P2,#80H
MOV P0,42H
NOP
NOP
MOV P0,#0FFH
JNB FLAG,S11;if FLAG!=0,which means 100ms hasn’t reached
CLR FLAG;clear the mark
DJNZ R7,S11;if R7!=0,jump into the circulation S11 to delay another 100ms
CLR TR0;close the timer
MOV R7,#10;a second has passed,so reset R7
RET
MS100:CLR TR0;close the timer
MOV TL0,#0B0H;reset the intial value of TL&TH
MOV TH0,#3CH
SETB FLAG;set the mark which means pass 100ms
SETB TR0;open the timer
RETI
SEGM:MOV DPTR,#1000H
MOV A,40H
MOV B,#10D
DIV AB
MOVC A,@A+DPTR
MOV 41H,A
MOV A,B
MOVC A,@A+DPTR
MOV 42H,A
RET
ORG 1000H
TAB:DB 0C0H,0F9H,0A4H,0B0H,099H,092H,082H,0F8H,080H,090H
END