<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dutor &#187; 单片机</title>
	<atom:link href="http://www.dutor.net/index.php/tag/micctrler/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dutor.net</link>
	<description>熟读而精思，循序而渐进，厚积而薄发。</description>
	<lastBuildDate>Tue, 17 Jan 2012 14:44:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PIC18 EEPROM编程</title>
		<link>http://www.dutor.net/index.php/2009/11/pic18-eeprom/</link>
		<comments>http://www.dutor.net/index.php/2009/11/pic18-eeprom/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 14:25:04 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[尚未分类]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=1720</guid>
		<description><![CDATA[　　本程序利用PIC18单片机实现了对EEPROM的读写。应用背景是"汽车里程表"，简单介绍下程序功能和流程。
　　单片机接受来自RA4管脚的计数脉冲信号，应用中这个脉冲信号通常由一个传感器来产生，计数脉冲被设定为上升沿触发。计数器溢出时，需要更新一个用于存储当前里程的RAM寄存器单元COUNT，可以理解为车轮转了一定圈数后，里程表的增加一定的里程数。
　　RB0管脚用来接收一个外部中断信号，接收到中断信号后，在中断服务程序中将COUNT的值即当前里程数保存至EEPROM的00H单元。这样可以配合外部电路实现当单片机掉电时自动保存里程表数值的功能，即汽车熄火时保存里程表，以减少对EEPROM的读写次数。
　　单片机启动时，首先应该到EEPROM的相应单元读取里程表的当前值，并在此基础上进行累加。
　　程序中为了调试方便，还将COUNT的数值同步地通过8个LED以二进制形式较直观地显示了出来。 
<pre lang="asm" line="1">
LOOP	
		
	BCF	INTCON, T0IF 	; 清TMR0中断标志
	MOVLW	TMR0B 
	MOVWF	TMR0L 		; 装入计数初值 253
	BSF	T0CON, TMR0ON 	; 启动计数器
	TEST	
	BTFSS	INTCON, T0IF 	; 检测TMR0是否溢出
	GOTO	TEST
	INCF	COUNT, F 	; 计数加一
	MOVFF	COUNT, PORTD 	; 输出，显示
		
	GOTO	LOOP
		
WIRT_EE				; 写EEPROM
	BCF	EECON1, EEPGD
	BCF	EECON1, CFGS 	; 设定EECON1控制寄存器
	BSF	EECON1, WREN 	; EEPROM写使能
	BCF	INTCON, GIE 	; 写EEPROM时需要关闭一切中断
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　本程序利用PIC18单片机实现了对EEPROM的读写。应用背景是&#8221;汽车里程表&#8221;，简单介绍下程序功能和流程。<br />
　　单片机接受来自RA4管脚的计数脉冲信号，应用中这个脉冲信号通常由一个传感器来产生，计数脉冲被设定为上升沿触发。计数器溢出时，需要更新一个用于存储当前里程的RAM寄存器单元COUNT，可以理解为车轮转了一定圈数后，里程表的增加一定的里程数。<br />
　　RB0管脚用来接收一个外部中断信号，接收到中断信号后，在中断服务程序中将COUNT的值即当前里程数保存至EEPROM的00H单元。这样可以配合外部电路实现当单片机掉电时自动保存里程表数值的功能，即汽车熄火时保存里程表，以减少对EEPROM的读写次数。<br />
　　单片机启动时，首先应该到EEPROM的相应单元读取里程表的当前值，并在此基础上进行累加。<br />
　　程序中为了调试方便，还将COUNT的数值同步地通过8个LED以二进制形式较直观地显示了出来。</p>

<div class="wp_codebox"><table><tr id="p17201"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
</pre></td><td class="code" id="p1720code1"><pre class="asm" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">list</span>	P = 18F452
#include P18F452<span style="color: #339933;">.</span><span style="color: #00007f; font-weight: bold;">INC</span>
&nbsp;
	TMR0B	EQU D<span style="color: #7f007f;">'253'</span>
	COUNT	EQU  0x10H
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">0000H</span>	  	<span style="color: #666666; font-style: italic;">;PIC上电时从0000h单元开始执行</span>
	<span style="color: #000000; font-weight: bold;">GOTO</span>	MAIN	  	<span style="color: #666666; font-style: italic;">;跳转到主程序</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">0008H</span>
	<span style="color: #000000; font-weight: bold;">GOTO</span>	INT0_ISR	<span style="color: #666666; font-style: italic;">;中断向量入口</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">0030H</span>	  	<span style="color: #666666; font-style: italic;">;主程序定位</span>
MAIN	
	CLRF	TRISD	  	<span style="color: #666666; font-style: italic;">;设定D口方向为输出</span>
	CLRF	PORTD 		<span style="color: #666666; font-style: italic;">;设定C口方向为输出</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>	TRISA<span style="color: #339933;">,</span> <span style="color: #0000ff;">4</span> 	<span style="color: #666666; font-style: italic;">; 使用RA4做为计数输入</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>	INTCON<span style="color: #339933;">,</span> GIE 	<span style="color: #666666; font-style: italic;">;开全局中断</span>
	BCF	INTCON<span style="color: #339933;">,</span> INT0IF 	<span style="color: #666666; font-style: italic;">;清INT0中断标志</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>	INTCON<span style="color: #339933;">,</span> INT0IE 	<span style="color: #666666; font-style: italic;">; 开INT0中断</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>	TRISB<span style="color: #339933;">,</span> INT0 	<span style="color: #666666; font-style: italic;">; 设定RB0即INT0脚为接收(输入)状态</span>
&nbsp;
	MOVLW	<span style="color: #0000ff;">68H</span>
	MOVWF	T0CON 		<span style="color: #666666; font-style: italic;">; 设定计数器TMR0为8位计数，上升沿触发，分频比1:1</span>
	MOVLW	<span style="color: #0000ff;">0x00</span>
	MOVWF	EEADR	 	<span style="color: #666666; font-style: italic;">; 装载EEPROM的地址00h</span>
	<span style="color: #00007f; font-weight: bold;">CALL</span>	READ_EE 	<span style="color: #666666; font-style: italic;">; 读入EEPROM中00h单元的原始数据，即计数初值，保存到WREG</span>
	MOVWF	COUNT
	MOVWF	PORTD 		<span style="color: #666666; font-style: italic;">; 输出到PORTD(连接了8个LED)</span>
&nbsp;
<span style="color: #00007f; font-weight: bold;">LOOP</span>	
&nbsp;
	BCF	INTCON<span style="color: #339933;">,</span> T0IF 	<span style="color: #666666; font-style: italic;">; 清TMR0中断标志</span>
	MOVLW	TMR0B 
	MOVWF	TMR0L 		<span style="color: #666666; font-style: italic;">; 装入计数初值 253</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>	T0CON<span style="color: #339933;">,</span> TMR0ON 	<span style="color: #666666; font-style: italic;">; 启动计数器</span>
	<span style="color: #00007f; font-weight: bold;">TEST</span>	
	BTFSS	INTCON<span style="color: #339933;">,</span> T0IF 	<span style="color: #666666; font-style: italic;">; 检测TMR0是否溢出</span>
	<span style="color: #000000; font-weight: bold;">GOTO</span>	<span style="color: #00007f; font-weight: bold;">TEST</span>
	INCF	COUNT<span style="color: #339933;">,</span> F 	<span style="color: #666666; font-style: italic;">; 计数加一</span>
	MOVFF	COUNT<span style="color: #339933;">,</span> PORTD 	<span style="color: #666666; font-style: italic;">; 输出，显示</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">GOTO</span>	<span style="color: #00007f; font-weight: bold;">LOOP</span>
&nbsp;
WIRT_EE				<span style="color: #666666; font-style: italic;">; 写EEPROM</span>
	BCF	EECON1<span style="color: #339933;">,</span> EEPGD
	BCF	EECON1<span style="color: #339933;">,</span> CFGS 	<span style="color: #666666; font-style: italic;">; 设定EECON1控制寄存器</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>	EECON1<span style="color: #339933;">,</span> WREN 	<span style="color: #666666; font-style: italic;">; EEPROM写使能</span>
	BCF	INTCON<span style="color: #339933;">,</span> GIE 	<span style="color: #666666; font-style: italic;">; 写EEPROM时需要关闭一切中断</span>
&nbsp;
	MOVLW	0x55h 	<span style="color: #666666; font-style: italic;">; </span>
	MOVWF	EECON2
	MOVLW	0xAAh
	MOVWF	EECON2
	<span style="color: #00007f; font-weight: bold;">BSF</span>	EECON1<span style="color: #339933;">,</span> WR 	<span style="color: #666666; font-style: italic;">; 经典的五指令序列，将EEDATA写入EEPROM</span>
&nbsp;
	<span style="color: #00007f; font-weight: bold;">BSF</span>	INTCON<span style="color: #339933;">,</span> GIE 	<span style="color: #666666; font-style: italic;">; 开全局中断</span>
	BCF	EECON1<span style="color: #339933;">,</span> WREN 	<span style="color: #666666; font-style: italic;">; 提前关闭写使能</span>
	RETURN	
&nbsp;
READ_EE				<span style="color: #666666; font-style: italic;">; 读EEPROM</span>
	BCF	EECON1<span style="color: #339933;">,</span> EEPGD
	BCF	EECON1<span style="color: #339933;">,</span> CFGS
	<span style="color: #00007f; font-weight: bold;">BSF</span>	EECON1<span style="color: #339933;">,</span> RD
	<span style="color: #00007f; font-weight: bold;">NOP</span>	
	MOVF	EEDATA<span style="color: #339933;">,</span> W 	<span style="color: #666666; font-style: italic;">; 将读出的结果写入W并返回，</span>
	RETURN	
&nbsp;
&nbsp;
INT0_ISR	
				<span style="color: #666666; font-style: italic;">; 外部中断int0服务程序，可以利用外部电路，</span>
				<span style="color: #666666; font-style: italic;">; 实现掉电时将当前计数值写入EEPROM</span>
	BTFSS	INTCON<span style="color: #339933;">,</span> INT0IF  <span style="color: #666666; font-style: italic;">; 重新测试溢出位，防止干扰信号触发中断</span>
	RETFIE	
	BCF	INTCON<span style="color: #339933;">,</span> INT0IF
	MOVLW	0x00h
	MOVWF	EEADR
	MOVFF	COUNT<span style="color: #339933;">,</span> EEDATA
	<span style="color: #00007f; font-weight: bold;">CALL</span>	WIRT_EE
&nbsp;
	RETFIE			<span style="color: #666666; font-style: italic;">; 中断返回</span>
<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>662e438d</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/11/pic18-eeprom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PIC18 ADC模数转换</title>
		<link>http://www.dutor.net/index.php/2009/11/pic18f52-adc/</link>
		<comments>http://www.dutor.net/index.php/2009/11/pic18f52-adc/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 14:40:37 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[尚未分类]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=1700</guid>
		<description><![CDATA[　　使用PIC18单片机的ADC转换模块对RA0口输入的模拟电压信号进行转换，然后通过PORTD端口输出，而这里与PORTD对应引脚相连接的是8个LED。
<pre lang="asm" line="1">
list P = 18F452 ;指明单片机型号为PIC18F452
#include P18F452.INC ;包含一个头文件，其中定义了一些端口及一些特殊寄存器的地址

	org	0000h  	;PIC上电时从0000h单元开始执行
	goto	main  	;跳转到主程序
	ORG	0008H  	;中断向量入口
	BTFSS	PIR1, ADIF 	; AD转换完成中断
	RETFIE
	GOTO	AD_ISR

	ORG	0030H  	;主程序定位
MAIN
	CLRF	TRISD  	;设定D口方向为输出
	CLRF 	PORTD 	;设定C口方向为输出
	BSF 	TRISA, 0 	; 使用AN0输入
	MOVLW	81H 	;FOSC/32, AN0, 开启
	MOVWF	ADCON0
	MOVLW	0EH 	;左对齐,AN0为模拟输入
	MOVWF	ADCON1 	;VDD &#038; VSS为参考电压
	BCF 	INTCON, TMR0IF
	BCF 	PIR1, ADIF 	;清AD中断标志位
	BSF 	PIE1, ADIE 	;开AD中断
	BSF 	INTCON, PEIE 	;开外围中断
	BSF  	NTCON, GIE 	;开总中断
	MOVLW 	C7H 	;TMR0 8位，分频比为1:256
	MOVWF	T0CON
LOOP
	CALL	DELAY
	BSF  	DCON0, GO 	;开启 A/D转换
	GOTO	LOOP

DELAY

	BTFSS  	NTCON, TMR0IF 	; 等待延时，采样保持
	GOTO  	DELAY
	BCF  	NTCON, TMR0IF
	RETURN

AD_ISR ;AD转换完成时调用的中断服务程序，将转换结果输出
	ORG 	0200H
	MOVFF	ADRESH, PORTD 	;显示转换结果
	BCF 	PIR1, ADIF 	;清AD中断标志位
	RETFIE
END 	;程序结束
</pre>]]></description>
			<content:encoded><![CDATA[<p>　　使用PIC18单片机的ADC转换模块对RA0口输入的模拟电压信号进行转换，然后通过PORTD端口输出，而这里与PORTD对应引脚相连接的是8个LED。</p>

<div class="wp_codebox"><table><tr id="p17002"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p1700code2"><pre class="asm" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">list</span> P = 18F452 <span style="color: #666666; font-style: italic;">;指明单片机型号为PIC18F452</span>
#include P18F452<span style="color: #339933;">.</span><span style="color: #00007f; font-weight: bold;">INC</span> <span style="color: #666666; font-style: italic;">;包含一个头文件，其中定义了一些端口及一些特殊寄存器的地址</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">org</span>	<span style="color: #0000ff;">0000h</span>  	<span style="color: #666666; font-style: italic;">;PIC上电时从0000h单元开始执行</span>
	<span style="color: #000000; font-weight: bold;">goto</span>	main  	<span style="color: #666666; font-style: italic;">;跳转到主程序</span>
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">0008H</span>  	<span style="color: #666666; font-style: italic;">;中断向量入口</span>
	BTFSS	PIR1<span style="color: #339933;">,</span> ADIF 	<span style="color: #666666; font-style: italic;">; AD转换完成中断</span>
	RETFIE
	<span style="color: #000000; font-weight: bold;">GOTO</span>	AD_ISR
&nbsp;
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">0030H</span>  	<span style="color: #666666; font-style: italic;">;主程序定位</span>
MAIN
	CLRF	TRISD  	<span style="color: #666666; font-style: italic;">;设定D口方向为输出</span>
	CLRF 	PORTD 	<span style="color: #666666; font-style: italic;">;设定C口方向为输出</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span> 	TRISA<span style="color: #339933;">,</span> <span style="color: #0000ff;">0</span> 	<span style="color: #666666; font-style: italic;">; 使用AN0输入</span>
	MOVLW	<span style="color: #0000ff;">81H</span> 	<span style="color: #666666; font-style: italic;">;FOSC/32, AN0, 开启</span>
	MOVWF	ADCON0
	MOVLW	<span style="color: #0000ff;">0EH</span> 	<span style="color: #666666; font-style: italic;">;左对齐,AN0为模拟输入</span>
	MOVWF	ADCON1 	<span style="color: #666666; font-style: italic;">;VDD &amp; VSS为参考电压</span>
	BCF 	INTCON<span style="color: #339933;">,</span> TMR0IF
	BCF 	PIR1<span style="color: #339933;">,</span> ADIF 	<span style="color: #666666; font-style: italic;">;清AD中断标志位</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span> 	PIE1<span style="color: #339933;">,</span> ADIE 	<span style="color: #666666; font-style: italic;">;开AD中断</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span> 	INTCON<span style="color: #339933;">,</span> PEIE 	<span style="color: #666666; font-style: italic;">;开外围中断</span>
	<span style="color: #00007f; font-weight: bold;">BSF</span>  	NTCON<span style="color: #339933;">,</span> GIE 	<span style="color: #666666; font-style: italic;">;开总中断</span>
	MOVLW 	C7H 	<span style="color: #666666; font-style: italic;">;TMR0 8位，分频比为1:256</span>
	MOVWF	T0CON
<span style="color: #00007f; font-weight: bold;">LOOP</span>
	<span style="color: #00007f; font-weight: bold;">CALL</span>	DELAY
	<span style="color: #00007f; font-weight: bold;">BSF</span>  	DCON0<span style="color: #339933;">,</span> GO 	<span style="color: #666666; font-style: italic;">;开启 A/D转换</span>
	<span style="color: #000000; font-weight: bold;">GOTO</span>	<span style="color: #00007f; font-weight: bold;">LOOP</span>
&nbsp;
DELAY
&nbsp;
	BTFSS  	NTCON<span style="color: #339933;">,</span> TMR0IF 	<span style="color: #666666; font-style: italic;">; 等待延时，采样保持</span>
	<span style="color: #000000; font-weight: bold;">GOTO</span>  	DELAY
	BCF  	NTCON<span style="color: #339933;">,</span> TMR0IF
	RETURN
&nbsp;
AD_ISR <span style="color: #666666; font-style: italic;">;AD转换完成时调用的中断服务程序，将转换结果输出</span>
	<span style="color: #000000; font-weight: bold;">ORG</span> 	<span style="color: #0000ff;">0200H</span>
	MOVFF	ADRESH<span style="color: #339933;">,</span> PORTD 	<span style="color: #666666; font-style: italic;">;显示转换结果</span>
	BCF 	PIR1<span style="color: #339933;">,</span> ADIF 	<span style="color: #666666; font-style: italic;">;清AD中断标志位</span>
	RETFIE
<span style="color: #000000; font-weight: bold;">END</span> 	<span style="color: #666666; font-style: italic;">;程序结束</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/11/pic18f52-adc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PIC中断汇编</title>
		<link>http://www.dutor.net/index.php/2009/11/pic-int-asm/</link>
		<comments>http://www.dutor.net/index.php/2009/11/pic-int-asm/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 23:24:20 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[尚未分类]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=1580</guid>
		<description><![CDATA[　　PIC的汇编实在诡异，有点被颠覆的感觉，原来汇编指令还可以这么来设计，原来汇编指令怎么设计都可以。最OOXX的一条指令就一个实现短转移的指令叫做BRA，意为BRAanch，看到这条指令的时候，我都诧异了，奶罩能做什么？哇塞！居然还能跳转！？奶罩居然可以无条件跳转？！Orz……另外PIC指令把单词缩写运用的淋漓尽致，譬如指令BTFSS，是一条位测试加条件跳转指令：BTFSS = Bit + Test + FileRegister + Skip + Set，用法：BTFSS  R1, 0003h, 寄存器R1的第3位为1时跳过<strong>下一条指令</strong>。真是震撼！

　　最后附上PIC18的中断体系硬件结构图，出自陈育斌老师的手笔：]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox"><table><tr id="p15803"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
</pre></td><td class="code" id="p1580code3"><pre class="asm" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">list</span> P = 18F452
#include P18F452<span style="color: #339933;">.</span><span style="color: #00007f; font-weight: bold;">INC</span>
&nbsp;
MOVLF <span style="color: #000000; font-weight: bold;">macro</span> R<span style="color: #339933;">,</span> K
    movlw 	K
    movwf 	R
<span style="color: #000000; font-weight: bold;">endm</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; 定义了几个寄存器</span>
    R1  	EQU <span style="color: #0000ff;">20H</span>
    R2  	EQU <span style="color: #0000ff;">21H</span>
    R3  	EQU <span style="color: #0000ff;">22H</span>
    R4 		EQU <span style="color: #0000ff;">23H</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">ORG</span> 	<span style="color: #0000ff;">0008H</span>  <span style="color: #666666; font-style: italic;">;中断向量入口</span>
    <span style="color: #000000; font-weight: bold;">GOTO</span> 	SELECT <span style="color: #666666; font-style: italic;">;跳转到中段服务选择子程序</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">org</span>		<span style="color: #0000ff;">0000h</span>  <span style="color: #666666; font-style: italic;">;PIC上电时从0000h单元开始执行</span>
	<span style="color: #000000; font-weight: bold;">goto</span>	main  <span style="color: #666666; font-style: italic;">;跳转到主程序</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">org</span>		<span style="color: #0000ff;">0030h</span>  <span style="color: #666666; font-style: italic;">;主程序定位</span>
main
	clrf	TRISD  <span style="color: #666666; font-style: italic;">;设定D口方向为输出</span>
    CLRF	TRISC <span style="color: #666666; font-style: italic;">;设定C口方向为输出</span>
    CLRF	PORTC <span style="color: #666666; font-style: italic;">;C口置零</span>
    <span style="color: #00007f; font-weight: bold;">BSF</span> 	TRISB<span style="color: #339933;">,</span> INT0 <span style="color: #666666; font-style: italic;">; 设定int0中断源对应引脚为输入</span>
    CLRF 	PORTD
    CLRF	INTCON <span style="color: #666666; font-style: italic;">;先将中断控制寄存器清零</span>
    <span style="color: #00007f; font-weight: bold;">BSF</span> 	INTCON<span style="color: #339933;">,</span> GIE <span style="color: #666666; font-style: italic;">; 允许全局中断</span>
    <span style="color: #00007f; font-weight: bold;">BSF</span>  	INTCON<span style="color: #339933;">,</span> TMR0IE <span style="color: #666666; font-style: italic;">; 允许TMR0定时器中断</span>
    <span style="color: #00007f; font-weight: bold;">BSF</span>		INTCON<span style="color: #339933;">,</span> INT0IE <span style="color: #666666; font-style: italic;">; 允许int0中断</span>
    MOVLF  	T0CON<span style="color: #339933;">,</span> <span style="color: #0000ff;">07H</span> <span style="color: #666666; font-style: italic;">; 设定定时器0的计数模式</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">; 给定时器装入初值，定时器为特殊的双缓冲结构，</span>
    <span style="color: #666666; font-style: italic;">; 注意初值的装入顺序为先高后低</span>
    MOVLF 	TMR0H<span style="color: #339933;">,</span> <span style="color: #0000ff;">0C2H</span>
    MOVLF  	TMR0L<span style="color: #339933;">,</span> <span style="color: #0000ff;">0F7H</span>
    <span style="color: #00007f; font-weight: bold;">BSF</span>  	T0CON<span style="color: #339933;">,</span> TMR0ON <span style="color: #666666; font-style: italic;">; 打开定时器开始计数</span>
&nbsp;
<span style="color: #00007f; font-weight: bold;">LOOP</span> <span style="color: #666666; font-style: italic;">; PIC汇编的标号不需要冒号':'</span>
   	<span style="color: #666666; font-style: italic;">;SLEEP  ; 进入Sleep模式</span>
   	<span style="color: #000000; font-weight: bold;">GOTO</span> <span style="color: #00007f; font-weight: bold;">LOOP</span> <span style="color: #666666; font-style: italic;">; 转啊转</span>
&nbsp;
&nbsp;
SELECT <span style="color: #666666; font-style: italic;">; 中断服务选择程序,这里的测试顺序决定了中断优先级</span>
   	BTFSC   INTCON<span style="color: #339933;">,</span> TMR0IF <span style="color: #666666; font-style: italic;">; 测试定时器溢出位，为0则跳过一条指令</span>
   	<span style="color: #000000; font-weight: bold;">GOTO</span>   	TMR0_ISR <span style="color: #666666; font-style: italic;">; TMR0IF为1时，跳转到定时器服务程序</span>
   	<span style="color: #666666; font-style: italic;">;NOP</span>
   	BTFSS   INTCON<span style="color: #339933;">,</span> INT0IF <span style="color: #666666; font-style: italic;">; 测试外部中断int0的标志位，为0则跳一步</span>
   	RETFIE <span style="color: #666666; font-style: italic;">; 中断返回，会涉及到出栈操作</span>
   	<span style="color: #000000; font-weight: bold;">GOTO</span>   	INT0_ISR <span style="color: #666666; font-style: italic;">; 跳转到int0服务程序</span>
&nbsp;
TMR0_ISR <span style="color: #666666; font-style: italic;">; 定时器服务程序</span>
   	BTFSS   INTCON<span style="color: #339933;">,</span> TMR0IF  <span style="color: #666666; font-style: italic;">; 重新测试溢出位，防止干扰信号触发中断</span>
   	RETFIE
   	BCF  	INTCON<span style="color: #339933;">,</span> TMR0IF  <span style="color: #666666; font-style: italic;">; 清除溢出位</span>
   	<span style="color: #666666; font-style: italic;">;BSF  	INTCON, GIE ; </span>
   	INCF   	PORTD<span style="color: #339933;">,</span> F <span style="color: #666666; font-style: italic;">; D口加1</span>
   	MOVLF 	TMR0H<span style="color: #339933;">,</span> <span style="color: #0000ff;">0C2H</span> <span style="color: #666666; font-style: italic;">; 计数器初值进行重装</span>
   	MOVLF  	TMR0L<span style="color: #339933;">,</span> <span style="color: #0000ff;">0F7H</span>
&nbsp;
   	RETFIE <span style="color: #666666; font-style: italic;">; 中断返回</span>
&nbsp;
&nbsp;
INT0_ISR <span style="color: #666666; font-style: italic;">; 外部中断int0服务程序</span>
   	<span style="color: #666666; font-style: italic;">;CALL 	delay</span>
   	BTFSS   INTCON<span style="color: #339933;">,</span> INT0IF  <span style="color: #666666; font-style: italic;">; 重新测试溢出位，防止干扰信号触发中断</span>
   	RETFIE
   	BCF   	INTCON<span style="color: #339933;">,</span> INT0IF <span style="color: #666666; font-style: italic;">; 清除溢出位</span>
   	<span style="color: #666666; font-style: italic;">; 下面的几行通过更改定时器的分频比来改变定时间隔，每次减半</span>
   	MOVFF  	T0CON<span style="color: #339933;">,</span> R1
   	DECF   	R1<span style="color: #339933;">,</span> W
   	ANDWF   <span style="color: #0000ff;">07H</span>
   	MOVWF   T0CON
   	<span style="color: #666666; font-style: italic;">; D口加1</span>
   	INCF   	PORTD
   	<span style="color: #666666; font-style: italic;">;MOVLF  R1, 0005H</span>
   	<span style="color: #666666; font-style: italic;">;MOVF 	PORTD, W</span>
   	<span style="color: #666666; font-style: italic;">;SUBWF 	R1, W</span>
   	<span style="color: #666666; font-style: italic;">;BNZ 	NEXT</span>
   	<span style="color: #666666; font-style: italic;">;BSF 	PORTC, 0002H</span>
   	<span style="color: #666666; font-style: italic;">;CALL 	DELAY</span>
   	<span style="color: #666666; font-style: italic;">;BCF 	PORTC, 0002H</span>
NEXT
&nbsp;
   	RETFIE <span style="color: #666666; font-style: italic;">; 中断返回</span>
&nbsp;
SPEAKER
  	<span style="color: #00007f; font-weight: bold;">BSF</span>  PORTC<span style="color: #339933;">,</span> <span style="color: #0000ff;">0002H</span>
  	RETURN
DELAY  <span style="color: #666666; font-style: italic;">; 软件延时</span>
	movlw	<span style="color: #0000ff;">0xFF</span>
	movwf 	R1
L3
	movlw	<span style="color: #0000ff;">0x1f</span>
	movwf	R2
L2
	movlw	<span style="color: #0000ff;">0x1f</span>
	movwf	R3
L1
	decf	R3<span style="color: #339933;">,</span> F
	bnz		L1
	decf		R2<span style="color: #339933;">,</span> F
	bnz		L2
	decf		R1<span style="color: #339933;">,</span> F
	bnz		L3
	return
&nbsp;
<span style="color: #000000; font-weight: bold;">end</span></pre></td></tr></table></div>

<p>　　PIC的汇编实在诡异，有点被颠覆的感觉，原来汇编指令还可以这么来设计，原来汇编指令怎么设计都可以。最OOXX的一条指令就一个实现短转移的指令叫做BRA，意为BRAanch，看到这条指令的时候，我都诧异了，奶罩能做什么？哇塞！居然还能跳转！？奶罩居然可以无条件跳转？！Orz……另外PIC指令把单词缩写运用的淋漓尽致，譬如指令BTFSS，是一条位测试加条件跳转指令：BTFSS = Bit + Test + FileRegister + Skip + Set，用法：BTFSS  R1, 0003h, 寄存器R1的第3位为1时跳过<strong>下一条指令</strong>。真是震撼！</p>
<p>　　最后附上PIC18的中断体系硬件结构图，出自陈育斌老师的手笔：<br />
<div class="wp-caption aligncenter" style="width: 630px"><img alt="PIC18中断体系硬件结构示意图" src="http://www.dutor.net/files/images/pic_int.png" title="PIC18中断体系硬件结构示意图" width="620" height="450" /><p class="wp-caption-text">PIC18中断体系硬件结构示意图</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/11/pic-int-asm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>双缓冲</title>
		<link>http://www.dutor.net/index.php/2009/10/double-buffer/</link>
		<comments>http://www.dutor.net/index.php/2009/10/double-buffer/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 13:59:51 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[尚未分类]]></category>
		<category><![CDATA[OS基础]]></category>
		<category><![CDATA[单片机]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=1469</guid>
		<description><![CDATA[　　图示是PIC 18单片机中定时/计数器的结构图，PIC18是一种8位的单片机，但它的定时/计数器(的寄存器)却是16位的，所以为其装初值的时候就要分高低字节分别装载。于是问题就来了，由于定时计数器一般是连续工作，需要经常进行<strong>重装</strong>，如果对一个正在工作的定时计数器进行<strong>重装</strong>的话，就会产生高低字节不同步的状态，这是一种潜在的错误，尽管这种错误发生的概率很小。为了防止这种错误的发生，PIC单片机设计者采用了上图所示的双缓存结构。其中，TMR0H'和TMR0L组成了一个真正的定时计数器，而TMR0H是一个临时寄存器只有TMR0L的写信号有效时它才能被装入TMR0H'。当需要重装定时器时，首先应该将16位定时/计数的初值的高8位装入TMR0H临时寄存器，然后在向TMR0L写入低8位时由于TMR0L写信号有效，TMR0H也被同步地装入TMR0H'。这样，定时计算器就可以正确的工作，这就是硬件的双缓冲。]]></description>
			<content:encoded><![CDATA[<p>　　双缓冲，顾名思义，就是二级缓冲。缓冲是一块内存或者一个/一组寄存器，一般位于接口之中，接口是指硬件或者软件间的一种连接。接口可以协调通信双方的数据交换，比如并行/串行数据的转换，模拟/数据信号的转换，高速/低速设备间的匹配等。那么双缓冲又是什么呢？</p>
<p>　　一种双缓冲是硬件上的，是一种严格意义上的双缓冲。下面就是一个双缓冲结构的例子：<br />
<div class="wp-caption aligncenter" style="width: 359px"><img alt="PIC定时器中的双缓冲结构" src="http://www.dutor.net/files/images/db_buf.png" title="PIC定时器中的双缓冲结构" width="349" height="406" /><p class="wp-caption-text">PIC定时器中的双缓冲结构</p></div><br />
　　图示是PIC 18单片机中定时/计数器的结构图，PIC18是一种8位的单片机，但它的定时/计数器(的寄存器)却是16位的，所以为其装初值的时候就要分高低字节分别装载。于是问题就来了，由于定时计数器一般是连续工作，需要经常进行<strong>重装</strong>，如果对一个正在工作的定时计数器进行<strong>重装</strong>的话，就会产生高低字节不同步的状态，这是一种潜在的错误，尽管这种错误发生的概率很小。为了防止这种错误的发生，PIC单片机设计者采用了上图所示的双缓存结构。其中，TMR0H&#8217;和TMR0L组成了一个真正的定时计数器，而TMR0H是一个临时寄存器只有TMR0L的写信号有效时它才能被装入TMR0H&#8217;。当需要重装定时器时，首先应该将16位定时/计数的初值的高8位装入TMR0H临时寄存器，然后在向TMR0L写入低8位时由于TMR0L写信号有效，TMR0H也被同步地装入TMR0H&#8217;。这样，定时计算器就可以正确的工作，这就是硬件的双缓冲。</p>
<p>　　接触到&#8221;软件&#8221;的或者说逻辑的双缓冲，是在Chris写一个3D魔方的时候。最初的魔方在转动时画面会发生闪烁，后来采用的双缓存消除了闪烁。画面闪烁是因为程序是边计算图像的&#8221;桢&#8221;(输入法无此字)数据，边向显示器(显存)写出桢数据所造成的延迟感。解决方法就是，先将计算所得数据存入内存，得到一个完整桢后再&#8221;一次性&#8221;地写入显存。这也是一种双缓存，也是一种同步，但不是严格意义上的同步。另外，一个更好的方法就是采用利用多线程，创建一个可容纳多个桢的缓冲池作为共享，创建一个线程来计算桢数据并添加到缓冲池，创建另外一个线程从缓冲池中取出桢并写入显存。当然，正两个线程需要一定的同步机制来协调工作。要是再创建一个线程，痴痴地等待着Chris同学的鼠标就perfect了！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/10/double-buffer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I2C键盘扫描程序</title>
		<link>http://www.dutor.net/index.php/2009/05/i2c-keyboard-scan-procedure/</link>
		<comments>http://www.dutor.net/index.php/2009/05/i2c-keyboard-scan-procedure/#comments</comments>
		<pubDate>Wed, 06 May 2009 14:22:26 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=378</guid>
		<description><![CDATA[<pre lang="asm" line="1">
;#################################################################
;              这是一个键盘扫描程序 
;将得到的健值（01H-10H）在右边两位数码管显示 (data= XX) 
;程序采用中断结构，硬件连接上将INT_KEY信号与P3.2(INT0) 连接；
;普通的I2C通讯程序可以直接利用，为读数据子程序需要加延时
;这是ZLG7290芯片在读数据时有延时，在RDBYT中添加一个20US延时
;#################################################################
SDA		BIT	P1.0
SCL		BIT	P1.1  
WSLA		EQU	070H
RSLA		EQU	071H
DISDA		EQU	20H		;源数据块首地址
DISCON		EQU	08H		;写入数据个数		
DATA_1		EQU	30H		;变量区首地址
;********************************************************
	ORG	8000H 
	LJMP	8100H  
;********************************************************
</pre>]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox"><table><tr id="p3784"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
</pre></td><td class="code" id="p378code4"><pre class="asm" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">;#################################################################</span>
<span style="color: #666666; font-style: italic;">;              这是一个键盘扫描程序 </span>
<span style="color: #666666; font-style: italic;">;将得到的健值（01H-10H）在右边两位数码管显示 (data= XX) </span>
<span style="color: #666666; font-style: italic;">;程序采用中断结构，硬件连接上将INT_KEY信号与P3.2(INT0) 连接；</span>
<span style="color: #666666; font-style: italic;">;普通的I2C通讯程序可以直接利用，为读数据子程序需要加延时</span>
<span style="color: #666666; font-style: italic;">;这是ZLG7290芯片在读数据时有延时，在RDBYT中添加一个20US延时</span>
<span style="color: #666666; font-style: italic;">;#################################################################</span>
SDA		BIT	P1<span style="color: #339933;">.</span>0
SCL		BIT	P1<span style="color: #339933;">.</span>1  
WSLA		EQU	<span style="color: #0000ff;">070H</span>
RSLA		EQU	<span style="color: #0000ff;">071H</span>
DISDA		EQU	<span style="color: #0000ff;">20H</span>		<span style="color: #666666; font-style: italic;">;源数据块首地址</span>
DISCON		EQU	<span style="color: #0000ff;">08H</span>		<span style="color: #666666; font-style: italic;">;写入数据个数		</span>
DATA_1		EQU	<span style="color: #0000ff;">30H</span>		<span style="color: #666666; font-style: italic;">;变量区首地址</span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">8000H</span> 
	<span style="color: #000000; font-weight: bold;">LJMP</span>	<span style="color: #0000ff;">8100H</span>  
<span style="color: #666666; font-style: italic;">;********************************************************</span>
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">8003H</span>
	<span style="color: #000000; font-weight: bold;">LJMP</span>	INT_7290
<span style="color: #666666; font-style: italic;">;********************************************************</span>
<span style="color: #666666; font-style: italic;">;            初始化部分					          </span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
	<span style="color: #000000; font-weight: bold;">ORG</span>	<span style="color: #0000ff;">8100H</span> 
START<span style="color: #339933;">:</span> <span style="color: #00007f; font-weight: bold;">MOV</span>	<span style="color: #00007f;">SP</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">60H</span>
	CLR	P1<span style="color: #339933;">.</span>7   		<span style="color: #666666; font-style: italic;">;7290复位</span>
	LCALL	DELAY	
	<span style="color: #00007f; font-weight: bold;">SETB</span>	P1<span style="color: #339933;">.</span>7	
	<span style="color: #00007f; font-weight: bold;">SETB</span>	EA 			<span style="color: #666666; font-style: italic;">;开INT0中断</span>
	<span style="color: #00007f; font-weight: bold;">SETB</span>	EX0
	<span style="color: #00007f; font-weight: bold;">SETB</span>	IT0  		<span style="color: #666666; font-style: italic;">;触发极性为下降沿 	</span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
<span style="color: #666666; font-style: italic;">;           建立变量缓冲区	(30H-37H) 			          </span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">,</span>  #<span style="color: #0000ff;">13H</span>	<span style="color: #666666; font-style: italic;">;变量缓冲区(显示 data =   )</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">1</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">13H</span>	<span style="color: #666666; font-style: italic;">;注意：</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">2</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">13H</span> 	<span style="color: #666666; font-style: italic;">;变量取值范围0-F</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">3</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">12H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">4</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">10H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">5</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">11H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">6</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">10H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DATA_1<span style="color: #339933;">+</span><span style="color: #0000ff;">7</span><span style="color: #339933;">,</span>#<span style="color: #0000ff;">0DH</span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
<span style="color: #666666; font-style: italic;">;           通过查表建立显示缓冲区（20H-27H）				          </span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DPTR<span style="color: #339933;">,</span>#LEDSEG 	<span style="color: #666666; font-style: italic;">;开始对变量查表</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R7<span style="color: #339933;">,</span>#DISCON		<span style="color: #666666; font-style: italic;">;写入数据个数	</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R0<span style="color: #339933;">,</span>#DISDA  		<span style="color: #666666; font-style: italic;">;源数据块首地址</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R1<span style="color: #339933;">,</span>#DATA_1
LOOP1<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">MOV</span>	A<span style="color: #339933;">,</span>@R1
	MOVC	A<span style="color: #339933;">,</span>@A<span style="color: #339933;">+</span>DPTR 		<span style="color: #666666; font-style: italic;">;查表得对应的字形码</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	@R0<span style="color: #339933;">,</span>A 			<span style="color: #666666; font-style: italic;">;送显示缓冲区</span>
	<span style="color: #00007f; font-weight: bold;">INC</span>	R1
	<span style="color: #00007f; font-weight: bold;">INC</span>	R0
	DJNZ	R7<span style="color: #339933;">,</span>LOOP1  
<span style="color: #666666; font-style: italic;">;********************************************************</span>
<span style="color: #666666; font-style: italic;">;	向7290B写入数据，以显示&quot;data=  &quot;</span>
<span style="color: #666666; font-style: italic;">;********************************************************</span>
<span style="color: #00007f; font-weight: bold;">LOOP</span><span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">MOV</span>	R7<span style="color: #339933;">,</span>#DISCON
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R2<span style="color: #339933;">,</span>#<span style="color: #0000ff;">10H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R3<span style="color: #339933;">,</span>#WSLA
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R0<span style="color: #339933;">,</span>#DISDA 
	LCALL	WRNBYT			<span style="color: #666666; font-style: italic;">;调显示子程序</span>
	LCALL	DELAY 			<span style="color: #666666; font-style: italic;">;使显示稳定 </span>
	SJMP	<span style="color: #00007f; font-weight: bold;">LOOP</span> 
<span style="color: #666666; font-style: italic;">;******************************************************************</span>
LEDSEG<span style="color: #339933;">:</span>	<span style="color: #000000; font-weight: bold;">DB</span>	<span style="color: #0000ff;">0FCH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">60H</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0DAH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0F2H</span><span style="color: #339933;">,</span><span style="color: #0000ff;">66H</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0B6H</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0BEH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0E4H</span>	<span style="color: #666666; font-style: italic;">;0-7的字形码</span>
		<span style="color: #000000; font-weight: bold;">DB</span>	<span style="color: #0000ff;">0FEH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0F6H</span><span style="color: #339933;">,</span><span style="color: #0000ff;">0EEH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">3EH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">9CH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">7AH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">9EH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">8EH</span>		<span style="color: #666666; font-style: italic;">;8-F的字形码</span>
		<span style="color: #000000; font-weight: bold;">DB</span>	<span style="color: #0000ff;">0FAH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">1EH</span><span style="color: #339933;">,</span><span style="color: #0000ff;">12H</span><span style="color: #339933;">,</span><span style="color: #0000ff;">00H</span>						<span style="color: #666666; font-style: italic;">;a,t,= 和熄灭码</span>
<span style="color: #666666; font-style: italic;">;******************************************************************</span>
<span style="color: #666666; font-style: italic;">;	拆分程序（将A中的数据拆分为两个四位16进制数并查表）</span>
<span style="color: #666666; font-style: italic;">;	( 结果在R4、R3中 ) </span>
<span style="color: #666666; font-style: italic;">;******************************************************************</span>
CF<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">02H</span> 		<span style="color: #666666; font-style: italic;">;将A中的数据拆分为两个四位16进制数并查表</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	DPH  	<span style="color: #666666; font-style: italic;">;	</span>
<span style="color: #00007f; font-weight: bold;">PUSH</span>	DPL
	<span style="color: #00007f; font-weight: bold;">MOV</span>	DPTR<span style="color: #339933;">,</span>#LEDSEG
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R2<span style="color: #339933;">,</span>A
	ANL	A<span style="color: #339933;">,</span>#<span style="color: #0000ff;">0FH</span>
	MOVC	A<span style="color: #339933;">,</span>@A<span style="color: #339933;">+</span>DPTR
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R3<span style="color: #339933;">,</span>A
	<span style="color: #00007f; font-weight: bold;">MOV</span>	A<span style="color: #339933;">,</span>R2
	SWAP	A
	ANL	A<span style="color: #339933;">,</span>#<span style="color: #0000ff;">0FH</span>
	MOVC	A<span style="color: #339933;">,</span>@A<span style="color: #339933;">+</span>DPTR
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R4<span style="color: #339933;">,</span>A
	<span style="color: #00007f; font-weight: bold;">POP</span>	DPL
	<span style="color: #00007f; font-weight: bold;">POP</span>	DPH
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">02H</span>
	<span style="color: #00007f; font-weight: bold;">RET</span>  
<span style="color: #666666; font-style: italic;">;*******************************************************************</span>
<span style="color: #666666; font-style: italic;">;          中断服务程序 INT_7290:（INT0）</span>
<span style="color: #666666; font-style: italic;">;*******************************************************************	</span>
INT_7290<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">00H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">02H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">03H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">04H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">07H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	ACC
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	PSW
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R0<span style="color: #339933;">,</span>#<span style="color: #0000ff;">28H</span>	<span style="color: #666666; font-style: italic;">;状态数据区首址</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R7<span style="color: #339933;">,</span>#<span style="color: #0000ff;">04H</span>	<span style="color: #666666; font-style: italic;">;取状态数据个数</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R2<span style="color: #339933;">,</span>#<span style="color: #0000ff;">00H</span> <span style="color: #666666; font-style: italic;">;内部数据首地址</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R3<span style="color: #339933;">,</span>#WSLA<span style="color: #666666; font-style: italic;">;取器件地址（写）</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R4<span style="color: #339933;">,</span>#RSLA<span style="color: #666666; font-style: italic;">;取器件地址（读）</span>
 	LCALL	RDADD	<span style="color: #666666; font-style: italic;">;读出7290的00H-03H数据存于28H-2BH </span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>			<span style="color: #666666; font-style: italic;">;设定一个断点,以观察读出的4个数据</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	A<span style="color: #339933;">,</span><span style="color: #0000ff;">29H</span>	<span style="color: #666666; font-style: italic;">;取健值</span>
	LCALL	CF		<span style="color: #666666; font-style: italic;">;拆分、查表</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	<span style="color: #0000ff;">20H</span><span style="color: #339933;">,</span>R3	<span style="color: #666666; font-style: italic;">;送显示缓冲区（最低两位数码管）</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	<span style="color: #0000ff;">21H</span><span style="color: #339933;">,</span>R4
	<span style="color: #00007f; font-weight: bold;">POP</span>	PSW
	<span style="color: #00007f; font-weight: bold;">POP</span>	ACC
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">07H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">04H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">03H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">02H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">00H</span>
	RETI
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
DELAY<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">00H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">01H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>	R0<span style="color: #339933;">,</span>#<span style="color: #0000ff;">00H</span>
DELAY1<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">MOV</span>	R1<span style="color: #339933;">,</span>#<span style="color: #0000ff;">00H</span>
	DJNZ	R1<span style="color: #339933;">,</span>$
	DJNZ	R0<span style="color: #339933;">,</span>DELAY1
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">01H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span>	<span style="color: #0000ff;">00H</span>
	<span style="color: #00007f; font-weight: bold;">RET</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
&nbsp;
<span style="color: #666666; font-style: italic;">;相关的I2C子程序（WRNBYT、WRBYT、STOP、CACK、STA）参见8.1.4 。这里省略</span>
<span style="color: #666666; font-style: italic;">;*******************************************************************</span>
<span style="color: #666666; font-style: italic;">;【附录一】由汇编语言编制的I2C通讯子程序</span>
<span style="color: #666666; font-style: italic;">;【提  示】下列程序是在系统时钟为12MHZ（或11.0592MHZ），即NOP指令为1微秒左右。</span>
<span style="color: #666666; font-style: italic;">;（1）带有内部单元地址的多字节写操作子程序 WRNBYT</span>
<span style="color: #666666; font-style: italic;">;*******************************************************************</span>
<span style="color: #666666; font-style: italic;">;通用的I2C通讯子程序（多字节写操作）</span>
<span style="color: #666666; font-style: italic;">;入口参数R7字节数,R0:源数据块首地址</span>
<span style="color: #666666; font-style: italic;">;R0原数据块首地址；R2从器件内部子地址;R3:外围器件地址（写）</span>
<span style="color: #666666; font-style: italic;">;相关子程序WRBYT、STOP、CACK、STA</span>
<span style="color: #666666; font-style: italic;">;*******************************************************************	</span>
WRNBYT<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">PUSH</span>	PSW		
		<span style="color: #00007f; font-weight: bold;">PUSH</span>	ACC				
WRADD<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>R3		<span style="color: #666666; font-style: italic;">;取外围器件地地址（包含r/w=0）	</span>
		LCALL	STA		<span style="color: #666666; font-style: italic;">;发送起始信号S  </span>
		LCALL	WRBYT		<span style="color: #666666; font-style: italic;">;发送外围地址</span>
		LCALL	CACK		<span style="color: #666666; font-style: italic;">;检测外围器件的应答信号</span>
		<span style="color: #00007f; font-weight: bold;">JB</span>		F0<span style="color: #339933;">,</span>WRADD	<span style="color: #666666; font-style: italic;">;如果应</span>
		<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>R2
		LCALL	WRBYT		<span style="color: #666666; font-style: italic;">;发送内部寄存器首地址</span>
		LCALL	CACK		<span style="color: #666666; font-style: italic;">;检测外围器件的应答信号</span>
		<span style="color: #00007f; font-weight: bold;">JB</span>		F0<span style="color: #339933;">,</span>WRADD	<span style="color: #666666; font-style: italic;">;如果应答不正确返回重来 	</span>
WRDA<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>@R0
		LCALL	WRBYT		<span style="color: #666666; font-style: italic;">;发送外围地址</span>
		LCALL	CACK		<span style="color: #666666; font-style: italic;">;检测外围器件的应答信号</span>
		<span style="color: #00007f; font-weight: bold;">JB</span>		F0<span style="color: #339933;">,</span>WRADD	<span style="color: #666666; font-style: italic;">;如果应答不正确返回重来</span>
		<span style="color: #00007f; font-weight: bold;">INC</span>		R0
		DJNZ  	R7<span style="color: #339933;">,</span>WRDA
		LCALL	STOP 	
		<span style="color: #00007f; font-weight: bold;">POP</span>		ACC
		<span style="color: #00007f; font-weight: bold;">POP</span>		PSW
		<span style="color: #00007f; font-weight: bold;">RET</span> 	       
<span style="color: #666666; font-style: italic;">;*******************************************************************</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">;（2）带有内部单元地址的多字节读操作子程序 RDADD </span>
<span style="color: #666666; font-style: italic;">;*******************************************************************</span>
<span style="color: #666666; font-style: italic;">;通用的I2C通讯子程序（多字节读操作）</span>
<span style="color: #666666; font-style: italic;">;入口参数R7字节数；</span>
<span style="color: #666666; font-style: italic;">;R0目标数据块首地址；R2从器件内部子地址；</span>
<span style="color: #666666; font-style: italic;">;R3器件地址（写）；R4器件地址（读）</span>
<span style="color: #666666; font-style: italic;">;相关子程序WRBYT、STOP、CACK、STA、MNACK </span>
<span style="color: #666666; font-style: italic;">;*******************************************************************	</span>
RDADD<span style="color: #339933;">:</span>  <span style="color: #00007f; font-weight: bold;">PUSH</span>	PSW			<span style="color: #666666; font-style: italic;">;从PCF8563的02H单元读入7个参数</span>
		<span style="color: #00007f; font-weight: bold;">PUSH</span>	ACC			<span style="color: #666666; font-style: italic;">;存放于20H-26H单元	</span>
RDADD1<span style="color: #339933;">:</span>	LCALL	STA 
		<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>R3		<span style="color: #666666; font-style: italic;">;取器件地址（写）</span>
		LCALL	WRBYT		<span style="color: #666666; font-style: italic;">;发送外围地址</span>
		LCALL	CACK		<span style="color: #666666; font-style: italic;">;检测外围器件的应答信号</span>
		<span style="color: #00007f; font-weight: bold;">JB</span>		F0<span style="color: #339933;">,</span>RDADD1	<span style="color: #666666; font-style: italic;">;如果应答不正确返回重来</span>
		<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>R2		<span style="color: #666666; font-style: italic;">;取内部地址	</span>
		LCALL	WRBYT		<span style="color: #666666; font-style: italic;">;发送外围地址</span>
		LCALL	CACK		<span style="color: #666666; font-style: italic;">;检测外围器件的应答信号</span>
		<span style="color: #00007f; font-weight: bold;">JB</span>		F0<span style="color: #339933;">,</span>RDADD1	<span style="color: #666666; font-style: italic;">;如果应答不正确返回重来	</span>
		LCALL	STA
		<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>R4		<span style="color: #666666; font-style: italic;">;取器件地址（读）</span>
		LCALL	WRBYT		<span style="color: #666666; font-style: italic;">;发送外围地址</span>
		LCALL	CACK		<span style="color: #666666; font-style: italic;">;检测外围器件的应答信号</span>
		<span style="color: #00007f; font-weight: bold;">JB</span>		F0<span style="color: #339933;">,</span>RDADD1	<span style="color: #666666; font-style: italic;">;如果应答不正确返回重来</span>
RDN<span style="color: #339933;">:</span>	LCALL	RDBYT 	
		<span style="color: #00007f; font-weight: bold;">MOV</span>		@R0<span style="color: #339933;">,</span>A
		DJNZ	R7<span style="color: #339933;">,</span>ACK
		LCALL	MNACK
		LCALL	STOP	
		<span style="color: #00007f; font-weight: bold;">POP</span>		ACC
		<span style="color: #00007f; font-weight: bold;">POP</span>		PSW
		<span style="color: #00007f; font-weight: bold;">RET</span>
ACK<span style="color: #339933;">:</span>	LCALL	MACK
		<span style="color: #00007f; font-weight: bold;">INC</span>		R0
		SJMP	RDN 
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">;（3）I2C各个信号子程序</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						启动信号子程序S </span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
STA<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">SETB</span>	SDA		<span style="color: #666666; font-style: italic;">;启动信号S</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL
		<span style="color: #00007f; font-weight: bold;">NOP</span>				<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>	
		CLR		SDA
		<span style="color: #00007f; font-weight: bold;">NOP</span>				<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span> 	
		CLR		SCL
		<span style="color: #00007f; font-weight: bold;">RET</span> 
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						停止信号子程序P </span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
STOP<span style="color: #339933;">:</span>	CLR		SDA 	<span style="color: #666666; font-style: italic;">;停止信号P</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL
		<span style="color: #00007f; font-weight: bold;">NOP</span>				<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>	
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SDA
		<span style="color: #00007f; font-weight: bold;">NOP</span>				<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>	
		CLR		SCL
		CLR		SDA
		<span style="color: #00007f; font-weight: bold;">RET</span> 
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						应答信号子程序   MACK</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
MACK<span style="color: #339933;">:</span>	CLR		SDA	<span style="color: #666666; font-style: italic;">;发送应答信号ACK</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL
		<span style="color: #00007f; font-weight: bold;">NOP</span>			<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		CLR		SCL
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SDA
		<span style="color: #00007f; font-weight: bold;">RET</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						非应答法信号子程序MNACK</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
MNACK<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">SETB</span>	SDA		<span style="color: #666666; font-style: italic;">;发送非应答信号NACK</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL
		<span style="color: #00007f; font-weight: bold;">NOP</span>				<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		CLR		SCL
		CLR		SDA
		<span style="color: #00007f; font-weight: bold;">RET</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						应答检测子程序CACK</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
CACK<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">SETB</span>	SDA		<span style="color: #666666; font-style: italic;">;应答位检测子程序</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL 
		CLR		F0
		<span style="color: #00007f; font-weight: bold;">MOV</span>		<span style="color: #000000; font-weight: bold;">C</span><span style="color: #339933;">,</span>SDA	<span style="color: #666666; font-style: italic;">;采样SDA</span>
		<span style="color: #00007f; font-weight: bold;">JNC</span>		CEND	<span style="color: #666666; font-style: italic;">;应答正确时转CEND</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	F0		<span style="color: #666666; font-style: italic;">;应答错误时F0置一</span>
CEND<span style="color: #339933;">:</span>	CLR		SCL
		<span style="color: #00007f; font-weight: bold;">RET</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						发送一个字节子程序WRBYT</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
WRBYT<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">06H</span>
<span style="color: #00007f; font-weight: bold;">MOV</span>		R6<span style="color: #339933;">,</span>#<span style="color: #0000ff;">08H</span>		<span style="color: #666666; font-style: italic;">;发送一个字节子程序 </span>
WLP<span style="color: #339933;">:</span>	RLC		A 			<span style="color: #666666; font-style: italic;">;(入口参数A)</span>
		<span style="color: #00007f; font-weight: bold;">MOV</span>		SDA<span style="color: #339933;">,</span><span style="color: #000000; font-weight: bold;">C</span>
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL
		<span style="color: #00007f; font-weight: bold;">NOP</span>					<span style="color: #666666; font-style: italic;">;产生4.7US延时</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		<span style="color: #00007f; font-weight: bold;">NOP</span>
		CLR		SCL
		DJNZ	R6<span style="color: #339933;">,</span>WLP
		<span style="color: #00007f; font-weight: bold;">POP</span>		<span style="color: #0000ff;">06H</span>
		<span style="color: #00007f; font-weight: bold;">RET</span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
<span style="color: #666666; font-style: italic;">;						接收一个字节子程序RDBYT </span>
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
RDBYT<span style="color: #339933;">:</span> 	<span style="color: #00007f; font-weight: bold;">PUSH</span>	<span style="color: #0000ff;">06H</span>
		<span style="color: #00007f; font-weight: bold;">MOV</span>		R6<span style="color: #339933;">,</span>#<span style="color: #0000ff;">08H</span>	<span style="color: #666666; font-style: italic;">;接收一个字节子程序</span>
RLP<span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">SETB</span>	SDA
		<span style="color: #00007f; font-weight: bold;">SETB</span>	SCL
<span style="color: #666666; font-style: italic;">;  *******************************************</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>			<span style="color: #666666; font-style: italic;">;!!!!!产生大于15微秒的延时!!!!!!</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span> 		<span style="color: #666666; font-style: italic;">;注意这是专门为ZLG7290</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span> 		<span style="color: #666666; font-style: italic;">;添加的20微秒延时部分</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
	<span style="color: #00007f; font-weight: bold;">NOP</span>
<span style="color: #666666; font-style: italic;">;  ********************************************	</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span>		<span style="color: #000000; font-weight: bold;">C</span><span style="color: #339933;">,</span>SDA
	<span style="color: #00007f; font-weight: bold;">MOV</span>		A<span style="color: #339933;">,</span>R2
	RLC		A
	<span style="color: #00007f; font-weight: bold;">MOV</span>		R2<span style="color: #339933;">,</span>A
	CLR		SCL
	DJNZ	R6<span style="color: #339933;">,</span>RLP 		<span style="color: #666666; font-style: italic;">;(出口参数R2)</span>
	<span style="color: #00007f; font-weight: bold;">POP</span>		<span style="color: #0000ff;">06H</span>
	<span style="color: #00007f; font-weight: bold;">RET</span>  
<span style="color: #666666; font-style: italic;">;**********************************************************************</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/05/i2c-keyboard-scan-procedure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>51单片机A/D转换器</title>
		<link>http://www.dutor.net/index.php/2009/05/51-micro-controller/</link>
		<comments>http://www.dutor.net/index.php/2009/05/51-micro-controller/#comments</comments>
		<pubDate>Wed, 06 May 2009 14:18:19 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=375</guid>
		<description><![CDATA[
<pre lang="asm" line="1">

	dat 	bit p3.2	;定义端口号
	clk	bit p3.3	
	cs	bit p3.4

	org	8000h		;程序定位及跳转指令的设置
	ljmp	8100h
	org	8100h

start:
	mov	sp, #60h	;定义堆栈底位置
stable:
	mov	r3, #00h	;循环体执行次数:256
	mov	r6, #00h	;寄存器清零
	mov	r7, #00h	;寄存器清零
loop:
				;取平均值主要是为了减小
				;高速模数转换干扰产生的误差
	lcall	tlc549_adc	;调用模数转换子程序
	add	a, r6		;向R7-R6累加a的值256次
	mov	r6, a
	mov 	a, #00h
	addc	a, r7
	mov	r7, a	
	lcall	delay
	djnz	r3, loop
	mov	a, r7		;将R7中的平均值送到a
	cpl	a		;a取反
	mov	p1, a		;输出a的值
	sjmp	stable

tlc549_adc:			;模数转换的驱动子程序
	push	07h
	clr	a		;清零
	clr	clk		;清零
	mov	r7, #08h	;由于是串行输入，每字节需要8次读入
	clr	cs		;片选信号置低位，选中模数转换器
loop1:
	setb	clk		;开始读取数据
	mov	c, dat
	rlc	a		;诸位读取，送到a
	clr	clk
	djnz	r7, loop1
	setb	cs
	setb	clk
	pop	07h
ret

delay:				;微小的延时，用来同步和协调单片机
				;与模数转换器的工作步调
	push	00h
	mov	r0, #00h
	djnz	r0, $
	pop	00h
ret


end
</pre>
]]></description>
			<content:encoded><![CDATA[
<div class="wp_codebox"><table><tr id="p3755"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code" id="p375code5"><pre class="asm" style="font-family:monospace;">&nbsp;
	dat 	bit p3<span style="color: #339933;">.</span>2	<span style="color: #666666; font-style: italic;">;定义端口号</span>
	clk	bit p3<span style="color: #339933;">.</span>3	
	<span style="color: #00007f;">cs</span>	bit p3<span style="color: #339933;">.</span>4
&nbsp;
	<span style="color: #000000; font-weight: bold;">org</span>	<span style="color: #0000ff;">8000h</span>		<span style="color: #666666; font-style: italic;">;程序定位及跳转指令的设置</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span>	<span style="color: #0000ff;">8100h</span>
	<span style="color: #000000; font-weight: bold;">org</span>	<span style="color: #0000ff;">8100h</span>
&nbsp;
start<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	<span style="color: #00007f;">sp</span><span style="color: #339933;">,</span> #<span style="color: #0000ff;">60h</span>	<span style="color: #666666; font-style: italic;">;定义堆栈底位置</span>
stable<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r3<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>	<span style="color: #666666; font-style: italic;">;循环体执行次数:256</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>	<span style="color: #666666; font-style: italic;">;寄存器清零</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>	<span style="color: #666666; font-style: italic;">;寄存器清零</span>
<span style="color: #00007f; font-weight: bold;">loop</span><span style="color: #339933;">:</span>
				<span style="color: #666666; font-style: italic;">;取平均值主要是为了减小</span>
				<span style="color: #666666; font-style: italic;">;高速模数转换干扰产生的误差</span>
	lcall	tlc549_adc	<span style="color: #666666; font-style: italic;">;调用模数转换子程序</span>
	<span style="color: #00007f; font-weight: bold;">add</span>	a<span style="color: #339933;">,</span> r6		<span style="color: #666666; font-style: italic;">;向R7-R6累加a的值256次</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> a
	<span style="color: #00007f; font-weight: bold;">mov</span> 	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>
	addc	a<span style="color: #339933;">,</span> r7
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> a	
	lcall	delay
	djnz	r3<span style="color: #339933;">,</span> <span style="color: #00007f; font-weight: bold;">loop</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	a<span style="color: #339933;">,</span> r7		<span style="color: #666666; font-style: italic;">;将R7中的平均值送到a</span>
	cpl	a		<span style="color: #666666; font-style: italic;">;a取反</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	p1<span style="color: #339933;">,</span> a		<span style="color: #666666; font-style: italic;">;输出a的值</span>
	sjmp	stable
&nbsp;
tlc549_adc<span style="color: #339933;">:</span>			<span style="color: #666666; font-style: italic;">;模数转换的驱动子程序</span>
	<span style="color: #00007f; font-weight: bold;">push</span>	<span style="color: #0000ff;">07h</span>
	clr	a		<span style="color: #666666; font-style: italic;">;清零</span>
	clr	clk		<span style="color: #666666; font-style: italic;">;清零</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">08h</span>	<span style="color: #666666; font-style: italic;">;由于是串行输入，每字节需要8次读入</span>
	clr	<span style="color: #00007f;">cs</span>		<span style="color: #666666; font-style: italic;">;片选信号置低位，选中模数转换器</span>
loop1<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	clk		<span style="color: #666666; font-style: italic;">;开始读取数据</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	<span style="color: #000000; font-weight: bold;">c</span><span style="color: #339933;">,</span> dat
	rlc	a		<span style="color: #666666; font-style: italic;">;诸位读取，送到a</span>
	clr	clk
	djnz	r7<span style="color: #339933;">,</span> loop1
	<span style="color: #00007f; font-weight: bold;">setb</span>	<span style="color: #00007f;">cs</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	clk
	<span style="color: #00007f; font-weight: bold;">pop</span>	<span style="color: #0000ff;">07h</span>
<span style="color: #00007f; font-weight: bold;">ret</span>
&nbsp;
delay<span style="color: #339933;">:</span>				<span style="color: #666666; font-style: italic;">;微小的延时，用来同步和协调单片机</span>
				<span style="color: #666666; font-style: italic;">;与模数转换器的工作步调</span>
	<span style="color: #00007f; font-weight: bold;">push</span>	<span style="color: #0000ff;">00h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r0<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>
	djnz	r0<span style="color: #339933;">,</span> $
	<span style="color: #00007f; font-weight: bold;">pop</span>	<span style="color: #0000ff;">00h</span>
<span style="color: #00007f; font-weight: bold;">ret</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">end</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/05/51-micro-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>单片机蜂鸣器</title>
		<link>http://www.dutor.net/index.php/2009/04/microcontroller-buzz/</link>
		<comments>http://www.dutor.net/index.php/2009/04/microcontroller-buzz/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 14:16:25 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=317</guid>
		<description><![CDATA[<strong>功能描述</strong>



<blockquote>功能很简单，程序更简单：</blockquote>


<blockquote>
简单的蜂鸣器实验程序：本程序通过在P1.1输出一个音频范围的方波，驱动实验板上的蜂鸣器发出蜂鸣声，其中包含有一个定时模块，作用是使输出的方波频率在人耳朵听觉能力之内的20KHZ以下，如果没有这个延时程序的话，输出的频率将大大超出人耳朵的听觉能力，我们将不能听到声音。更改定时常数，可以改变输出频率，也就可以调整蜂鸣器的音调。</blockquote>]]></description>
			<content:encoded><![CDATA[<p><strong>功能描述</strong></p>
<blockquote><p>功能很简单，程序更简单：</p></blockquote>
<blockquote><p>
简单的蜂鸣器实验程序：本程序通过在P1.1输出一个音频范围的方波，驱动实验板上的蜂鸣器发出蜂鸣声，其中包含有一个定时模块，作用是使输出的方波频率在人耳朵听觉能力之内的20KHZ以下，如果没有这个延时程序的话，输出的频率将大大超出人耳朵的听觉能力，我们将不能听到声音。更改定时常数，可以改变输出频率，也就可以调整蜂鸣器的音调。</p></blockquote>
<p><script type="text/javascript"><!--
google_ad_client = "pub-8781012522518994";
/* 468x15, chk_matlab */
google_ad_slot = "0885612183";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>

<div class="wp_codebox"><table><tr id="p3176"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p317code6"><pre class="asm" style="font-family:monospace;"> 	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8000h</span>		<span style="color: #666666; font-style: italic;">;定位</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span> 	start
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8100h</span>
start<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> 	<span style="color: #00007f;">sp</span><span style="color: #339933;">,</span> #<span style="color: #0000ff;">60h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tmod<span style="color: #339933;">,</span> #<span style="color: #0000ff;">10h</span>	<span style="color: #666666; font-style: italic;">;置T1为方式1</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tl1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">010h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">010h</span>	<span style="color: #666666; font-style: italic;">;设初值，定时为50ms</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	tr1		<span style="color: #666666; font-style: italic;">;启动定时器T1</span>
<span style="color: #00007f; font-weight: bold;">loop</span><span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">jnb</span>	tf1<span style="color: #339933;">,</span> $
&nbsp;
	clr	tf1
	<span style="color: #00007f; font-weight: bold;">mov</span>	tl1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">033h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0feh</span>
	<span style="color: #00007f; font-weight: bold;">jb</span>	p1<span style="color: #339933;">.</span>0<span style="color: #339933;">,</span> <span style="color: #00007f; font-weight: bold;">loop</span>
	cpl	p1<span style="color: #339933;">.</span>1
down<span style="color: #339933;">:</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
	<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>[warning]This is <em>original</em> article, you could copy it freely with my site links!<br />此日志为dutor原创，您可以自由转载，添加原文链接我将万分感激！[/warning]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/04/microcontroller-buzz/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>单片机简易电子琴</title>
		<link>http://www.dutor.net/index.php/2009/04/microcontroller-simple-piano/</link>
		<comments>http://www.dutor.net/index.php/2009/04/microcontroller-simple-piano/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 14:12:53 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=314</guid>
		<description><![CDATA[<strong>功能描述</strong>


<blockquote>由p1口外接按键开关，p3.3接蜂鸣器组成。</blockquote>

<pre lang="asm" line="1">
 	org 	8000h		;定位
	ljmp 	start
	org 	8100h
start:
	mov 	sp, #60h
	mov	tmod, #10h	;置T1为方式1
;	mov	tl1, #010h
;	mov	th1, #010h	;设初值，定时为50ms
	setb	tr1		;启动定时器T1
</pre>]]></description>
			<content:encoded><![CDATA[<p><strong>功能描述</strong></p>
<blockquote><p>由p1口外接按键开关，p3.3接蜂鸣器组成。</p></blockquote>

<div class="wp_codebox"><table><tr id="p3147"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code" id="p314code7"><pre class="asm" style="font-family:monospace;"> 	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8000h</span>		<span style="color: #666666; font-style: italic;">;定位</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span> 	start
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8100h</span>
start<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> 	<span style="color: #00007f;">sp</span><span style="color: #339933;">,</span> #<span style="color: #0000ff;">60h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tmod<span style="color: #339933;">,</span> #<span style="color: #0000ff;">10h</span>	<span style="color: #666666; font-style: italic;">;置T1为方式1</span>
<span style="color: #666666; font-style: italic;">;	mov	tl1, #010h</span>
<span style="color: #666666; font-style: italic;">;	mov	th1, #010h	;设初值，定时为50ms</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	tr1		<span style="color: #666666; font-style: italic;">;启动定时器T1</span>
&nbsp;
loop1<span style="color: #339933;">:</span>	
	<span style="color: #00007f; font-weight: bold;">mov</span>	p1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0ffh</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	a<span style="color: #339933;">,</span> p1
	<span style="color: #00007f; font-weight: bold;">mov</span>	r5<span style="color: #339933;">,</span> a
	cpl 	a
	<span style="color: #00007f; font-weight: bold;">jz</span>	loop1
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">01h</span><span style="color: #339933;">,</span> loop2
	sjmp	do
loop2<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">02h</span><span style="color: #339933;">,</span> loop3
	sjmp	ra
loop3<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">04h</span><span style="color: #339933;">,</span> loop4
	sjmp	mi
loop4<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">08h</span><span style="color: #339933;">,</span> loop5
	sjmp	fa
loop5<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">10h</span><span style="color: #339933;">,</span> loop6
	sjmp	so
loop6<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">20h</span><span style="color: #339933;">,</span> loop7
	sjmp	la
loop7<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">40h</span><span style="color: #339933;">,</span> loop8
	sjmp	xi
loop8<span style="color: #339933;">:</span>
	cjne	a<span style="color: #339933;">,</span> #<span style="color: #0000ff;">80h</span><span style="color: #339933;">,</span> loop1
	sjmp	hdo
	sjmp	loop1
&nbsp;
do<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0f9h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">21h</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
ra<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0f9h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0e0h</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
mi<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fah</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">08bh</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
fa<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fah</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0d7h</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
so<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fbh</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">67h</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
la<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fbh</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0e8h</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
xi<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fch</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">5bh</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
hdo<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fch</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">8eh</span>
	sjmp	<span style="color: #00007f; font-weight: bold;">loop</span>
&nbsp;
<span style="color: #00007f; font-weight: bold;">loop</span><span style="color: #339933;">:</span>
	lcall 	music
	sjmp	loop1
music<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tl1<span style="color: #339933;">,</span> r6
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> r7
&nbsp;
loop9<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">jnb</span>	tf1<span style="color: #339933;">,</span> $
	clr	tf1
	<span style="color: #00007f; font-weight: bold;">mov</span>	tl1<span style="color: #339933;">,</span> r6
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> r7
	cpl	p3<span style="color: #339933;">.</span>3
	<span style="color: #00007f; font-weight: bold;">mov</span>	a<span style="color: #339933;">,</span> p1
	cpl	a
	<span style="color: #00007f; font-weight: bold;">jnz</span>	loop9
	<span style="color: #00007f; font-weight: bold;">setb</span>	p3<span style="color: #339933;">.</span>3
down<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">ret</span>
	<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>[warning]This is <em>original</em> article, you could copy it freely with my site links!<br />此日志为dutor原创，您可以自由转载，添加原文链接我将万分感激！[/warning]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/04/microcontroller-simple-piano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>单片机中断实验</title>
		<link>http://www.dutor.net/index.php/2009/04/microcontroller-interrupt-experiment/</link>
		<comments>http://www.dutor.net/index.php/2009/04/microcontroller-interrupt-experiment/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 14:05:40 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=311</guid>
		<description><![CDATA[<strong>功能描述</strong>


<blockquote>正常情况下(p3.2为高电平), p3.3的电平以一定的频率连续翻转，当p3.2为低电平时，触发int0外部中断，进入中断服务程序，另p3.3保持低电平，并将p1端口加1。p3.2外接一个按键开关时，中断服务程序有防抖动的功能，这时通过一定的延时(通常为10ms--20ms)来实现的。</blockquote>

<strong>程序</strong>
<pre lang="asm" line="1">
 	org 	8000h		;定位
	ljmp 	start
	org 	8003h		;中断向量
	ljmp	int_0
	org 	8100h
start:
	mov 	sp, #60h
	setb	ex0		;开int0中断
	setb 	ea		;开总中断
	mov	tcon, #00h	;低电平触发
	mov	r3, #00h
	mov	a, r3
	cpl	a
loop3:				;死循环
	mov	p1, a
	cpl	p3.3		;翻转
	lcall	DELAY		;延时
	sjmp	loop3

int_0:				;中断服务子程序
	push	psw
	lcall	DELAY		;防抖动
	setb	p3.3
	inc	r3
	mov	a, r3
	cpl	a
	mov	p1, a
	jnb	p3.2, $		;查询，防止多次中断
	lcall	DELAY		;还是防抖动
	pop	psw
	reti

DELAY:  PUSH 06H
	PUSH 07H
	MOV R7, #70H
LABEL1:
	MOV R6, #70H
LABEL2:
	DJNZ R6, $
	DJNZ R7, LABEL1
	POP 07H
	POP 06H
	RET
	END
</pre>

]]></description>
			<content:encoded><![CDATA[<p><strong>功能描述</strong></p>
<blockquote><p>正常情况下(p3.2为高电平), p3.3的电平以一定的频率连续翻转，当p3.2为低电平时，触发int0外部中断，进入中断服务程序，另p3.3保持低电平，并将p1端口加1。p3.2外接一个按键开关时，中断服务程序有防抖动的功能，这时通过一定的延时(通常为10ms&#8211;20ms)来实现的。</p></blockquote>
<p><strong>程序</strong></p>

<div class="wp_codebox"><table><tr id="p3118"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p311code8"><pre class="asm" style="font-family:monospace;"> 	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8000h</span>		<span style="color: #666666; font-style: italic;">;定位</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span> 	start
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8003h</span>		<span style="color: #666666; font-style: italic;">;中断向量</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span>	int_0
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8100h</span>
start<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> 	<span style="color: #00007f;">sp</span><span style="color: #339933;">,</span> #<span style="color: #0000ff;">60h</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	ex0		<span style="color: #666666; font-style: italic;">;开int0中断</span>
	<span style="color: #00007f; font-weight: bold;">setb</span> 	ea		<span style="color: #666666; font-style: italic;">;开总中断</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tcon<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>	<span style="color: #666666; font-style: italic;">;低电平触发</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r3<span style="color: #339933;">,</span> #<span style="color: #0000ff;">00h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	a<span style="color: #339933;">,</span> r3
	cpl	a
loop3<span style="color: #339933;">:</span>				<span style="color: #666666; font-style: italic;">;死循环</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	p1<span style="color: #339933;">,</span> a
	cpl	p3<span style="color: #339933;">.</span>3		<span style="color: #666666; font-style: italic;">;翻转</span>
	lcall	DELAY		<span style="color: #666666; font-style: italic;">;延时</span>
	sjmp	loop3
&nbsp;
int_0<span style="color: #339933;">:</span>				<span style="color: #666666; font-style: italic;">;中断服务子程序</span>
	<span style="color: #00007f; font-weight: bold;">push</span>	psw
	lcall	DELAY		<span style="color: #666666; font-style: italic;">;防抖动</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	p3<span style="color: #339933;">.</span>3
	<span style="color: #00007f; font-weight: bold;">inc</span>	r3
	<span style="color: #00007f; font-weight: bold;">mov</span>	a<span style="color: #339933;">,</span> r3
	cpl	a
	<span style="color: #00007f; font-weight: bold;">mov</span>	p1<span style="color: #339933;">,</span> a
	<span style="color: #00007f; font-weight: bold;">jnb</span>	p3<span style="color: #339933;">.</span>2<span style="color: #339933;">,</span> $		<span style="color: #666666; font-style: italic;">;查询，防止多次中断</span>
	lcall	DELAY		<span style="color: #666666; font-style: italic;">;还是防抖动</span>
	<span style="color: #00007f; font-weight: bold;">pop</span>	psw
	reti
&nbsp;
DELAY<span style="color: #339933;">:</span>  <span style="color: #00007f; font-weight: bold;">PUSH</span> <span style="color: #0000ff;">06H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span> <span style="color: #0000ff;">07H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span> R7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">70H</span>
LABEL1<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span> R6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">70H</span>
LABEL2<span style="color: #339933;">:</span>
	DJNZ R6<span style="color: #339933;">,</span> $
	DJNZ R7<span style="color: #339933;">,</span> LABEL1
	<span style="color: #00007f; font-weight: bold;">POP</span> <span style="color: #0000ff;">07H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span> <span style="color: #0000ff;">06H</span>
	<span style="color: #00007f; font-weight: bold;">RET</span>
	<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>[warning]This is <em>original</em> article, you could copy it freely with my site links!<br />此日志为dutor原创，您可以自由转载，添加原文链接我将万分感激！[/warning]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/04/microcontroller-interrupt-experiment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>中断方式定时器</title>
		<link>http://www.dutor.net/index.php/2009/04/interrupt-based-timer/</link>
		<comments>http://www.dutor.net/index.php/2009/04/interrupt-based-timer/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 13:54:20 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=307</guid>
		<description><![CDATA[89C51单片机，每计时一秒将P1端口翻转一次，晶振频率12MHz，中断方式实现。这里另外一个<a href="http://www.dutor.net/index.php/2009/04/query-based-timer-5/">查询方式</a>的实现
<pre lang="asm" line="1">
 	org 	8000h		;定位
	ljmp 	start
	org 	801bh		;中断向量
	ljmp	int_t1
	org 	8100h
start:
	mov 	sp, #60h
	mov	tmod, #10h	;置T1为方式1
	mov	tl1, 0fch
	mov	th1, #4bh	;设初值，定时为50ms
	mov	r1, #20		;中断次数，以使定时为1ms
	setb	tr1		;启动定时器T1
	clr	a		;累加器清零
	setb	et1		;T1中断允许
	setb	ea		;开总外部中断标志
	sjmp	$		;等待中断


int_t1:				;中断服务子程序
	push	psw		;保存程序状态字
	mov 	tl1, #0fch	;重装计数器
	mov	th1, #4bh
	djnz	r1, exit	;1s时间未到，返回主程序，等待下一次中断
	mov	r1, #20		;1s时间到，重装r1
	cpl	a		;a取反
	mov	p1, a		;输出a
exit:	pop	psw		;程序状态字出栈
	reti

DELAY:  PUSH 06H
	PUSH 07H
	MOV R7, #70H
LABEL1:
	MOV R6, #70H
LABEL2:
	DJNZ R6, $
	DJNZ R7, LABEL1
	POP 07H
	POP 06H
	RET
	END
</pre>]]></description>
			<content:encoded><![CDATA[<p>89C51单片机，每计时一秒将P1端口翻转一次，晶振频率12MHz，中断方式实现。这里另外一个<a href="http://www.dutor.net/index.php/2009/04/query-based-timer-5/">查询方式</a>的实现</p>

<div class="wp_codebox"><table><tr id="p3079"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code" id="p307code9"><pre class="asm" style="font-family:monospace;"> 	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8000h</span>		<span style="color: #666666; font-style: italic;">;定位</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span> 	start
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">801bh</span>		<span style="color: #666666; font-style: italic;">;中断向量</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span>	int_t1
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8100h</span>
start<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> 	<span style="color: #00007f;">sp</span><span style="color: #339933;">,</span> #<span style="color: #0000ff;">60h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tmod<span style="color: #339933;">,</span> #<span style="color: #0000ff;">10h</span>	<span style="color: #666666; font-style: italic;">;置T1为方式1</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	tl1<span style="color: #339933;">,</span> <span style="color: #0000ff;">0fch</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">4bh</span>	<span style="color: #666666; font-style: italic;">;设初值，定时为50ms</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">20</span>		<span style="color: #666666; font-style: italic;">;中断次数，以使定时为1ms</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	tr1		<span style="color: #666666; font-style: italic;">;启动定时器T1</span>
	clr	a		<span style="color: #666666; font-style: italic;">;累加器清零</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	et1		<span style="color: #666666; font-style: italic;">;T1中断允许</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	ea		<span style="color: #666666; font-style: italic;">;开总外部中断标志</span>
	sjmp	$		<span style="color: #666666; font-style: italic;">;等待中断</span>
&nbsp;
&nbsp;
int_t1<span style="color: #339933;">:</span>				<span style="color: #666666; font-style: italic;">;中断服务子程序</span>
	<span style="color: #00007f; font-weight: bold;">push</span>	psw		<span style="color: #666666; font-style: italic;">;保存程序状态字</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> 	tl1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">0fch</span>	<span style="color: #666666; font-style: italic;">;重装计数器</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">4bh</span>
	djnz	r1<span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">exit</span>	<span style="color: #666666; font-style: italic;">;1s时间未到，返回主程序，等待下一次中断</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">20</span>		<span style="color: #666666; font-style: italic;">;1s时间到，重装r1</span>
	cpl	a		<span style="color: #666666; font-style: italic;">;a取反</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	p1<span style="color: #339933;">,</span> a		<span style="color: #666666; font-style: italic;">;输出a</span>
<span style="color: #000000; font-weight: bold;">exit</span><span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">pop</span>	psw		<span style="color: #666666; font-style: italic;">;程序状态字出栈</span>
	reti
&nbsp;
DELAY<span style="color: #339933;">:</span>  <span style="color: #00007f; font-weight: bold;">PUSH</span> <span style="color: #0000ff;">06H</span>
	<span style="color: #00007f; font-weight: bold;">PUSH</span> <span style="color: #0000ff;">07H</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span> R7<span style="color: #339933;">,</span> #<span style="color: #0000ff;">70H</span>
LABEL1<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">MOV</span> R6<span style="color: #339933;">,</span> #<span style="color: #0000ff;">70H</span>
LABEL2<span style="color: #339933;">:</span>
	DJNZ R6<span style="color: #339933;">,</span> $
	DJNZ R7<span style="color: #339933;">,</span> LABEL1
	<span style="color: #00007f; font-weight: bold;">POP</span> <span style="color: #0000ff;">07H</span>
	<span style="color: #00007f; font-weight: bold;">POP</span> <span style="color: #0000ff;">06H</span>
	<span style="color: #00007f; font-weight: bold;">RET</span>
	<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>[warning]This is <em>original</em> article, you could copy it freely with my site links!<br />此日志为dutor原创，您可以自由转载，添加原文链接我将万分感激！[/warning]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/04/interrupt-based-timer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>查询式定时器</title>
		<link>http://www.dutor.net/index.php/2009/04/query-based-timer-5/</link>
		<comments>http://www.dutor.net/index.php/2009/04/query-based-timer-5/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 13:33:29 +0000</pubDate>
		<dc:creator>dutor</dc:creator>
				<category><![CDATA[边走编程]]></category>
		<category><![CDATA[单片机]]></category>
		<category><![CDATA[汇编]]></category>

		<guid isPermaLink="false">http://www.dutor.net/?p=296</guid>
		<description><![CDATA[89C51单片机，每计时一秒将P1端口翻转一次，晶振频率12MHz，这里另外一个<a href="http://www.dutor.net/index.php/2009/04/interrupt-based-timer/">中断方式</a>的实现
<pre lang="asm" line="1">
 	org 	8000h		;定位
	ljmp 	start
	org 	8100h
start:
	mov 	sp, #60h
	mov	r1, #20	
	clr	a
	mov	tmod, #10h	;置T1为方式1
loop:	mov	tl1, 0fch
	mov	th1, #4bh	;设初值，定时为50ms
	setb	tr1		;启动定时器T1
	jnb	tf1, $		;查询TF1是否溢出

	clr	tf1		;清除溢出标志
	djnz	r1, loop	;1s时间未到，重装计数器
	mov	r1, #20		;1s时间到，重装r1
	cpl	a		;a取反
	mov	p1, a		;输出a
	ljmp	loop
	
	END
</pre>]]></description>
			<content:encoded><![CDATA[<p>89C51单片机，每计时一秒将P1端口翻转一次，晶振频率12MHz，这里另外一个<a href="http://www.dutor.net/index.php/2009/04/interrupt-based-timer/">中断方式</a>的实现</p>

<div class="wp_codebox"><table><tr id="p29610"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p296code10"><pre class="asm" style="font-family:monospace;"> 	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8000h</span>		<span style="color: #666666; font-style: italic;">;定位</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span> 	start
	<span style="color: #000000; font-weight: bold;">org</span> 	<span style="color: #0000ff;">8100h</span>
start<span style="color: #339933;">:</span>
	<span style="color: #00007f; font-weight: bold;">mov</span> 	<span style="color: #00007f;">sp</span><span style="color: #339933;">,</span> #<span style="color: #0000ff;">60h</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">20</span>	
	clr	a
	<span style="color: #00007f; font-weight: bold;">mov</span>	tmod<span style="color: #339933;">,</span> #<span style="color: #0000ff;">10h</span>	<span style="color: #666666; font-style: italic;">;置T1为方式1</span>
<span style="color: #00007f; font-weight: bold;">loop</span><span style="color: #339933;">:</span>	<span style="color: #00007f; font-weight: bold;">mov</span>	tl1<span style="color: #339933;">,</span> <span style="color: #0000ff;">0fch</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	th1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">4bh</span>	<span style="color: #666666; font-style: italic;">;设初值，定时为50ms</span>
	<span style="color: #00007f; font-weight: bold;">setb</span>	tr1		<span style="color: #666666; font-style: italic;">;启动定时器T1</span>
	<span style="color: #00007f; font-weight: bold;">jnb</span>	tf1<span style="color: #339933;">,</span> $		<span style="color: #666666; font-style: italic;">;查询TF1是否溢出</span>
&nbsp;
	clr	tf1		<span style="color: #666666; font-style: italic;">;清除溢出标志</span>
	djnz	r1<span style="color: #339933;">,</span> <span style="color: #00007f; font-weight: bold;">loop</span>	<span style="color: #666666; font-style: italic;">;1s时间未到，重装计数器</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	r1<span style="color: #339933;">,</span> #<span style="color: #0000ff;">20</span>		<span style="color: #666666; font-style: italic;">;1s时间到，重装r1</span>
	cpl	a		<span style="color: #666666; font-style: italic;">;a取反</span>
	<span style="color: #00007f; font-weight: bold;">mov</span>	p1<span style="color: #339933;">,</span> a		<span style="color: #666666; font-style: italic;">;输出a</span>
	<span style="color: #000000; font-weight: bold;">ljmp</span>	<span style="color: #00007f; font-weight: bold;">loop</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">END</span></pre></td></tr></table></div>

<p>[warning]This is <em>original</em> article, you could copy it freely with my site links!<br />此日志为dutor原创，您可以自由转载，添加原文链接我将万分感激！[/warning]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dutor.net/index.php/2009/04/query-based-timer-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

