📄 dpjjx23.htm
字号:
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb_2312-80">
<META NAME="Generator" CONTENT="Microsoft FrontPage 5.0">
<TITLE>串行接口</TITLE>
</HEAD>
<BODY background="../back.jpg">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">串行接口</P>
</FONT>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<OL>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
</FONT>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">概述</LI></p>
</FONT>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P></OL>
<OL>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">串行接口的一般概念</LI>
单片机与外界进行信息交换称之为通讯。
</OL>
</FONT>
</FONT>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><FONT SIZE=2>8051</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>单片机的通讯方式有两种:</FONT></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>并行通讯:数据的各位同时发送或接收。</FONT></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>串行通讯:数据一位一位顺序发送或接收。参看下图:</FONT></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">
<img src="DPJ221.gif" width="565" height="341"></font></p>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P>
</FONT>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">串行通讯的方式:</P>
</FONT>
<OL><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">异步通讯:它用一个起始位表示字符的开始,用停止位表示字符的结束。其每帧的格式如下:</LI></p>
</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P>
</font>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>在一帧格式中,先是一个起始位</font><FONT SIZE=2>0</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,然后是</FONT><FONT SIZE=2>8</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>个数据位,规定低位在前,高位在后,接下来是奇偶校验位(可以省略),最后是停止位</FONT><FONT SIZE=2>1</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>。用这种格式表示字符,则字符可以一个接一个地传送。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>在异步通讯中,</font><FONT SIZE=2>CPU</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>与外设之间必须有两项规定,即字符格式和波特率。字符格式的规定是双方能够在对同一种</FONT><FONT SIZE=2>0</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>和</FONT><FONT SIZE=2>1</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>的串理解成同一种意义。原则上字符格式可以由通讯的双方自由制定,但从通用、方便的角度出发,一般还是使用一些标准为好,如采用</FONT><FONT SIZE=2>ASCII</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>标准。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>波特率即数据传送的速率,其定义是每秒钟传送的二进制数的位数。例如,数据传送的速率是</font><FONT SIZE=2>120</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>字符</FONT><FONT SIZE=2>/s</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,而每个字符如上述规定包含</FONT><FONT SIZE=2>10</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>数位,则传送波特率为</FONT><FONT SIZE=2>1200</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>波特。</font></P><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"></font>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">同步通讯:在同步通讯中,每个字符要用起始位和停止位作为字符开始和结束的标志,占用了时间;所以在数据块传递时,为了提高速度,常去掉这些标志,采用同步传送。由于数据块传递开始要用同步字符来指示,同时要求由时钟来实现发送端与接收端之间的同步,故硬件较复杂。</LI></p>
</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">通讯方向:在串行通讯中,把通讯接口只能发送或接收的单向传送方法叫单工传送;而把数据在甲乙两机之间的双向传递,称之为双工传送。在双工传送方式中又分为半双工传送和全双工传送。半双工传送是两机之间不能同时进行发送和接收,任一时该,只能发或者只能收信息。</LI></p>
</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P></font></font></OL>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>2</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>.</FONT><FONT SIZE=2>8051</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>单片机的串行接口结构</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>8051</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>串行接口是一个可编程的全双工串行通讯接口。它可用作异步通讯方式(</FONT><FONT SIZE=2>UART</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>),与串行传送信息的外部设备相连接,或用于通过标准异步通讯协议进行全双工的</FONT><FONT SIZE=2>8051</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>多机系统也可以通过同步方式,使用</FONT><FONT SIZE=2>TTL</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>或</FONT><FONT SIZE=2>CMOS</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>移位寄存器来扩充</FONT><FONT SIZE=2>I/O</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>口。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT SIZE=2>8051</font><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>单片机通过引脚</FONT><FONT SIZE=2>RXD</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>(</FONT><FONT SIZE=2>P3.0</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,串行数据接收端)和引脚</FONT><FONT SIZE=2>TXD</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>(</FONT><FONT SIZE=2>P3.1</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,串行数据发送端)与外界通讯。</FONT><FONT SIZE=2>SBUF</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>是串行口缓冲寄存器,包括发送寄存器和接收寄存器。它们有相同名字和地址空间,但不会出现冲突,因为它们两个一个只能被</FONT><FONT SIZE=2>CPU</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>读出数据,一个只能被</FONT><FONT SIZE=2>CPU</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>写入数据。</font></P>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<OL>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
</FONT>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">串行口的控制与状态寄存器</LI></p>
</FONT>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P></OL>
</FONT>
<OL>
<FONT FACE="宋体" LANG="ZH-CN" SIZE=3>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
</font>
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>串行口控制寄存器</font><FONT SIZE=2>SCON</LI> </font>
<FONT SIZE=3>
</p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT FACE="宋体" LANG="ZH-CN" SIZE=2>它用于定义串行口的工作方式及实施接收和发送控制。字节地址为</font><FONT SIZE=2>98H</FONT><FONT FACE="宋体" LANG="ZH-CN" SIZE=2>,其各位定义如下表:</font></P>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=592>
<TR>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D7
</FONT></TD>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D6
</FONT></TD>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D5
</FONT></TD>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D4
</FONT></TD>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D3
</FONT></TD>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D2
</FONT></TD>
<TD WIDTH="13%" VALIGN="TOP"> <FONT SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">D1
</FONT></TD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -