南邮微机实验 串行口的测试(查询发送,中断接收)

在查询方式的基础上,设计查询发送,中断方式接收的串行通信自发自收方式测试。

.586
DATA SEGMENT USE16
MESG DB 'HELLO'
LENS EQU $-MESG
OLD0B DD ?
DATA ENDS
CODE SEGMENT USE16
ASSUME CS:CODE,DS:DATA 
BEG:   MOV AX,DATA
	   MOV DS,AX
	   CLI                        ;关中断
	   CALL I8250
	   CALL I8259
	   CALL RD0B                  ;读中断向量
	   CALL WR0B 				  ;写中断向量
	   STI                        ;开中断
	   
	   MOV BX,OFFSET MESG
	   MOV CX,LENS

SCANT: MOV DX,2FDH
	   IN AL,DX
	   TEST AL,20H
	   JZ SCANT
	   
	   MOV DX,2F8H
	   MOV AL,[BX]
	   OUT DX,AL
	   INC BX
	   MOV EDX,0
SINEXT:DEC EDX
	   JNZ SINEXT
	   LOOP SCANT	   
	   
RETURN:CALL RESET
	   MOV AH,4CH
	   INT 21H   
	   
RECEIVE PROC
	   PUSH AX
	   PUSH DX
	   PUSH DS
	   MOV AX,DATA
	   MOV DS,AX
	   MOV DX,2F8H
	   IN AL,DX
	   AND AL,7FH
	   MOV AH,2
	   MOV DL,AL
	   INT 21H
	   JMP EXIT	   
EXIT:  MOV AL,20H      ;中断结束命令
	   OUT 20H,AL
	   POP DS
	   POP DX
	   POP AX
	   IRET
RECEIVE ENDP

I8250 PROC
	   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
	   IN AL,21H
	   AND AL,11101111B
	   OUT 21H,AL
	   RET
I8259 ENDP

RD0B PROC 
	   MOV AX,350CH
	   INT 21H
	   MOV WORD PTR OLD0B,BX
	   MOV WORD PTR OLD0B+2,ES
	   RET
RD0B ENDP

WR0B PROC
	   PUSH DS
	   MOV AX,CODE
	   MOV DS,AX
	   MOV DX,OFFSET RECEIVE
	   MOV AX,250CH
	   INT 21H
	   POP DS
	   RET
WR0B ENDP

RESET PROC
	   IN AL,21H
	   OR AL,00010000B
	   OUT 21H,AL
	   MOV AX,250CH
	   MOV DX,WORD PTR OLD0B
	   MOV DS,WORD PTR OLD0B+2
	   INT 21H
	   RET
RESET ENDP
CODE ENDS
	END BEG	      	   	   	   	    


你可能感兴趣的:(南邮微机实验 串行口的测试(查询发送,中断接收))