STACK SEGMENT STACK DB 200 DUP(0) STACK ENDS DATA SEGMENT TIME DB 00H,06H LEDTAL DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,73H,38H COUNT DW 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA,SS:STACK START:MOV AX,DATA MOV DS,AX
;填IR0中断向量 PUSH DS MOV AX,0000H MOV DS,AX MOV AX,OFFSET IRQ0 ADD AX,2000H MOV SI,0020H MOV [SI],AX MOV AX,0000H MOV SI,0022H MOV [SI],AX CLI POP DS IN AL,21H AND AL,0FEH;清除对IRQ0的中断 OUT 21H,AL
;填IR2中断向量 PUSH DS MOV AX,0000H MOV DS,AX MOV AX,OFFSET IRQ2 ADD AX,2000H MOV SI,0028H MOV [SI],AX MOV AX,0000H MOV SI,002AH MOV [SI],AX CLI POP DS IN AL,21H AND AL,0FBH;清除对IRQ2的中断 OUT 21H,AL
;填IRQ5中断向量 PUSH DS MOV AX,0000H MOV DS,AX MOV AX,OFFSET IRQ5 ADD AX,2000H MOV SI,0034H MOV [SI],AX MOV AX,0000H MOV SI,0036H MOV [SI],AX CLI POP DS IN AL,21H AND AL,0DFH;清除对IRQ5的中断 OUT 21H,AL
;填IRQ6中断向量 PUSH DS MOV AX,0000H MOV DS,AX MOV AX,OFFSET IRQ6 ADD AX,2000H MOV SI,0038H MOV [SI],AX MOV AX,0000H MOV SI,003AH MOV [SI],AX CLI POP DS IN AL,21H AND AL,0BFH;清除对IRQ6的中断 OUT 21H,AL
;填IRQ7中断向量 PUSH DS MOV AX,0000H MOV DS,AX MOV AX,OFFSET IRQ7 ADD AX,2000H MOV SI,003CH MOV [SI],AX MOV AX,0000H MOV SI,003EH MOV [SI],AX CLI POP DS IN AL,21H AND AL,7FH;清除对IRQ7的中断 OUT 21H,AL
;NORMAL表示正常情况下的倒计时 NORMAL:MOV AL,80H ;8255A初始化,A,B口方式0输出,C口输出 OUT 63H,AL
MOV AL,0B6H ;8253A初始化,计数器2方式3 OUT 43H,AL MOV AX,59500 OUT 42H,AL MOV AL,AH OUT 42H,AL
MOV COUNT,0 STI
FANS1:MOV AL,0B7H ;FANS1表示主干道绿灯,次干道红灯。LED显示60-5秒 OUT 61H,AL CALL DISP CMP COUNT,20 JL FANS1 MOV COUNT,0 MOV DI,OFFSET TIME MOV AL,[DI+1] CMP AL,00H JZ A5 MOV AL,[DI] CMP AL,00H JZ A6 DEC AL MOV [DI],AL JMP FANS1 A5: MOV AL,[DI] CMP AL,06H JZ A0 DEC AL MOV [DI],AL JMP FANS1 A6: MOV AL,9 MOV [DI],AL MOV AL,[DI+1] DEC AL MOV [DI+1],AL JMP FANS1 A0: MOV AL,05H MOV [DI],AL JMP FANS21 ;FANS21和FANS22表示次干道红灯,主干道隔一秒黄灯亮一次。LED显示5-1秒,再由1秒跳为45秒 FANS21:MOV AL,9DH ;FANS21表示主干道黄灯,次干道红灯 OUT 61H,AL CALL DISP CMP COUNT,20 JL FANS21 MOV COUNT,0 MOV DI,OFFSET TIME MOV AL,[DI] CMP AL,01H JZ A7 DEC AL MOV [DI],AL JMP FANS22 A7: MOV AL,4 MOV [DI+1],AL MOV AL,5 MOV [DI],AL JMP FANS3
FANS22:MOV AL,0BFH ;FANS22表示次干道红灯,主干道不亮灯 OUT 61H,AL CALL DISP CMP COUNT,20 JL FANS22 MOV COUNT,0 MOV DI,OFFSET TIME MOV AL,[DI] CMP AL,01H JZ A7 DEC AL MOV [DI],AL JMP FANS21
FANS3:MOV AL,7BH ;FANS3表示主干道红灯,次干道绿灯。LED显示45-5秒 OUT 61H,AL CALL DISP CMP COUNT,20 JL FANS3 MOV COUNT,0 MOV DI,OFFSET TIME MOV AL,[DI+1] CMP AL,00H JZ A8 MOV AL,[DI] CMP AL,00H JZ A9 DEC AL MOV [DI],AL JMP FANS3 A8: MOV AL,[DI] CMP AL,06H JZ A1 DEC AL MOV [DI],AL JMP FANS3 A9: MOV AL,9 MOV [DI],AL MOV AL,[DI+1] DEC AL MOV [DI+1],AL JMP FANS3 A1: MOV AL,05H MOV [DI],AL JMP FANS41
;FANS41和FANS42表示主干道红灯,次干道隔一秒黄灯亮一次。LED显示5-1秒,再由1秒跳为60秒 FANS41:MOV AL,6EH ;FANS41表示主干道红灯,次干道黄灯 OUT 61H,AL CALL DISP CMP COUNT,20 JL FANS41 MOV COUNT,0 MOV DI,OFFSET TIME MOV AL,[DI] CMP AL,01H JZ A10 DEC AL MOV [DI],AL JMP FANS42 A10: MOV AL,6 MOV [DI+1],AL MOV AL,0 MOV [DI],AL JMP FANS1
FANS42:MOV AL,7FH ;FANS41表示主干道红灯,次干道不亮灯 OUT 61H,AL CALL DISP CMP COUNT,20 JL FANS42 MOV COUNT,0 MOV DI,OFFSET TIME MOV AL,[DI] CMP AL,01H JZ A10 DEC AL MOV [DI],AL JMP FANS41 ;以上执行完105秒为一个循环,再跳回FANS1重新开始循环
;以下为遇到特殊情况的中断
;IRQ0的中断服务程序 IRQ0: MOV AL,20H ;遇到特殊情况,主干道一直保持通行(绿灯),次干道保持禁止通行(红灯)状态;LED显示'SP'表示'STOP'由按键KK1-控制 OUT 20H,AL L7: STI MOV DI,OFFSET TIME MOV AL,5 MOV [DI+1],AL MOV AL,10 MOV [DI],AL MOV AL,0B7H OUT 61H,AL CALL DISP JMP L7 IRET
;IRQ2的中断服务程序 IRQ2: MOV AL,20H ;在午夜车流量较少时,黄灯每隔0.5秒亮一次;LED显示'LS'表示'LOW SPEED'由按键KK2-控制 OUT 20H,AL STI MOV DI,OFFSET TIME MOV AL,11 MOV [DI+1],AL MOV AL,5 MOV [DI],AL L3: MOV COUNT,0 L0: MOV AL,0CCH OUT 61H,AL CALL DISP CMP COUNT,10 JL L0 MOV COUNT,0 L1: MOV AL,0FFH OUT 61H,AL CALL DISP CMP COUNT,10 JL L1 JMP L3 IRET
;IRQ5的中断服务程序 IRQ5: MOV AL,20H ;完成复位从45秒开始进入NORMAL状态由开关K0控制 OUT 20H,AL MOV DI,OFFSET TIME MOV AL,4 MOV [DI+1],AL MOV AL,5 MOV [DI],AL MOV AL,88H ;8255A初始化,A,B口方式0输出,C低四位口输出,高四位输入 OUT 63H,AL MOV AL,0B6H ;8253A初始化,计数器2方式3 OUT 43H,AL MOV AX,59500 OUT 42H,AL MOV AL,AH OUT 42H,AL MOV COUNT,0 STI JMP FANS3 IRET
;IRQ6的中断服务程序 IRQ6: MOV AL,20H ;完成复位从60秒开始进入NORMAL状态由开关K1控制 OUT 20H,AL MOV DI,OFFSET TIME MOV AL,6 MOV [DI+1],AL MOV AL,0 MOV [DI],AL JMP NORMAL IRET
;IRQ7的中断服务程序 IRQ7: INC COUNT ;由8253的OUT2控制,每隔50ms发一次中断,让COUNT值加1 MOV AL,20H OUT 20H,AL IRET
;显示子程序 DISP PROC NEAR MOV DI,OFFSET TIME MOV CL,0FEH ST1: MOV AL,CL TEST AL,04H ;判断显示到第几位,是否显示到最高位 JZ ED OUT 62H,AL ;C口低四位做输入用于选择哪个LED亮 ROL AL,01H ;让下一位LED灯管显示 MOV CL,AL MOV AL,[DI] MOV BX,OFFSET LEDTAL XLAT OUT 60H,AL ;A口做输出用于LED显示 CALL DELAY INC DI JMP ST1 ED: RET ;每个LED都显示完毕 DISP ENDP
;延时子程序 DELAY PROC NEAR PUSH CX MOV CX,2000 ;0.5ms,每0.5ms就切换一次LED灯管的显示,给人视觉各个LED是同时亮 WAIT: LOOP WAIT POP CX RET DELAY ENDP CODE ENDS END START
|