⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iralyze.asm.htm

📁 pic 单片机红外接收分析仪的资料
💻 HTM
字号:
<PRE>
<FONT COLOR=green>;**********************************************************************</FONT>
<FONT COLOR=green>; Analyzes IR remote control signals                                  *</FONT>
<FONT COLOR=green>;**********************************************************************</FONT>
<FONT COLOR=green>;                                                                     *</FONT>
<FONT COLOR=green>;    Filename:	    iralyze.asm                                       *</FONT>
<FONT COLOR=green>;    Date:          22/8/2002                                         *</FONT>
<FONT COLOR=green>;    File Version:  $Revision: 4 $                                    *</FONT>
<FONT COLOR=green>;                                                                     *</FONT>
<FONT COLOR=green>;    Author:        Prashant Bhandary                                 *</FONT>
<FONT COLOR=green>;                                                                     *</FONT>
<FONT COLOR=green>;**********************************************************************</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>; </FONT>
<FONT COLOR=green>; Currently done for a 16F876</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=red>	list      p=16f876            </FONT><FONT COLOR=green>; list directive to define processor</FONT>
	#include &lt;p16f876.inc&gt;        <FONT COLOR=green>; processor specific variable definitions</FONT>
	
	__CONFIG _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _HS_OSC & _WRT_ENABLE_ON & _LVP_OFF & _DEBUG_OFF & _CPD_OFF 

<FONT COLOR=green>;</FONT>
dly1    equ     04h
dly2    equ     00h
dly3    equ     00h
baud19_2 equ	.31	<FONT COLOR=green>;19.2K baud with high speed enable(10MHz crystal)</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>; Error codes</FONT>
ERR_HEADER	equ	0x80	<FONT COLOR=green>; Indicates error byte to follow</FONT>
ERR_NO_SIGNAL	equ	0x41	<FONT COLOR=green>; Indicates no signal received</FONT>
ERR_TIMEOUT	equ	0x42	<FONT COLOR=green>; Indicates end of signal</FONT>
MaxTimeout	equ	0x80	<FONT COLOR=green>; Timeout count for delay after signal</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>; Data</FONT>
<FONT COLOR=red>	ORG     20H     </FONT><FONT COLOR=green>; Data Origin</FONT>
<FONT COLOR=green>;</FONT>
DlyHsb  RES     1       <FONT COLOR=green>; MSB of delay count</FONT>
DlyMsb  RES     1       <FONT COLOR=green>; MSB of delay count</FONT>
DlyLsb  RES     1       <FONT COLOR=green>; LSB of delay count</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>; Timeout delay waiting for start of signal</FONT>
Wait1	RES	1
Wait2	RES	1
Wait3	RES	1
<FONT COLOR=green>;</FONT>
PortA_	RES	1	<FONT COLOR=green>; Store last state of Port A</FONT>
InpBit	equ	0
InpMask	equ	(1&lt;&lt;InpBit)
TicCount	RES	1	<FONT COLOR=green>; No. of samples</FONT>
Timeout	RES	1	<FONT COLOR=green>; Hold timeout once signal received</FONT>
ErrReg	RES	1	<FONT COLOR=green>; Holds error to be sent</FONT>
TxBuf	RES	1	<FONT COLOR=green>; Holds byte to be transmitted</FONT>
<FONT COLOR=green>;</FONT>
w_temp        EQU     0x70        <FONT COLOR=green>; variable used for context saving </FONT>
status_temp   EQU     0x71        <FONT COLOR=green>; variable used for context saving</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>; Program</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=red>	ORG     0       </FONT><FONT COLOR=green>; Reset vector</FONT>
<FONT COLOR=green>;</FONT>
	nop
	goto    <A HREF="#main">main</A>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=red>	ORG     4       </FONT><FONT COLOR=green>; Interrupt vector</FONT>
	retfie                    <FONT COLOR=green>; return from interrupt</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>;</FONT>
