串行通信实验报告文档格式.docx
《串行通信实验报告文档格式.docx》由会员分享,可在线阅读,更多相关《串行通信实验报告文档格式.docx(11页珍藏版)》请在冰豆网上搜索。
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:
CLRTI
INCDPTR
MOVA,DPH
CJNEA,76H,END1
MOVA,DPL
CJNEA,75H,END1
SETBF0
CLRES
CLREA
END1:
MOVXA,@DPTR
RETI
END
乙方发送程序如下:
LJMP
MAIN
ORG
0023H
COM_INT
1000H
ACALLRECEI
RECEI:
MOVR0,#78H
MOV
TMOD,#20H
TH1,#0F3H
TL1,#0F3H
PCON,#80H
SETB
TR1
SCON,#50H
IE,#90H
CLR
F0
7FH
JNB7FH,WAIT
PUSHDPL
PUSH
DPH
Acc
RI
JBF0,R_DATA
A,SBUF
@R0,A
DEC
R0
CJNE
R0,#74H,RETN
RETN:
POPAcc
POPDPH
POPDPL
R_DATA:
MOVDPH,78H
MOVA,SBUF
MOVX@DPTR,A
INC77H
MOVA,77H
JNZEND2
INC78H
END2:
MOVA,76H
CJNEA,78H,RETN
A,75H
A,77H,RETN
ES
EA
SJMP
RETN
五、实验过程中遇到的主要问题OUTBITequ08002h;
位控制口OUTSEGequ08004h;
段控制口INequ08001h;
键盘读入口
HasRcvequ20h.0;
接收标志位
LEDBufequ40h;
显示缓冲
RCVBufequ50H;
接收缓冲
ORG0000HLJMPSTART
;
串行口中断程序
JNBTI,S0_R
NOP
SJMPS0_RET
S0_R:
;
接收数据
CLRRI
MOVRCVBUF,SBUF;
保存数据
SETBHasRcv;
提示收到数据NOP
S0_RET:
LEDMAP:
八段管显示码
db3fh,06h,5bh,4fh,66h,6dh,7dh,07h
db7fh,6fh,77h,7ch,39h,5eh,79h,71h
Delay:
延时子程序movr7,#0
DelayLoop:
djnzr7,DelayLoopdjnzr6,DelayLoopret
DisplayLED:
mov
r0,#LEDBuf
r1,#6
共6个八段管
r2,#00100000b
从左边开始显示
Loop:
dptr,#OUTBIT
a,#0
movx
@dptr,a
关所有八段管
a,@r0
dptr,#OUTSEG
@dptr,a
a,r2
@dptr,a;
显示一位八段管
movr6,#1
callDelay
显示下一位
rr
a
r2,a
inc
r0
djnz
r1,Loop
ret
TestKey:
输出线置为0
dptr,#IN
a,@dptr
读入键状态
cpl
anl
a,#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:
P2,dph
r0,#Low(IN)
r1,#00100000b
r2,#6
KLoop:
a,r1
找出键所在列
r1,a
下一列
jnz
Goon1
该列有键入
r2,KLoop
r2,#0ffh;
没有键按下,返回
0ffh
sjmp
Exit
Goon1:
键值=列X4+
行
decarlarla
r2=(r2-1)*4
r1中为读入的行值
r1,#4
LoopC:
rrc
移位找出所在行
jc
r2
r2=r2+行值
r1,LoopC
Exit:
取出键码
movdptr,#KeyTablemovca,@a+dptrmovr2,a
WaitRelease:
movclrmovx
dptr,#OUTBITa
等键释放
r6,#10
call
Delay
TestKey
WaitRelease
START:
SP,#60H
IE,#0;
DISABLEALLINTERRUPT
TMOD,#020H
定时器1工作于方式2(8位重装)
TH1,#0F3H;
波特率?
2400BPS@12MHz
TL1,#0F3H
ANL
PCON,#07FH;
SMOD位清零
orl
PCON,#80h
SCON,#050H
串行口工作方式设置
LEDBuf,#0ffh;
显示8.8.8.8.
LEDBuf+1,#0ffh
LEDBuf+2,#0ffh
movmovmovSETB
LEDBuf+3,#0ffh
LEDBuf+4,#0
LEDBuf+5,#0
sbuf,a
jnbti,$
MLoop:
jb
HasRcv,RcvData
收到数据?
DisplayLED
显示
有键入?
jz
MLoop
无键入,继续显示
GetKey
读入键码
a,#0fh;
通讯口输出键码
SBUF,A
RcvData:
clr
HasRcv
是
a,RcvBuf
显示数据
b,a
a,#0fh
显示低位
dptr,#LEDMap
movc
a,@a+dptr
LEDBuf+5,a
a,b
swap
显示高位
LEDBuf+4,a
ljmp
六、实验后的心得体会