汇编写的交通灯,需要大家帮组。
[code]SECOND1 EQU30H
SECOND2 EQU31H
DBUF EQU40H
TEMP EQU 44H
GREEN1EQU P2.1
YELLOW1EQU P2.2
RED1EQU P2.3
GREEN2EQU P2.4
YELLOW2 EQU P2.5
RED2EQU P2.6
ORG 0
START:MOV TMOD,#01H;T0方式1
MOVTH0,#3CH;定时50Ms初值
MOV TL0,#0B0H
CLR TF0
SETB TR0
CLR A
MOV P1,A
MAIN:MOV R2,#20 ;设置50Ms计数器,产生1S
MOV R3,#31
MOV SECOND1,#34
MOV SECOND2,#34
LCALL DISPLAY
LCALL STATUS1
WAIT1:JNB TF0,WAIT1
CLRTF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R2,WAIT1
MOV R2,#20
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT1
MOV R2,#10
MOV R4,#2
MOV R3,#3
MOV SECOND1,#3
MOV SECOND2,#3
LCALL DISPLAY
WAIT2: LCALL STATUS2
JNB TF0,WAIT2
CLR TF0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ R4,WAIT2
CPL GREEN1
MOV R4,#2
DJNZ R2,WAIT2
MOV R2,#10
DEC SECOND1
DEC SECOND2
LCALL DISPLAY
DJNZ R3,WAIT2
STATUS1:
SETB GREEN1
CLR YELLOW1
CLR RED1
CLR GREEN2
CLR YELLOW2
SETB RED2
RET
STATUS2:
CLR YELLOW1
CLR RED1
CLR GREEN2
CLR YELLOW2
SETB RED2
RET
DISPLAY:MOV A,SECOND1
MOV B,#10
DIV AB
MOV DBUF+3,A
MOV A,B
MOV DBUF+2,A
MOV A,SECOND2
MOV B,#10
DIV AB
MOV DBUF+1,A
MOV A,B
MOV DBUF,A
MOV R0,#DBUF
MOV R1,#TEMP
MOV R2,#4
DP1:MOV DPTR,#SEG_TAB
MOV A,@R0
MOVC A,@A+DPTR
MOV @R1,A
INC R0
INC R1
DJNZ R2,DP1
MOV R0,#TEMP
MOV R1,#4
DP2: MOV R2,#8
MOV A,@R0
DP3:RLC A
MOV P3.2,C
CLR P3.3
SETB P3.3
DJNZ R2,DP3
INC R0
DJNZ R1,DP2
RET
SEG_TAB:DB 3FH,06H,5BH,4FH,66H,6DH
DB 7DH,07H,7FH,6FH
END