<FONT COLOR=green>;	ORG     8       ; Program starts here</FONT>
<FONT COLOR=green>;</FONT>
<A NAME="main">main    bsf     STATUS,RP0
	movlw   1
	movwf   TRISA   <FONT COLOR=green>; Set Port A to all outputs except RA0</FONT>
	movlw	7
	movwf	ADCON1	<FONT COLOR=green>; Disable A/D port</FONT>
	<FONT COLOR=green>; Setup serial port</FONT>
	movlw	baud19_2
	movwf	SPBRG
	bcf     STATUS,RP0
	bsf	RCSTA,SPEN	<FONT COLOR=green>; Enable serial port</FONT>
	bsf	RCSTA,CREN	<FONT COLOR=green>; Enable receive</FONT>
	bsf     STATUS,RP0
	bsf	TXSTA,TXEN
	bsf	TXSTA,BRGH
	bcf     STATUS,RP0

<A NAME="delay">delay	movlw	dly1
	movwf	DlyHsb
<A NAME="loop4">loop4	movlw	dly2
	movwf	DlyMsb
<A NAME="loop3">loop3   movlw	dly3
	movwf	DlyLsb
<A NAME="loop2">loop2	btfss	RCSTA,OERR
	goto	<A HREF="#NoOver">NoOver</A>
	bcf	RCSTA,CREN
	bsf	RCSTA,CREN
	
<A NAME="NoOver">NoOver</A>
	btfss	PIR1,RCIF
	goto	<A HREF="#NoRecv">NoRecv</A>
	movf	RCREG,0
	<FONT COLOR=green>;movwf	TXREG</FONT>
	xorlw	'R'
	btfss	STATUS,Z
	goto	<A HREF="#NoRecv">NoRecv</A>
	clrf	ErrReg
	call	<A HREF="#ReadIR">ReadIR</A>
<A NAME="ChkTx">ChkTx</A>
	btfss	PIR1,TXIF
	goto	<A HREF="#ChkTx">ChkTx</A>
	movf	ErrReg,0
	movwf	TXREG
<A NAME="ChkTx2">ChkTx2</A>
	btfss	PIR1,TXIF
	goto	<A HREF="#ChkTx2">ChkTx2</A>
<A NAME="NoRecv">NoRecv</A>
	decfsz	DlyLsb,1
	goto	<A HREF="#loop2">loop2</A>
	decfsz	DlyMsb,1
	goto	<A HREF="#loop3">loop3</A>
	decfsz	DlyHsb,1
	goto	<A HREF="#loop4">loop4</A>
	movlw	2
	xorwf	PORTA,1
	goto	<A HREF="#delay">delay</A>
<FONT COLOR=green>;</FONT>
<A NAME="ReadIR">ReadIR</A>
	clrf	TicCount
	clrf	Timeout
	clrf	Wait1
	clrf	Wait2
	movlw	.38
	movwf	Wait3
	clrf	PortA_
<A NAME="WaitStart">WaitStart</A>
	movf	PORTA,0			<FONT COLOR=green>;1</FONT>
	xorwf	PortA_,0		<FONT COLOR=green>;2</FONT>
	andlw	InpMask			<FONT COLOR=green>;3</FONT>
	btfss	STATUS,Z		<FONT COLOR=green>;4/5</FONT>
	goto	<A HREF="#StartFound">StartFound</A>		<FONT COLOR=green>;5</FONT>
	decfsz	Wait1,1
	goto	<A HREF="#WaitStart">WaitStart</A>
	decfsz	Wait2,1
	goto	<A HREF="#WaitStart">WaitStart</A>
	decfsz	Wait3,1
	goto	<A HREF="#WaitStart">WaitStart</A>
	movlw	ERR_NO_SIGNAL
	movwf	ErrReg
	movlw	ERR_HEADER
	movwf	TXREG
	return

<A NAME="StartFound">StartFound</A>
	movf	PORTA,0			<FONT COLOR=green>;7</FONT>
	movwf	PortA_			<FONT COLOR=green>;8</FONT>
	incf	TicCount,1		<FONT COLOR=green>;9</FONT>
	goto	<A HREF="#Delay1">Delay1</A>			<FONT COLOR=green>;10</FONT>

