南郵マイクロマシン実験シリアルポートのテスト(クエリー送信、受信中断)

1794 ワード

クエリー方式に基づいて,クエリー送信,割り込み方式で受信するシリアル通信の自発的自己受信方式テストを設計した.
.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