串行通信的实验报告Word格式文档下载.docx
《串行通信的实验报告Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《串行通信的实验报告Word格式文档下载.docx(10页珍藏版)》请在冰豆网上搜索。
MAIN:
MOVSP,#53H
MOV78H,#20H
MOV77H,00H
MOV76H,20H
MOV75H,40H
ACALLTRANS
HERE:
SJMPHERE
TRANS:
MOVTMOD,#20H
MOVTH1,#0F3H
MOVTL1,#0F3H
MOVPCON,#80H
SETBTR1
MOVSCON,#40H
MOVIE,#00H
CLRF0
MOVSBUF,78H
WAIT1:
JNBTI,WAIT1
CLRTI
MOVSBUF,77H
WAIT2:
JNBTI,WAIT2
MOVSBUF,76H
WAIT3:
JNBTI,WAIT3
MOVSBUF,75H
WAIT4:
JNBTI,WAIT4
MOVIE,#90H
MOVDPH,78H
MOVDPL,77H
MOVXA,@DPTR
MOVSBUF,A
WAIT:
JNBF0,WAIT
RET
COM_INT:
INCDPTR
MOVA,DPH
CJNEA,76H,END1
MOVA,DPL
CJNEA,75H,END1
SETBF0
CLRES
CLREA
END1:
RETI
END
乙方发送程序如下:
ORG0000H
ACALLRECEI
RECEI:
MOVR0,#78H
MOVSCON,#50H
CLR7FH
JNB7FH,WAIT
PUSHDPL
PUSHDPH
PUSHAcc
CLRRI
JBF0,R_DATA
MOVA,SBUF
MOV@R0,A
DECR0
CJNER0,#74H,RETN
RETN:
POPAcc
POPDPH
POPDPL
R_DATA:
MOVX@DPTR,A
INC77H
MOVA,77H
JNZEND2
INC78H
END2:
MOVA,76H
CJNEA,78H,RETN
MOVA,75H
CJNEA,77H,RETN
SETB7FH
SJMPRETN
五、实验过程中遇到的主要问题
OUTBITequ08002h;
位控制口
OUTSEGequ08004h;
段控制口
INequ08001h;
键盘读入口
HasRcvequ20h.0;
接收标志位
LEDBufequ40h;
显示缓冲
RCVBufequ50H;
接收缓冲
LJMPSTART
;
串行口中断程序
JNBTI,S0_R
NOP
SJMPS0_RET
S0_R:
;
接收数据
MOVRCVBUF,SBUF;
保存数据
SETBHasRcv;
提示收到数据
S0_RET:
LEDMAP:
八段管显示码
db3fh,06h,5bh,4fh,66h,6dh,7dh,07h
db7fh,6fh,77h,7ch,39h,5eh,79h,71h
Delay:
延时子程序
movr7,#0
DelayLoop:
djnzr7,DelayLoop
djnzr6,DelayLoop
ret
DisplayLED:
movr0,#LEDBuf
movr1,#6;
共6个八段管
movr2,#00100000b;
从左边开始显示
Loop:
movdptr,#OUTBIT
mova,#0
movx@dptr,a;
关所有八段管
mova,@r0
movdptr,#OUTSEG
movx@dptr,a
mova,r2
显示一位八段管
movr6,#1
callDelay
mova,r2;
显示下一位
rra
movr2,a
incr0
djnzr1,Loop
TestKey:
输出线置为0
movdptr,#IN
movxa,@dptr;
读入键状态
cpla
anla,#0fh;
高四位不用
KeyTable:
键码定义
db16h,15h,14h,0ffh
db13h,12h,11h,10h
db0dh,0ch,0bh,0ah
db0eh,03h,06h,09h
db0fh,02h,05h,08h
db00h,01h,04h,07h
GetKey:
movP2,dph
movr0,#Low(IN)
movr1,#00100000b
movr2,#6
KLoop:
mova,r1;
找出键所在列
movx@dptr,a
movr1,a;
下一列
movxa,@r0
anla,#0fh
jnzGoon1;
该列有键入
djnzr2,KLoop
movr2,#0ffh;
没有键按下,返回0ffh
sjmpExit
Goon1:
键值=列X4+行
deca
rla
movr2,a;
r2=(r2-1)*4
r1中为读入的行值
movr1,#4
LoopC:
rrca;
移位找出所在行
jcExit
incr2;
r2=r2+行值
djnzr1,LoopC
Exit:
取出键码
movdptr,#KeyTable
movca,@a+dptr
WaitRelease:
movdptr,#OUTBIT;
等键释放
clra
movr6,#10
callTestKey
jnzWaitRelease
START:
MOVSP,#60H
MOVIE,#0;
DISABLEALLINTERRUPT
MOVTMOD,#020H;
定时器1工作于方式2(8位重装)
MOVTH1,#0F3H;
波特率?
2400BPS@12MHz
MOVTL1,#0F3H
ANLPCON,#07FH;
SMOD位清零
orlPCON,#80h
MOVSCON,#050H;
串行口工作方式设置
MOVLEDBuf,#0ffh;
显示8.8.8.8.
movLEDBuf+1,#0ffh
movLEDBuf+2,#0ffh
movLEDBuf+3,#0ffh
movLEDBuf+4,#0
movLEDBuf+5,#0
SETBES
SETBEA
movsbuf,a
jnbti,$
MLoop:
jbHasRcv,RcvData;
收到数据?
callDisplayLED;
显示
callTestKey;
有键入?
jzMLoop;
无键入,继续显示
callGetKey;
读入键码
通讯口输出键码
LJMPMLoop
RcvData:
clrHasRcv;
是
mova,RcvBuf;
显示数据
movb,a
anla,#0fh;
显示低位
movdptr,#LEDMap
movLEDBuf+5,a
mova,b
swapa;
显示高位
anla,#0fh
movLEDBuf+4,a
ljmpMLoop
六、实验后的心得体会