ORG0000H
LJMPSTART
ORG0003H
LJMPINT0_S
ORG0013H
LJMPINT1_S
ORG0100H
START:
;初始化
MOVP0,#0FFH
MOVP1,#0FFH
MOVP2,#0FFH
MOVP3,#0FFH
MOVR0,#20;定時次數20次1秒
MOVR1,#11;定時次數10次1秒定時10秒
MOVR2,#0
MOVR3,#1
CLRP1.4
CLRP1.5
CLRP2.0
CLRP2.1
MOVTMOD,#01H
LOP:
MOVTH0,#3CH
MOVTL0,#0B0H
SETBTR0
AGA1:
JBCTF0,K1
SJMPAGA1
K1:
DJNZR0,LOP
MOVR0,#20
INCR2
CJNER2,#6,NEXT
SETBEX0
SETBEX1
SETBEA
NEXT:
MOVA,R1
MOVDPTR,#TAB1
MOVCA,@A+DPTR
MOVP0,A
SETBP3.5
CLRP3.4
LCALLDELAY1
MOVA,R1
MOVDPTR,#TAB0
MOVCA,@A+DPTR
MOVP0,A
SETBP3.4
CLRP3.5
DJNZR1,LOP
MOVR1,#11
MOVR2,#0
;10秒到南北黃閃亮紅東西亮綠
CJNER3,#1,S1
INCR3
MOVR3,#2
LCALLFIRST
LJMPLOP
;第二次10秒到東西黃閃亮紅南北亮綠
S1:
CJNER3,#2,OUT
MOVR3,#1
LCALLSECOND
OUT:
LJMPLOP
;--------------------------------------------
;外部中斷0
;東西黃閃亮紅南北亮綠
INT0_S:
LCALLDELAY
JNBP3.4,EXIT1
CLREA
LCALLSECOND
EXIT1:
//MOVR3,#1
RETI
;-------------------------------------------
;外部中斷1
;南北黃閃亮紅東西亮綠
INT1_S:
LCALLDELAY
JNBP3.5,EXIT2
CLREA
LCALLFIRST
EXIT2:
//MOVR3,#2
RETI
;-------------------------------------------
;南北黃閃亮紅東西亮綠
FIRST:
MOVR4,#3
YELLOW0:
CLRP1.2
CLRP1.3
LCALLDELAY1
SETBP1.2
SETBP1.3
LCALLDELAY1
DJNZR4,YELLOW0
SETBP1.4
SETBP1.5
CLRP1.0
CLRP1.1
SETBP2.0
SETBP2.1
CLRP2.4
CLRP2.5
RET
;----------------------------------------------
;東西黃閃亮紅南北亮綠
SECOND:
MOVR4,#3
YELLOW1:
CLRP2.2
CLRP2.3
LCALLDELAY1
SETBP2.2
SETBP2.3
LCALLDELAY1
DJNZR4,YELLOW1
SETBP2.4
SETBP2.5
CLRP2.0
CLRP2.1
SETBP1.0
SETBP1.1
CLRP1.4
CLRP1.5
RET
;----------------------------------------------
DELAY:
MOVR6,#20H
DL11:MOVR7,#7DH
DL22:NOP
NOP
DJNZR7,DL22
DJNZR6,DL11
RET
;----------------------------------------------
DELAY1:
MOVR6,#0FFH
DL1:MOVR7,#066H
DL2:NOP
NOP
DJNZR7,DL2
DJNZR6,DL1
RET
TAB0:DB0C0H,0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
TAB1:DB0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0C0H,0F9H
END