实验三 8259中断优先级实验
1. 实验内容
基础部分
编写中断实验程序:
主程序通过 8255 的 PB 口输出 0FFH,使数据灯 D0~D7 全亮;
IR6中断服务程序使绿灯亮(红灯灭),延时一段时间后返回主程序;
IR7中断服务程序使红灯亮(绿灯灭),延时一段时间后返回主程序。
要求:
按单脉冲开关 KK1:响应IR6中断请求;
按单脉冲开关 KK2:响应IR7中断请求。
拓展部分
使用单脉冲开关控制 LED 灯的移动方向:
初始时 D7 点亮,其余灯熄灭;
任意时刻按下 KK1,点亮的 LED 灯立即向右循环移动;
任意时刻按下 KK2,点亮的 LED 灯立即向左循环移动。
2. 实验原理
在实验系统中,将主控制器的 IR6、IR7 以及从控制器的 IR1 开放出来供实验使用,主片 8259 的 IR4 供系统串口使用。
ICW1: 11H 上升沿触发,有 ICW4
ICW2: 08H
ICW3: 04H
ICW4: 07H 全嵌套非缓冲,自动结束中断,8086~Pentium CPU
OCW1: 允许IR7、IR6、IR4(键盘)中断
3. 连线
8255 连线见实验一
4. 实验代码
基础实验:
P8255A EQU 0640H
P8255B EQU 0642H
P8255C EQU 0644H
P8255MODE EQU 0646H
CODE SEGMENT
ASSUME CS:CODE
START:
MOV DX, P8255MODE
MOV AL, 90H
OUT DX, AL
MOV AL, 0FFH
MOV DX, P8255B
OUT DX, AL
LEA AX, MIR6 ;IR6中断向量填充
MOV SI, 0038H
MOV [ES:SI], AX
MOV AX, CS
MOV SI, 003AH
MOV [ES:SI], AX
LEA AX, MIR7 ;IR7中断向量填充
MOV SI, 003CH
MOV [ES:SI], AX
MOV AX, CS
MOV SI, 003EH
MOV [ES:SI], AX
CLI ;关中断
MOV AL, 11H ;ICW1:级联(主片),上升沿,有ICW4
OUT 20H, AL
MOV AL, 08H ;ICW2:
OUT 21H, AL
MOV AL, 04H ;ICW3:
OUT 21H, AL
MOV AL, 07H ;ICW4:全嵌套非缓冲,主片,自动结束中断,8086~Pentium CPU
OUT 21H, AL
MOV AL, 2FH ;OCW1 允许IR1中断
OUT 21H, AL
STI ;开中断
MAIN:
MOV AL, 0FFH
MOV DX, P8255B
OUT DX, AL
JMP MAIN
MIR6:
MOV AL, 0FH ;只点亮低四位
MOV DX, P8255B
OUT DX, AL
;MOV AL, 20H ;手动结束中断
;OUT 20H, AL ;自动模式下不需要
CALL DELAY ;等待一段时间
IRET
MIR7:
MOV AL, 0F0H ;只点亮高四位
MOV DX, P8255B
OUT DX, AL
;MOV AL, 20H
;OUT 20H, AL
CALL DELAY
IRET
DELAY:
PUSH CX
MOV CX,0FFFFH
LOOP $
POP CX
RET
CODE ENDS
END START
扩展实验:
1. 中断平级
P8255A EQU 0640H
P8255B EQU 0642H
P8255C EQU 0644H
P8255MODE EQU 0646H
DATA SEGMENT
SIGN DB 00H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, DS:DATA
START:
MOV AX, 0000H
MOV DS, AX
MOV DX, P8255MODE
MOV AL, 80H
OUT DX, AL
MOV DX, P8255B
MOV AL, 80H
OUT DX, AL
LEA AX, MIR6
MOV SI, 38H
MOV [ES:SI], AX
MOV AX, CS
MOV SI, 3AH
MOV [ES:SI], AX
LEA AX, MIR7
MOV SI, 3CH
MOV [ES:SI], AX
MOV AX, CS
MOV SI, 3EH
MOV [ES:SI], AX
CLI
MOV AL, 11H
OUT 20H, AL
MOV AL, 08H
OUT 21H, AL
MOV AL, 04H
OUT 21H, AL
MOV AL, 07H
OUT 21H, AL
MOV AL, 2FH
OUT 21H, AL
STI
MAIN:
CMP SIGN, 00H
JZ MAIN
CMP SIGN, 02H
JZ B2
B1:
MOV DX, P8255B
IN AL, DX
CMP AL, 01H
JZ BACK
ROR AL, 1
CALL DELAY
OUT DX, AL
JMP MAIN
B2:
MOV DX, P8255B
IN AL, DX
CMP AL, 80H
JZ BACK
ROL AL, 1
CALL DELAY
OUT DX,AL
JMP MAIN
BACK:
MOV SIGN, 00H
JMP MAIN
MIR6:
MOV SIGN, 01H
IRET
MIR7:
MOV SIGN, 02H
IRET
DELAY:
PUSH CX
MOV CX, 0FFFFH
LOOP $
POP CX
RET
CODE ENDS
END START
2. 中断嵌套(IR6可打断IR7)
P8255A EQU 0640H
P8255B EQU 0642H
P8255C EQU 0646H
P8255MODE EQU 0646H
CODE SEGMENT
ASSUME CS:CODE
START:
MOV AX, 0000H
MOV DS, AX
MOV DX, P8255MODE
MOV AL, 80H
OUT DX, AL
MOV DX, P8255B
MOV AL, 80H
OUT DX, AL
LEA AX, MIR6
MOV SI, 38H
MOV [ES:SI], AX
MOV AX, CS
MOV SI, 3AH
MOV [ES:SI], AX
LEA AX, MIR7
MOV SI, 3CH
MOV [ES:SI], AX
MOV AX, CS
MOV SI, 3EH
MOV [ES:SI], AX
CLI
MOV AL, 11H ;ICW1
OUT 20H, AL
MOV AL, 08H ;ICW2
OUT 21H, AL
MOV AL, 04H ;ICW3
OUT 21H, AL
MOV AL, 07HB ;ICW4
OUT 21H, AL
MOV AL, 2FH ;OCW1
OUT 21H, AL
STI
MAIN:
JMP MAIN
MIR6:
STI
PUSH AX
AA1:
MOV DX, P8255B
IN AL, DX
CMP AL, 01H
JZ EXIT6
ROR AL, 1
CALL DELAY
OUT DX, AL
JMP AA1
EXIT6:
POP AX
IRET
MIR7:
STI
PUSH AX
AA2:
MOV DX, P8255B
IN AL, DX
CMP AL, 80H
JZ EXIT7
ROL AL, 1
CALL DELAY
OUT DX, AL
JMP AA2
EXIT7:
POP AX
IRET
DELAY:
MOV CX, 0FFFFH
LOOP $
RET
CODE ENDS
END START