接口RS232串口通信
- 格式:doc
- 大小:182.00 KB
- 文档页数:11
华北科技学院计算机学院综合性实验
实验报告
课程名称接口技术
实验学期 2014 至 2015 学年第 2 学期学生所在学院部计算机学院
年级专业班级
学生姓名学号
任课教师顾涛
实验成绩
计算机学院制
《接口技术》课程综合性实验报告
io8253b equ 283h
io8251a equ 2b8h
io8251b equ 2b9h
mes1 db'you can play a key on the keybord!',0dh,0ah,24h
mes2 dd mes1
message1 db'success!$'
message2 db'failed!$'
counter db'1'
buffer1 db 4 dup(?)
buffer2 db 3 dup(?)
buffer3 db 3 dup(?)
flag1 db ?
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov dx,io8253b ;设置计数器工作方式
mov al,16h
out dx,al
mov dx,io8253a
mov al,52 ;给计数器送初值
out dx,al
mov dx,io8251b ;初始化
xor al,al
mov cx,03 ;向控制端口送个
delay:
call out1
loop delay
mov al,40h ;向控制端口送H,使其复位
call out1
mov al,4eh ;设置为个停止位,8个数据位,波特率因子为call out1
mov al,27h ;向送控制字允许其发送和接收
call out1
lds dx,mes2 ;显示提示信息
mov ah,09
int 21h
mov ah,09h ;显示序号1
waiti:
call testsend
mov ah,01 ;是,从键盘上读一字符
int 21h
cmp al,27 ;若为ESC,结束
jnz continue
exit:
mov ah,4ch ;退出
int 21h
continue:
mov dx,io8251a
push ax
call testsend
mov al,30h
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer1],al
mov dx,io8251a
call testsend
mov al,[counter]
add [counter],byte ptr 1
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer1+1],al
mov dx,io8251a
pop ax
call comflag
shl al,1
add al,bl
call testsend
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer1+2],al
mov dx,io8251a
call testsend
mov al,50h
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer1+3],al
cmp [buffer1+3],50h ;数据包检查
jnz error
mov al,[buffer1+2]
push ax
and al,01h
mov [flag1],al
pop ax
shr al,1
call comflag
cmp bl,[flag1]
jnz error
push ax
push dx
mov ah,09h
lea dx,message1
int 21h
mov dl,[buffer1+1]
inc dl
mov ah,02 ;将接收到的字符显示在屏幕上int 21h
mov dl,' '
mov ah,02 ;将接收到的字符显示在屏幕上int 21h
pop dx
pop ax
mov dx,io8251a
;push ax
call testsend
mov al,60h
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer2],al
mov dx,io8251a
call testsend
mov al,[buffer1+1]
inc al
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer2+1],al
mov dx,io8251a
call testsend
mov al,80h
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer2+2],al
jmp waiti
error:
push ax
push dx
mov ah,09h
lea dx,message2
int 21h
mov dl,[buffer1+1]
mov ah,02 ;将接收到的字符显示在屏幕上int 21h
pop dx
pop ax
mov dx,io8251a
;push ax
mov al,70h
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer3],al
mov dx,io8251a
call testsend
mov al,[buffer1+1]
out dx,al
call testrec
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer3+1],al
mov dx,io8251a
call testsend
mov al,90h
out dx,al
mov dx,io8251a
in al,dx;准备好,接收
mov [buffer3+2],al
jmp exit
out1 proc near ;向外发送一字节的子程序out dx,al
push cx
mov cx,40h
gg:
loop gg ;延时
pop cx
ret
out1 endp
testsend proc near
push dx
push ax
waitii:
mov dx,io8251b
in al,dx
test al,01 ;发送是否准备好
jz waitii
pop ax
pop dx
ret
testsend endp
testrec proc near
push ax
push dx
next:
mov dx,io8251b
in al,dx
test al,02 ;检查接收是否准备好
jz next ;没有,等待
pop dx
pop ax
ret
testrec endp
comflag proc near
mov bl,0
add al,0
jp flagend
mov bl,1
flagend:
ret
comflag endp
code ends
end start
四、实验结果及分析
1、运行结果截图如下所示:
第10 页。