?? dpjjx21.htm
字號(hào):
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">ORG	000BH ;定時(shí)器0的中斷向量地址</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">AJMP	TIME0	;跳轉(zhuǎn)到真正的定時(shí)器程序處</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">ORG	30H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">START:</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	P1,#0FFH ;關(guān)所 燈</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	30H,#00H ;軟件計(jì)數(shù)器預(yù)清0</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TMOD,#00000001B ;定時(shí)/計(jì)數(shù)器0工作于方式1</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TH0,#3CH	</font>	</P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TL0,#0B0H ;即數(shù)15536</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	EA	;開(kāi)總中斷允許</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	ET0	;開(kāi)定時(shí)/計(jì)數(shù)器0允許</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">SETB	TR0	 ;定時(shí)/計(jì)數(shù)器0開(kāi)始運(yùn)行</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">LOOP:	AJMP	LOOP	;真正工作時(shí),這里可寫(xiě)任意程序</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">TIME0:			;定時(shí)器0的中斷處理程序</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">PUSH	ACC</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">PUSH	PSW	;將PSW和ACC推入堆棧保護(hù)</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">INC	30H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	A,30H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">CJNE	A,#20,T_RET	;30H單元中的值到了20了嗎?</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">T_L1:	CPL	P1.0		;到了,取反P10</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	30H,#0 ;清軟件計(jì)數(shù)器</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">T_RET:</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TH0,#15H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TL0,#9FH	;重置定時(shí)常數(shù)</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">POP	PSW</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">POP	ACC</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">RETI</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">END</font></P>
</FONT></TD>
</TR>
</TABLE>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" FACE="宋體" LANG="ZH-CN">先自己分析一下,看看是怎么實(shí)現(xiàn)的?這里采用了軟件計(jì)數(shù)器的概念,思路是這樣的,先用定時(shí)</font><font size="2"><FONT FACE="System" LANG="ZH-CN">/</FONT><FONT FACE="宋體" LANG="ZH-CN">計(jì)數(shù)器</FONT><FONT FACE="System" LANG="ZH-CN">0</FONT><FONT FACE="宋體" LANG="ZH-CN">做一個(gè)</FONT><FONT FACE="System" LANG="ZH-CN">50</FONT><FONT FACE="宋體" LANG="ZH-CN">毫秒的定時(shí)器,定時(shí)是間到了以后并不是立即取反</FONT><FONT FACE="System" LANG="ZH-CN">P10</FONT><FONT FACE="宋體" LANG="ZH-CN">,而是將軟件計(jì)數(shù)器中的值加</FONT><FONT FACE="System" LANG="ZH-CN">1</FONT><FONT FACE="宋體" LANG="ZH-CN">,如果軟件計(jì)數(shù)器計(jì)到了</FONT><FONT FACE="System" LANG="ZH-CN">20</FONT><FONT FACE="宋體" LANG="ZH-CN">,就取反</FONT><FONT FACE="System" LANG="ZH-CN">P10</FONT><FONT FACE="宋體" LANG="ZH-CN">,并清掉軟件計(jì)數(shù)器中的值,否則直接返回,這樣,就變成了</FONT><FONT FACE="System" LANG="ZH-CN">20</FONT><FONT FACE="宋體" LANG="ZH-CN">次定時(shí)中斷才取反一次</FONT><FONT FACE="System" LANG="ZH-CN">P10</FONT><FONT FACE="宋體" LANG="ZH-CN">,因此定時(shí)時(shí)間就延長(zhǎng)了成了</FONT><FONT FACE="System" LANG="ZH-CN">20*50</FONT><FONT FACE="宋體" LANG="ZH-CN">即</FONT><FONT FACE="System" LANG="ZH-CN">1000</FONT></font><font size="2" FACE="宋體" LANG="ZH-CN">毫秒了。</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">
<font size="2" FACE="宋體" LANG="ZH-CN">這個(gè)思路在工程中是非常有用的,有的時(shí)候我們需要若干個(gè)定時(shí)器,可</font><font size="2"><FONT FACE="System" LANG="ZH-CN">51</FONT><FONT FACE="宋體" LANG="ZH-CN">中總共才有</FONT><FONT FACE="System" LANG="ZH-CN">2</FONT><FONT FACE="宋體" LANG="ZH-CN">個(gè),怎么辦呢?其實(shí),只要這幾個(gè)定時(shí)的時(shí)間有一定的公約數(shù),我們就可以用軟件定時(shí)器加以實(shí)現(xiàn),如我要實(shí)現(xiàn)</FONT><FONT FACE="System" LANG="ZH-CN">P10</FONT><FONT FACE="宋體" LANG="ZH-CN">口所接燈按</FONT><FONT FACE="System" LANG="ZH-CN">1S</FONT><FONT FACE="宋體" LANG="ZH-CN">每次,而</FONT><FONT FACE="System" LANG="ZH-CN">P11</FONT><FONT FACE="宋體" LANG="ZH-CN">口所接燈按</FONT><FONT FACE="System" LANG="ZH-CN">2S</FONT><FONT FACE="宋體" LANG="ZH-CN">每次閃爍,怎么實(shí)現(xiàn)呢?對(duì)了我們用兩個(gè)計(jì)數(shù)器,一個(gè)在它計(jì)到</FONT><FONT FACE="System" LANG="ZH-CN">20</FONT><FONT FACE="宋體" LANG="ZH-CN">時(shí),取反</FONT><FONT FACE="System" LANG="ZH-CN">P10</FONT><FONT FACE="宋體" LANG="ZH-CN">,并清零,就如上面所示,另一個(gè)計(jì)到</FONT><FONT FACE="System" LANG="ZH-CN">40</FONT><FONT FACE="宋體" LANG="ZH-CN">取反</FONT><FONT FACE="System" LANG="ZH-CN">P11</FONT><FONT FACE="宋體" LANG="ZH-CN">,然后清</FONT><FONT FACE="System" LANG="ZH-CN">0</FONT></font><font size="2" FACE="宋體" LANG="ZH-CN">,不就行了嗎?這部份的程序如下</font></P>
<TABLE CELLSPACING=0 BORDER=1 CELLPADDING=7 WIDTH=645>
<TR><TD VALIGN="TOP">
<FONT FACE="宋體" LANG="ZH-CN">
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">ORG	0000H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">AJMP	START</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">ORG	000BH ;定時(shí)器0的中斷向量地址</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">AJMP	TIME0	;跳轉(zhuǎn)到真正的定時(shí)器程序處</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">ORG	30H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">START:</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	P1,#0FFH ;關(guān)所 燈</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	30H,#00H ;軟件計(jì)數(shù)器預(yù)清0</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TMOD,#00000001B ;定時(shí)/計(jì)數(shù)器0工作于方式1</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TH0,#3CH	</font>	</P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TL0,#0B0H ;即數(shù)15536</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	EA	;開(kāi)總中斷允許</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	ET0	;開(kāi)定時(shí)/計(jì)數(shù)器0允許</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">SETB	TR0	 ;定時(shí)/計(jì)數(shù)器0開(kāi)始運(yùn)行</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">LOOP:	AJMP	LOOP	;真正工作時(shí),這里可寫(xiě)任意程序</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">TIME0:			;定時(shí)器0的中斷處理程序</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">PUSH	ACC</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">PUSH	PSW	;將PSW和ACC推入堆棧保護(hù)</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">INC	30H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">INC	31H	;兩個(gè)計(jì)數(shù)器都加1</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	A,30H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">CJNE	A,#20,T_NEXT	;30H單元中的值到了20了嗎?</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">T_L1:	CPL	P1.0		;到了,取反P10</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	30H,#0 ;清軟件計(jì)數(shù)器</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">T_NEXT:</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	A,31H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">CJNE	A,#40,T_RET	;31h單元中的值到40了嗎?</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">T_L2:</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">CPL	P1.1</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	31H,#0		;到了,取反P11,清計(jì)數(shù)器,返回</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">T_RET:</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">MOV	TH0,#15H</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TL0,#9FH	;重置定時(shí)常數(shù)</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">POP	PSW</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">POP	ACC</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">RETI</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">END</font></FONT></TD>
</TR>
</TABLE>
<FONT FACE="宋體" LANG="ZH-CN">
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><a href="down/Exec061.asm">
<font size="2">程序一下載</font></a><font size="2"> <a href="down/Exec061.hex">代碼下載</a> <a href="down/exec062.asm">程序二下載</a>
<a href="down/Exec062.hex">代碼下載</a> <a href="down/exec063.asm">程序三下載</a> <a href="down/Exec063.hex">代碼下載</a>
<a href="down/exec064.ASM">程序四下載</a></font><a href="down/Exec064.hex"><font size="2"> 代碼下載</font></a></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">您能用定時(shí)器的方法實(shí)現(xiàn)前面講的流水燈嗎?試試看。</font></P></FONT></BODY>
</HTML>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -