四 源程序
1单机通信:
DATA SEGMENT
STRING DB 'TRANSLATE ','$' STRING1 DB 'RECEIVE ','$' STRING2 DB 0DH,0AH,'$'
DATA ENDS
STACK SEGMENT STACK 'SATCK' DB 100 DUP(?)
STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK
;延时子程序
DELAY PROC NEAR PUSH CX
MOV CX,100H WAIT0: LOOP WAIT0 POP CX RET DELAY ENDP
START: MOV AX,DATA MOV DS,AX ;8254初始化
MOV DX,283H
MOV AL,16H ;计数器0,只读低字节,方式0,二进制 OUT DX,AL CALL DELAY
MOV DX,280H ;计数器0,初值为52 MOV AL,34H OUT DX,AL CALL DELAY ;8251初始化
MOV DX,2B9H ;控制端口 MOV AL,40H ;内部复位命令 OUT DX,AL NOP
CALL DELAY
MOV AL,5EH ;方式控制字 OUT DX,AL
MOV AL,37H ;命令控制字 OUT DX,AL CALL DELAY ;发送数据
GOON: MOV DX,2B9H ;读状态字 IN AL,DX TEST AL,01H JZ GOON
;显示提示语句
MOV AH,09H
MOV DX,OFFSET STRING INT 21H
MOV AH,01H INT 21H ;检测是否为ESC键 CMP AL,1BH JZ EXIT INC AL;加1
MOV DX,2B8H OUT DX,AL ;接收数据
RECEIVE: MOV DX,2B9H IN AL,DX TEST AL,02H JZ RECEIVE
;显示提示语句
MOV AH,09H
MOV DX,OFFSET STRING2 INT 21H MOV AH,09H
MOV DX,OFFSET STRING1 INT 21H
MOV DX,2B8H
IN AL,DX MOV DL,AL
MOV AH,02H ;显示接收的数据 INT 21H MOV AH,09H
MOV DX,OFFSET STRING2 INT 21H
JMP GOON
EXIT: MOV AX,4C00H
INT 21H
CODE ENDS
END START
双机通信
DATA SEGMENT
STRING DB 'Please put in a word',0DH,0AH,'$' TABLE DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H,00H ;数码管显示
NUM DB 70H,0B0H,0D0H,0E0H DATA ENDS
STACK SEGMENT STACK 'SATCK' DB 100 DUP(?) STACK ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA,SS:STACK ;延时子程序
DELAY PROC NEAR PUSH CX
MOV CX,100H WAIT0: LOOP WAIT0 POP CX RET DELAY ENDP ;延时子程序2
DELAY1 PROC NEAR
PUSH CX PUSH BX
MOV BX,250 LP2: MOV CX,0FFFFH LP1: LOOP LP1 DEC BX JNZ LP2 POP BX POP CX RET DELAY1 ENDP
input PROC NEAR
LOOP1: MOV DX,28AH
mov al,01111111b out dx,al in al,dx
and al,00001111b cmp al,00000111b
jz case0
CMP AL,00001011B JZ CASE1
CMP AL,00001101B JZ CASE2
CMP AL,00001110B JZ CASE3
mov al,10111111b out dx,al in al,dx
and al,00001111b cmp al,00000111b jz case4
CMP AL,00001011B JZ CASE5
CMP AL,00001101B JZ CASE6
CMP AL,00001110B JZ CASE7
mov al,11011111b out dx,al in al,dx
and al,00001111b cmp al,00000111b jz case8
CMP AL,00001011B JZ CASE9
CMP AL,00001101B JZ CASE10
CMP AL,00001110B JZ CASE11
mov al,11101111b out dx,al in al,dx
and al,00001111b cmp al,00000111b jz case12
CMP AL,00001011B JZ CASE13
CMP AL,00001101B JZ CASE14
CMP AL,00001110B JZ CASE15 MOV AL,16