<A NAME="LoopRead">LoopRead</A>
	movf	PORTA,0			<FONT COLOR=green>;1</FONT>
	xorwf	PortA_,0		<FONT COLOR=green>;2</FONT>
	andlw	InpMask			<FONT COLOR=green>;3</FONT>
	btfss	STATUS,Z		<FONT COLOR=green>;4/5</FONT>
	goto	<A HREF="#Bchange">Bchange</A>			<FONT COLOR=green>;5</FONT>
	<FONT COLOR=green>;</FONT>
	incf	TicCount,1		<FONT COLOR=green>;6</FONT>
	movf	TicCount,0		<FONT COLOR=green>;7</FONT>
	xorlw	.127			<FONT COLOR=green>;8</FONT>
	btfss	STATUS,Z		<FONT COLOR=green>;9/10</FONT>
	goto	<A HREF="#Delay1">Delay1</A>			<FONT COLOR=green>;10</FONT>
	<FONT COLOR=green>;</FONT>
	<FONT COLOR=green>; count reached 127	</FONT>
	incf	Timeout,1		<FONT COLOR=green>;11</FONT>
	movlw	MaxTimeout		<FONT COLOR=green>;12</FONT>
	xorwf	Timeout,0		<FONT COLOR=green>;13</FONT>
	btfsc	STATUS,Z		<FONT COLOR=green>;14/15</FONT>
	goto	<A HREF="#ErrorTOut">ErrorTOut</A>		<FONT COLOR=green>;15</FONT>

	clrf	TicCount		<FONT COLOR=green>;16</FONT>
	movlw	.127			<FONT COLOR=green>;17</FONT>
	movwf	TxBuf			<FONT COLOR=green>;18</FONT>
	btfsc	PortA_,InpBit		<FONT COLOR=green>;19/20</FONT>
	bsf	TxBuf,7			<FONT COLOR=green>;20</FONT>
	movf	TxBuf,0			<FONT COLOR=green>;21</FONT>
	movwf	TXREG			<FONT COLOR=green>;22</FONT>
	goto	<A HREF="#LoopRead">LoopRead</A>		<FONT COLOR=green>;24</FONT>

<A NAME="ErrorTOut">ErrorTOut</A>
	movlw	ERR_TIMEOUT		<FONT COLOR=green>;16</FONT>
	movwf	ErrReg
	movlw	ERR_HEADER
	movwf	TXREG
	return

<A NAME="Bchange">Bchange</A>
	clrf	Timeout			<FONT COLOR=green>;7</FONT>
	incf	TicCount,0		<FONT COLOR=green>;8</FONT>
	movwf	TxBuf			<FONT COLOR=green>;9</FONT>
	btfsc	PortA_,InpBit		<FONT COLOR=green>;10/11</FONT>
	bsf	TxBuf,7			<FONT COLOR=green>;11</FONT>
	movf	TxBuf,0			<FONT COLOR=green>;12</FONT>
	movwf	TXREG			<FONT COLOR=green>;13</FONT>
	clrf	TicCount		<FONT COLOR=green>;14</FONT>
	movf	PORTA,0			<FONT COLOR=green>;15</FONT>
	movwf	PortA_			<FONT COLOR=green>;16</FONT>
	goto	<A HREF="#Delay2">Delay2</A>			<FONT COLOR=green>;18</FONT>

<A NAME="Delay1">Delay1</A>					<FONT COLOR=green>;11</FONT>
	nop				<FONT COLOR=green>;12</FONT>
	nop				<FONT COLOR=green>;13</FONT>
	nop				<FONT COLOR=green>;14</FONT>
	nop				<FONT COLOR=green>;15</FONT>
	nop				<FONT COLOR=green>;16</FONT>
	nop				<FONT COLOR=green>;17</FONT>
<A NAME="Delay2">Delay2</A>					<FONT COLOR=green>;18</FONT>
	nop				<FONT COLOR=green>;18</FONT>
	nop				<FONT COLOR=green>;19</FONT>
	nop				<FONT COLOR=green>;20</FONT>
	nop				<FONT COLOR=green>;21</FONT>
	nop				<FONT COLOR=green>;22</FONT>
	goto	<A HREF="#LoopRead">LoopRead</A>		<FONT COLOR=green>;24</FONT>
<FONT COLOR=green>;</FONT>
	return
<FONT COLOR=green>;</FONT>
	end

</PRE>
<HR>
External Labels :<P>
<PRE>
</PRE>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -