?? dpjjx24.htm
字號:
<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="宋體">	AJMP	START</font></p>
<p align="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" face="宋體">	ORG	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 	;</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 		</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 		;</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 + -