?? receive.asm
字號(hào):
data segment
dis0 db '+-----------------------------------------------------------------------+',0dh,0ah
db '| Serial Test Receive Terminal |',0dh,0ah
db '| ^-^ ^-^ ^-^ |',0dh,0ah
db '+-----------------------------------------------------------------------+',0dh,0ah,'$'
dis1 db 0dh,0ah,'The data you have received are: ',0dh,0ah,'$'
dis2 db 0dh,0ah,'Do you want to continue? (y\n)',0dh,0ah,'$'
dis3 db 0dh,0ah,'Receive Successfully!',0dh,0ah,'$'
dis4 db 0dh,0ah,'-> Receive error!',0dh,0ah,'$'
dis5 db 0dh,0ah,'Waiting for the data......',0dh,0ah,'$'
receive_data db 100 dup(?)
data ends
code segment
assume cs:code,ds:data
;------------------------------------------------------------------------------------------
main proc far
mov ax,data
mov ds,ax
xor ax,ax
;16色文本顯示方式
mov al,3
mov ah,0
int 10h
mov dx,offset dis0
call disp
;初始化串口
call initialize_serial
repeat_all:
;顯示等待數(shù)據(jù)
mov dx,offset dis5
call disp
;接收來(lái)自接發(fā)送端的信
call receive
call crlf
choose_yesno:
;詢問(wèn)是否繼續(xù)
mov dx,offset dis2
call disp
;調(diào)用選擇是否繼續(xù)程序段
call inpute_yesno
exit_all:
mov ax,4c00h
int 21h
main endp
;---------------------------------------------------------------------------------------
initialize_serial proc near
;通信控制寄存器D7=1
mov dx,03fbh
mov al,80h
out dx,al
;設(shè)置波特率為9600
mov dx,03f8h
mov al,0ch
out dx,al
inc dx
mov al,0
out dx,al
;初始化通信控制寄存器
mov dx,03fbh
mov al,0bh
out dx,al
;初始化modem控制器
mov dx,03fch
mov al,03h
out dx,al
;寫中斷允許寄存器
mov dx,03f9h
mov al,0
out dx,al
ret
initialize_serial endp
;---------------------------------------------------------------------------------------
receive proc near
mov si,0
waitre:
mov dx,3fdh
;循環(huán)等待接受段的確認(rèn)信息
in al,dx
mov ah,al
test ah,1eh
jnz receive_error
test al,01h
jz waitre
mov dx,3f8h
in al,dx
mov receive_data[si],al
inc si
cmp al,24h
jz receive_exit
jmp waitre
receive_exit:
;顯示成功接受
mov dx,offset dis3
call disp
;顯示接受到的數(shù)據(jù)
mov dx,offset dis1
call disp
mov dx,offset receive_data
call disp
ret
receive_error:
;顯示接受錯(cuò)誤
mov dx,offset dis4
call disp
ret
receive endp
;------------------------------------------------------------------------------------------
inpute_yesno proc near
inpute_yesno_again:
mov ah,7
int 21h
cmp al,79h
je yes
cmp al,6eh
je no
jmp inpute_yesno_again
yes:
jmp repeat_all
no:
jmp exit_all
ret
inpute_yesno endp
;------------------------------------------------------------------------------------------
disp proc near
mov ah,9
int 21h
ret
disp endp
;------------------------------------------------------------------------------------------
crlf proc near
mov dl,0dh
mov ah,2
int 21h
mov dl,0ah
mov ah,2
int 21h
ret
crlf endp
code ends
end main
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -