📄 dpjjx21.htm
字号:
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">ORG	000BH ;定时器0的中断向量地址</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">AJMP	TIME0	;跳转到真正的定时器程序处</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 ;关所 灯</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	30H,#00H ;软件计数器预清0</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TMOD,#00000001B ;定时/计数器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 ;即数15536</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	EA	;开总中断允许</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	ET0	;开定时/计数器0允许</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">SETB	TR0	 ;定时/计数器0开始运行</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">LOOP:	AJMP	LOOP	;真正工作时,这里可写任意程序</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">TIME0:			;定时器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推入堆栈保护</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 ;清软件计数器</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	;重置定时常数</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">先自己分析一下,看看是怎么实现的?这里采用了软件计数器的概念,思路是这样的,先用定时</font><font size="2"><FONT FACE="System" LANG="ZH-CN">/</FONT><FONT FACE="宋体" LANG="ZH-CN">计数器</FONT><FONT FACE="System" LANG="ZH-CN">0</FONT><FONT FACE="宋体" LANG="ZH-CN">做一个</FONT><FONT FACE="System" LANG="ZH-CN">50</FONT><FONT FACE="宋体" LANG="ZH-CN">毫秒的定时器,定时是间到了以后并不是立即取反</FONT><FONT FACE="System" LANG="ZH-CN">P10</FONT><FONT FACE="宋体" LANG="ZH-CN">,而是将软件计数器中的值加</FONT><FONT FACE="System" LANG="ZH-CN">1</FONT><FONT FACE="宋体" LANG="ZH-CN">,如果软件计数器计到了</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">,并清掉软件计数器中的值,否则直接返回,这样,就变成了</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">,因此定时时间就延长了成了</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">这个思路在工程中是非常有用的,有的时候我们需要若干个定时器,可</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">个,怎么办呢?其实,只要这几个定时的时间有一定的公约数,我们就可以用软件定时器加以实现,如我要实现</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">每次闪烁,怎么实现呢?对了我们用两个计数器,一个在它计到</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">,并清零,就如上面所示,另一个计到</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 ;定时器0的中断向量地址</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">AJMP	TIME0	;跳转到真正的定时器程序处</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 ;关所 灯</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	30H,#00H ;软件计数器预清0</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">MOV	TMOD,#00000001B ;定时/计数器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 ;即数15536</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	EA	;开总中断允许</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0">	
<font size="2">SETB	ET0	;开定时/计数器0允许</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">SETB	TR0	 ;定时/计数器0开始运行</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">LOOP:	AJMP	LOOP	;真正工作时,这里可写任意程序</font></P>
<P style="line-height: 150%; margin-top: 0; margin-bottom: 0"><font size="2">TIME0:			;定时器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推入堆栈保护</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	;两个计数器都加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 ;清软件计数器</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,清计数器,返回</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	;重置定时常数</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">您能用定时器的方法实现前面讲的流水灯吗?试试看。</font></P></FONT></BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -