MODE EQU 80H ; 8255 工作方式
PA8255 EQU 8000H ; 8255 PA 口输出地址
CTL8255 EQU 8C00H
ICW1 EQU 00010011B ; 单片 8259, 上升沿中断, 要写 ICW4
ICW2 EQU 00100000B ; 中断号为 20H
ICW4 EQU 00000001B ; 工作在 8086/88 方式
OCW1 EQU 00000000B ; 只响应 INT0 中断
CS8259A EQU 09000H ; 8259 地址
CS8259B EQU 09100H
CODE SEGMENT
ASSUME CS:CODE, DS: DATA,SS:STACK
ORG 00H
JMP IEnTER
ORG 800H
START:
MOV AX, DATA
MOV DS, AX
MOV AX, STACK
MOV SS, AX
MOV AX, TOP
MOV SP, AX
MOV DX, CTL8255
MOV AL, MODE
OUT DX, AL
CLI
PUSH DS
MOV AX ,0
MOV DS ,AX
MOV BX, 128 ;0X20 * 4 中断号
MOV AX, CODE
MOV CL, 4
SHL AX, CL ; X 16
ADD AX, OFFSET IEnTER
MOV [BX], AX ; 中断入口地址(段地址为 0)
MOV AX, 0
INC BX
INC BX
MOV [BX], AX ; 代码段地址为 0
POP DS
CALL IInIT
MOV AL, CNT ; 计数值初始为 0
MOV DX, PA8255
OUT DX, AL
STI
LP:
NOP
JMP LP
IInIT:
MOV DX,CS8259A
MOV AL,ICW1
OUT DX,AL
MOV DX,CS8259B
MOV AL,ICW2
OUT DX,AL
MOV AL,ICW4
OUT DX,AL
MOV AL,OCW1
OUT DX,AL
RET
IEnTER:
CLI
MOV DX,PA8255
DEC CNT
MOV AL,CNT
OUT DX,AL
MOV DX,CS8259A
MOV AL,20H
OUT DX,AL
STI
IRET
CODE ENDS
DATA SEGMENT
CNT DB 0FFH
DATA ENDS
STACK SEGMENT 'STACK'
STA DB 100 DUP(?)
TOP EQU LENGTH STA
STACK ENDS
END START
|