ORG 0000H
LJMP MAIN
ORG 000BH ;中断程序入口地址
LJMP TIME_0
ORG 0040H
MAIN:
MOV IE,#82H
MOV TCON , #10H
MOV TH0, #3CH
MOV TL0,#0AFH ;定时器T0初始化
MOV R1,#20 ;定时累积
RED:
MOV R2,#30 ;R2为时间设定
LOOP1:
MOV A,R2
JZ GREEN ;R2为0时转到GREEN处,改变亮灯状态
CALL SHOW ;调用显示子程序,显示30s
MOV P3,#0
SETB P3.0
LJMP LOOP1
GREEN:
MOV R2,#20
LOOP2:
MOV A,R2
JZ YELLOW ;R2为0时转到YELLOW 处,改变亮灯状态
CALL SHOW ;调用显示子程序,显示20s
MOV P3,#0
SETB P3.1
LJMP LOOP2
YELLOW:
MOV R2, #3 ;3s时间设定
MOV R0, #6
MOV P3, #00H
SETB P3.2 ;闪烁位
LOOP3:
MOV A, R2
JZ RED
MOV A, R0
JZ SHAN
dec R0
CALL SHOW
LJMP LOOP3
SHAN:
MOV R0, #6
CPL P3.2
LJMP LOOP3
SHOW:
MOV A,R2
MOV B,#10
DIV AB ;二进制转十进制
MOV DPTR ,#TABL
MOVC A,@A+DPTR ;查表
MOV P1,#0FFH
MOV P1,A
MOV P2,#00H
SETB P2.1
CALL DELY
MOV A,B
MOV DPTR, #TABL
MOVC A, @A+DPTR
MOV P1, #0FFH
MOV P1, A
MOV P2, #00H
SETB P2.2
CALL DELY
RET
DELY: ;延时子程序
D3: MOV R6, #100
D2: MOV R7, #10
D1: DJNZ R7, D1
DJNZ R6, D2
RET
TIME_0:
PUSH ACC ;保护现场
PUSH PSW
MOV TH0, #3CH
MOV TL0, #0AFH ;定时器T0初始化,定时50ms
DJNZ R1, OUT_T0 ;计时1s后做如下工作
MOV R1, #20
DEC R2
OUT_T0:
POP PSW
POP ACC
RETI
TABL:DB 0C0H, 0F9H, 0A4H, 0B0H, 99H, 92H, 82H, 0F8H, 80H, 90H
END