⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dpjjx24.htm

📁 本单片机教程是平凡老师花了大量时间
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html>
<head>
<title>串行口中断应用实验</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" background="../back.jpg">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 
<font size="2" face="宋体">串行口应用编程实例</font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">1. 串口方式0应用编程 8051单片机串行口方式0为移位寄存器方式,外接一个串入并出的移位寄存器,就可以扩展一个并行口。</font></p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"><img src="dpjjx246.gif" width="368" height="214"></font></p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">例:用8051串行口外接CD4094扩展8位并行输出口,如图所示,8位并行口的各位都接一个发光二极管,要求发光管呈流水灯状态。 串行口方式0的数据传送可采用中断方式,也可采用查询方式,无论哪种方式,都要借助于TI或RI标志。串行发送时,可以靠TI置位(发完一帧数据后)引起中断申请,在中断服务程序中发送下一帧数据,或者通过查询TI的状态,只要TI为0就继续查询,TI为1就结束查询,发送下一帧数据。在串行接收时,则由RI引起中断或对RI查询来确定何时接收下一帧数据。无论采用什么方式,在开始通讯之前,都要先对控制寄存器SCON进行初始化。在方式0中将,将00H送SCON就可以了。 
</font>  
</p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">ORG 2000H </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">START: MOV SCON,#00H ;置串行口工作方式0 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">MOV A,#80H ;最高位灯先亮 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">CLR P1.0 ;关闭并行输出(避象传输过程中,各LED的"暗红"现象)</font></p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"> 
<font size="2" face="宋体">OUT0: MOV SBUF,A ;开始串行输出 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">OUT1: JNB TI,OUT1 ;输出完否 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">CLR TI ;完了,清TI标志,以备下次发送 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">SETB P1.0 ;打开并行口输出 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">ACALL DELAY ;延时一段时间 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">RR A ;循环右移 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">CLR P1.0 ;关闭并行输出 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">JMP OUT0 ;循环 </font> </p> 
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">说明:DELAY延时子程序可以用前面我们讲P1口流水灯时用的延时子程序,这里就不给出了。 </font> </p>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">二、异步通讯</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体">org 
0000H</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">&#9;AJMP&#9;START</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">&#9;ORG&#9;30H</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">START: </font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> mov SP,#5fh ;</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体"> mov TMOD,#20h ;T1: </font>
<font face="宋体" lang="ZH-CN" size=2>工作模式</font><font size=2 face="宋体">2</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> mov PCON,#80h ;SMOD=1</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体"> mov TH1,#0FDH ;</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" face="宋体"> mov SCON,#50h ;Standard UART settings</font></p> 
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体"> MOV R0,#0AAH &#9;;</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 face="宋体">SETB 
REN ;</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 face="宋体"> SETB TR1 ;T1</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" face="宋体">WAIT:</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> MOV A,R0 &#9;&#9;</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> CPL A</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> MOV R0,A</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> MOV SBUF,A</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> LCALL DELAY </font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体"> JBC TI,WAIT1 ;</font><font face="宋体" lang="ZH-CN" size=2>如果</font><font size=2 face="宋体">TI</font><font face="宋体" lang="ZH-CN" size=2>等于</font><font size=2 face="宋体">1</font><font face="宋体" lang="ZH-CN" size=2>,则清</font><font size=2 face="宋体">TI</font><font face="宋体" lang="ZH-CN" size=2>并转</font><font size=2 face="宋体">WAIT1</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> AJMP WAIT</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size=2 face="宋体">WAIT1: JBC RI,READ &#9;&#9;;</font><font face="宋体" lang="ZH-CN" size=2>如果</font><font size=2 face="宋体">RI</font><font face="宋体" lang="ZH-CN" size=2>等于</font><font size=2 face="宋体">1</font><font face="宋体" lang="ZH-CN" size=2>,则清</font><font size=2 face="宋体">RI</font><font face="宋体" lang="ZH-CN" size=2>并转</font><font size=2 face="宋体">READ</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体"> AJMP WAIT1</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋体">READ:</font></p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -