AD0 EQU 30H AD1 EQU 31H ORG 0000H LJMP MAIN ORG 0030H MAIN: MOV AD0,#0 MOV AD1,#0 MOV P1,#0DFH MOV B,#2 SETB PX0 MOV TCON,#00H MOV IE,#85H LOOP: MOV P2,#0DEH ;籄道绿灯,B道红灯16S MOV R1,#16 MOV R2,#16 AP1: MOV R7,#0EFH MOV AD0,#6 MOV AD1,#7 LCALL DISP DEC R2 MOV A,R2 MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A LCALL DELAY DJNZ R1,AP1 MOV R1,#6 MOV R2,#6 AP2: DEC R2 MOV A,R2 MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A CPL P2.5 ;籄道绿灯闪,B道红灯闪3S,共6S CPL P2.0 LCALL DELAY DJNZ R1,AP2 MOV P2,#0EDH ;籄、B道黄灯3S,共6S MOV R1,#6 MOV R2,#6 AP3: DEC R2 MOV A,R2 MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A LCALL DELAY DJNZ R1,AP3 MOV P2,#0F3H ;籄道红灯,B道绿灯10S MOV R1,#10 MOV R2,#10 BP1: DEC R2 MOV A,R2 MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A LCALL DELAY DJNZ R1,BP1 MOV R1,#6 MOV R2,#6 BP2: DEC R2 MOV A,R2 MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A CPL P2.2 ;A道红灯闪,B道绿灯闪3S,共6S CPL P2.3 LCALL DELAY DJNZ R1,BP2 MOV P2,#0EDH ;籄、B道黄灯3S,共6S MOV R1,#6 MOV R2,#6 BP3: DEC R2 MOV A,R2 MOV DPTR,#TABLE MOVC A,@A+DPTR MOV P0,A LCALL DELAY DJNZ R1,BP3 LJMP LOOP ORG 0200H DELAY:MOV R4,#80 ;1S的延时子程序 LP1: MOV R5,#50 LP2: MOV R6,#248 NOP LP3: DJNZ R6,LP3 DJNZ R5,LP2 DJNZ R4,LP1 RET
DELAY1:MOV R4,#1 ;1S的延时子程序 LP4: MOV R5,#50 LP5: MOV R6,#248 NOP LP6: DJNZ R6,LP6 DJNZ R5,LP5 DJNZ R4,LP4 RET
DISP: MOV DPTR,#TABLE MOV R0,#AD1 NEXT: MOV A,@R0 MOVC A,@A+DPTR MOV P0,A MOV P1,R7 ACALL DELAY1 DEC R0 MOV A,R7 RL A MOV R7,A CJNE R2,#0DFH,NEXT RET TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H DB 7FH,6FH,77H,7CH,39H,5EH,79H,71H END |