ORG 0000H
LJMP START
ORG 0003H
LJMP INT0_S
ORG 0013H
LJMP INT1_S
ORG 0100H
START:
;初始化
MOV P0,#0FFH
MOV P1,#0FFH
MOV P2,#0FFH
MOV P3,#0FFH
MOV R0,#20 ;定時次數 20次1秒
MOV R1,#11 ;定時次數 10次1秒定時10秒
MOV R2,#0
MOV R3,#1
CLR P1.4
CLR P1.5
CLR P2.0
CLR P2.1
MOV TMOD,#01H
LOP:
MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
AGA1:
JBC TF0,K1
SJMP AGA1
K1:
DJNZ R0,LOP
MOV R0,#20
INC R2
CJNE R2,#6,NEXT
SETB EX0
SETB EX1
SETB EA
NEXT:
MOV A,R1
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P0,A
SETB P3.5
CLR P3.4
LCALL DELAY1
MOV DPTR,#TAB0
SETB P3.4
CLR P3.5
DJNZ R1,LOP
MOV R1,#11
;10秒到 南北黃閃亮紅 東西亮綠
CJNE R3,#1,S1
INC R3
MOV R3,#2
LCALL FIRST
LJMP LOP
;第二次10秒到 東西黃閃亮紅 南北亮綠
S1:
CJNE R3,#2,OUT
LCALL SECOND
OUT:
;--------------------------------------------
;外部中斷0
;東西黃閃亮紅 南北亮綠
INT0_S:
LCALL DELAY
JNB P3.4,EXIT1
CLR EA
EXIT1:
//MOV R3,#1
RETI
;-------------------------------------------
;外部中斷1
;南北黃閃亮紅 東西亮綠
INT1_S:
JNB P3.5,EXIT2
EXIT2:
//MOV R3,#2
FIRST:
MOV R4,#3
YELLOW0:
CLR P1.2
CLR P1.3
SETB P1.2
SETB P1.3
DJNZ R4,YELLOW0
SETB P1.4
SETB P1.5
CLR P1.0
CLR P1.1
SETB P2.0
SETB P2.1
CLR P2.4
CLR P2.5
RET
;----------------------------------------------
SECOND:
YELLOW1:
CLR P2.2
CLR P2.3
SETB P2.2
SETB P2.3
DJNZ R4,YELLOW1
SETB P2.4
SETB P2.5
SETB P1.0
SETB P1.1
DELAY:
MOV R6,#20H
DL11:MOV R7,#7DH
DL22:NOP
NOP
DJNZ R7,DL22
DJNZ R6,DL11
DELAY1:
MOV R6,#0FFH
DL1:MOV R7,#066H
DL2:NOP
DJNZ R7,DL2
DJNZ R6,DL1
TAB0: DB 0C0H,0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
TAB1: DB 0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0F9H
END
ORG 0000H
LJMP START
ORG 0003H
LJMP INT0_S
ORG 0013H
LJMP INT1_S
ORG 0100H
START:
;初始化
MOV P0,#0FFH
MOV P1,#0FFH
MOV P2,#0FFH
MOV P3,#0FFH
MOV R0,#20 ;定時次數 20次1秒
MOV R1,#11 ;定時次數 10次1秒定時10秒
MOV R2,#0
MOV R3,#1
CLR P1.4
CLR P1.5
CLR P2.0
CLR P2.1
MOV TMOD,#01H
LOP:
MOV TH0,#3CH
MOV TL0,#0B0H
SETB TR0
AGA1:
JBC TF0,K1
SJMP AGA1
K1:
DJNZ R0,LOP
MOV R0,#20
INC R2
CJNE R2,#6,NEXT
SETB EX0
SETB EX1
SETB EA
NEXT:
MOV A,R1
MOV DPTR,#TAB1
MOVC A,@A+DPTR
MOV P0,A
SETB P3.5
CLR P3.4
LCALL DELAY1
MOV A,R1
MOV DPTR,#TAB0
MOVC A,@A+DPTR
MOV P0,A
SETB P3.4
CLR P3.5
DJNZ R1,LOP
MOV R1,#11
MOV R2,#0
;10秒到 南北黃閃亮紅 東西亮綠
CJNE R3,#1,S1
INC R3
MOV R3,#2
LCALL FIRST
LJMP LOP
;第二次10秒到 東西黃閃亮紅 南北亮綠
S1:
CJNE R3,#2,OUT
MOV R3,#1
LCALL SECOND
OUT:
LJMP LOP
;--------------------------------------------
;外部中斷0
;東西黃閃亮紅 南北亮綠
INT0_S:
LCALL DELAY
JNB P3.4,EXIT1
CLR EA
LCALL SECOND
EXIT1:
//MOV R3,#1
RETI
;-------------------------------------------
;外部中斷1
;南北黃閃亮紅 東西亮綠
INT1_S:
LCALL DELAY
JNB P3.5,EXIT2
CLR EA
LCALL FIRST
EXIT2:
//MOV R3,#2
RETI
;-------------------------------------------
;南北黃閃亮紅 東西亮綠
FIRST:
MOV R4,#3
YELLOW0:
CLR P1.2
CLR P1.3
LCALL DELAY1
SETB P1.2
SETB P1.3
LCALL DELAY1
DJNZ R4,YELLOW0
SETB P1.4
SETB P1.5
CLR P1.0
CLR P1.1
SETB P2.0
SETB P2.1
CLR P2.4
CLR P2.5
RET
;----------------------------------------------
;東西黃閃亮紅 南北亮綠
SECOND:
MOV R4,#3
YELLOW1:
CLR P2.2
CLR P2.3
LCALL DELAY1
SETB P2.2
SETB P2.3
LCALL DELAY1
DJNZ R4,YELLOW1
SETB P2.4
SETB P2.5
CLR P2.0
CLR P2.1
SETB P1.0
SETB P1.1
CLR P1.4
CLR P1.5
RET
;----------------------------------------------
DELAY:
MOV R6,#20H
DL11:MOV R7,#7DH
DL22:NOP
NOP
DJNZ R7,DL22
DJNZ R6,DL11
RET
;----------------------------------------------
DELAY1:
MOV R6,#0FFH
DL1:MOV R7,#066H
DL2:NOP
NOP
DJNZ R7,DL2
DJNZ R6,DL1
RET
TAB0: DB 0C0H,0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
TAB1: DB 0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0F9H
END