?? dpjjx14.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>
<META NAME="Template" CONTENT="C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\html.dot">
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080" background="../back.jpg">
<FONT LANG="ZH-CN">
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">單片機教學</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">三、邏輯運算類指令:</font></P>
</FONT><OL><LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">對累加器</font><font size="2"><FONT LANG="ZH-CN">A的邏輯操作:</FONT></LI></font></OL>
<DIR>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">CLR	A </font><FONT LANG="ZH-CN" size="2">;將A中的值清0,單周期單字節指令,與MOV
A,#00H效果相同。</FONT></P>
<FONT LANG="ZH-CN">
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">CPL	A </font> </FONT><FONT LANG="ZH-CN" size="2">;將A</FONT><FONT LANG="ZH-CN"><font size="2">中的值按位取反
</font>
</FONT><FONT LANG="ZH-CN">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">RL		A
</font> </FONT><FONT LANG="ZH-CN" size="2">;將A</FONT><FONT LANG="ZH-CN"><font size="2">中的值邏輯左移
</font></p>
</FONT><FONT FACE="宋體" LANG="ZH-CN">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P>
</FONT><FONT LANG="ZH-CN">
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">RLC	A </font> </FONT><FONT LANG="ZH-CN" size="2">;將A</FONT><FONT LANG="ZH-CN"><font size="2">中的值加上進位位進行邏輯左移
</font>
</font><FONT FACE="宋體" LANG="ZH-CN">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P>
</font></DIR>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">RR		A </font><FONT LANG="ZH-CN" size="2">;將A中的值進行邏輯右移</FONT></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT LANG="ZH-CN"> <font size="2">RRC	A </font> </font>
<FONT LANG="ZH-CN" size="2">;將A中的值加上進位位進行邏輯右移</FONT></P><DIR>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">SWAP	A </font><FONT LANG="ZH-CN" size="2">;將A中的值高、低4位交換。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">例:(</font><FONT LANG="ZH-CN" size="2">A)=73H,則執行CPL		A,這樣進行:</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">73H</font><FONT LANG="ZH-CN" size="2">化為二進制為01110011,</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">逐位取反即為</font> <FONT LANG="ZH-CN" size="2">10001100,也就是8CH。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT LANG="ZH-CN"><font size="2">RL	A</font></font><FONT LANG="ZH-CN" size="2">是將(A)中的值的第7位送到第0位,第0位送1位,依次類推。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">例:</font><FONT LANG="ZH-CN" size="2">A中的值為68H,執行RL		A。68H化為二進制為01101000,按上圖進行移動。01101000化為11010000,即D0H。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<FONT LANG="ZH-CN"><font size="2">RLC		A</font></font><FONT LANG="ZH-CN" size="2">,是將(A)中的值帶上進位位(C)進行移位。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">例:</font><FONT LANG="ZH-CN" size="2">A中的值為68H,C中的值為1,則執行RLC		A</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">1 01101000</font><FONT LANG="ZH-CN" size="2">后,結果是0 11010001,也就是C進位位的值變成了0,而(A)則變成了D1H。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">RR	A</font><FONT LANG="ZH-CN" size="2">和RRC		A就不多談了,請大家參考上面兩個例子自行練習吧。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">SWAP	A</font><FONT LANG="ZH-CN" size="2">,是將A中的值的高、低4位進行交換。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">例:(</font><FONT LANG="ZH-CN" size="2">A)=39H,則執行SWAP	A之后,A中的值就是93H。怎么正好是這么前后交換呢?因為這是一個16進制數,每1個16進位數字代表4個二進位。注意,如果是這樣的:(A)=39,后面沒H,執行SWAP	A之后,可不是(A)=93。要將它化成二進制再算:39化為二進制是10111,也就是0001,0111高4位是0001,低4位是0111,交換后是01110001,也就是71H,即113。</FONT></P></DIR>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">練習,已知(</font><FONT LANG="ZH-CN" size="2">A)=39H,執行下列指令后寫出每步的結果</FONT></P>
<FONT LANG="ZH-CN">
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">CPL			A</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">RL			A</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">CLR			C</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">RRC			A</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">SETB		9; C</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">RLC			A</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">SWAP		9; A</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">通過前面的學習,我們已經掌握了相當一部份的指令,大家對這些枯燥的指令可能也有些厭煩了,下面讓我們輕松一下,做個實驗。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">實驗五:</font></P>
</FONT><FONT LANG="ZH-CN" SIZE=2>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> ORG 0000H</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> LJMP START</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> ORG 30H</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">START:</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> MOV SP,#5FH</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> MOV A,#80H</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">LOOP:</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> MOV P1,A</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> RL A</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> LCALL DELAY</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> LJMP LOOP</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">delay:</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	mov	#9; r7,#255</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">d1:	mov	#9; r6,#255</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">d2:	nop</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	nop</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	nop</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	nop</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	djnz	 r6,d2</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	djnz 	r7,d1</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	ret</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">	END</P>
</FONT><FONT LANG="ZH-CN">
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">先讓我們將程序寫入片中,裝進實驗板,看一看現象。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">。</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">看到的是一個暗點流動的現象,讓我們來分析一下吧。</font></P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">前而的</font><FONT LANG="ZH-CN" size="2">ORG 0000H、LJMP	START、ORG	30H等我們稍后分析。從START開始,MOV	SP,#5FH,這是初始化堆棧,在本程序中有無此句無關緊要,不過我們慢慢開始接觸正規的編程,我也就慢慢給大家培養習慣吧。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">MOV 	A</font><FONT LANG="ZH-CN" size="2">,#80H,將80H這個數送到A中去。干什么呢?不知道,往下看。</FONT></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" LANG="ZH-CN">MOV	P1</font><FONT LANG="ZH-CN" size="2">,A。將A中的值送到P1端口去。此時A中的值是80H,所以送出去的也就是80H,因此P1口的值是80H,也就是10000000B,通過前面的分析,我們應當知道,此時P1。7接的LED是不亮的,而其它的LED都是亮的,所以就形成了一個“暗點”。繼續看,RL	A,RL	A是將A中的值進行左移,算一下,移之后的結果是什么?對了,是01H,也就是00000001B,這樣,應當是接在P1。0上的LED不亮,而其它的都亮了,從現象上看“暗點”流到了后面。然后是調用延時程序,這個我們很熟悉了,讓這個“暗點”“暗”一會兒。然后又調轉到LOOP處(LJMP	LOOP)。請大家計算一下,下面該哪個燈不亮了。。。。。對了,應當是接在P1。1上燈不亮了。這樣依次循環,就形成了“暗點流動”這一現象。</FONT></P>
<FONT LANG="ZH-CN">
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">問題:</font></P>
</FONT><FONT FACE="宋體" LANG="ZH-CN">
<OL>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
</FONT><FONT LANG="ZH-CN">
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">如何實現亮點流動?</LI></font></p>
</FONT><FONT FACE="宋體" LANG="ZH-CN">
<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 LANG="ZH-CN">
<LI>
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">如何改變流動的方向?</LI></font></p>
</FONT><FONT FACE="宋體" LANG="ZH-CN">
<p style="line-height: 150%; margin-top: 0; margin-bottom: 0"></P></OL>
<FONT LANG="ZH-CN">
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">答案:</font></P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">1、將A中的初始值改為7FH即可。	</font>	</P>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2">2、將RL A改為RR A即可。</font></P>
</FONT>
<P ALIGN="JUSTIFY" style="line-height: 150%; margin-top: 0; margin-bottom: 0"> </P>
</FONT>
</FONT></BODY>
</HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -