实验名称: 测试微机系统串行口(实验教程P109 实验6.10,可参考课本341页例9.3)
实验环境:PC系列机,汇编语言开发工具TASM5.0或 未来汇编
实验目的:
学习汇编语言程序设计的方法;掌握8250异步串行接口芯片的工作原理;掌握串行通信程序的设计。
实验内容:
.586
DATA SEGMENT USE16
OLD0B DD ?
FLAG DB 0
DATA ENDS
CODE SEGMENT USE16
ASSUME CS:CODE,DS:DATA
BEG: MOV AX,DATA
MOV DS,AX
CLI ;关中断
CALL I8250 ;主串口初始化
CALL I8259 ;开放主8259A辅串口中断
CALL RD0B ;读中断向量
CALL WR0B ;写中断向量
STI ;开中断
SCANT: CMP FLAG,-1
JE RETURN
MOV DX,2FDH
IN AL,DX
TEST AL,20H ;发送保持寄存器是否为空
JZ SCANT
MOV AH,1
INT 16H
JZ SCANT
MOV AH,0
INT 16H
AND AL,7FH
MOV DX,2F8H
OUT DX,AL
CMP AL,1BH
JNE SCANT
TWAIT: MOV DX,2F8H
IN AL,DX
TEST AL,40H
JZ TWAIT
RETURN: CALL RESET
MOV AH,4CH
INT 21H
RECEIVE PROC ;仅删除判断'ESC'字符的内容
PUSH AX
PUSH DX
PUSH DS
MOV AX,DATA
MOV DS,AX
MOV DX,2F8H
IN AL,DX
AND AL,7FH
CMP AL,1BH
JE NEXT
MOV AH,2
MOV DL,AL
INT 21H
JMP EXIT
NEXT: MOV FLAG,-1
EXIT: MOV AL,20H ;中断结束命令
OUT 20H,AL
POP DS
POP DX
POP AX
IRET
RECEIVE ENDP
I8250 PROC ;一样,仅修改3FBH为2FBH
MOV DX,2FBH
MOV AL,80H
OUT DX,AL
MOV DX,2F9H
MOV AL,0
OUT DX,AL
MOV DX,2F8H
MOV AL,60H
OUT DX,AL
MOV DX,2FBH
MOV AL,03H
OUT DX,AL
MOV DX,2F9H
MOV AL,01H
OUT DX,AL
MOV DX,2FCH
MOV AL,08H
OUT DX,AL
RET
I8250 ENDP
I8259 PROC ;D3 = 1
IN AL,21H
AND AL,11110111B
OUT 21H,AL
RET
I8259 ENDP
RD0B PROC ;修改名称OLD0C为OLD0B
MOV AX,350BH
INT 21H
MOV WORD PTR OLD0B,BX
MOV WORD PTR OLD0B+2,ES
RET
RD0B ENDP
WR0B PROC ;修改名称WR0C为WR0B 250BH
PUSH DS
MOV AX,CODE
MOV DS,AX
MOV DX,OFFSET RECEIVE
MOV AX,250BH
INT 21H
POP DS
RET
WR0B ENDP
RESET PROC ;一样
IN AL,21H
OR AL,00001000B
OUT 21H,AL
MOV AX,250BH
MOV DX,WORD PTR OLD0B
MOV DS,WORD PTR OLD0B+2
INT 21H
RET
RESET ENDP
CODE ENDS
END BEG