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

📄 ir6122.h

📁 NEC6122红外协议
💻 H
字号:

.define 	IRPORT		PBD
.define 	IRIN		2
.define		IR_USER_ID	00H	;030H

;--------------------------------------------------------------
;
;			receive ir
;
;--------------------------------------------------------------

IrReceive:		
			BTFSC		IrStateB0,	B2
			goto		ReceiveRepeat

			CALL		ReceiveLeadLow
			BTFSC		IrStateB0,	B0	;receive lead code
			RET

			CALL		ReceiveLeadHigh
			BTFSC		IrStateB0,	B0
			RET

			CALL		ReceiveData		;receive user id low
			BTFSC		IrStateB0,	B0	;judge ir err or right
			RET
			MOVLW		IR_USER_ID
			XORWF		IrDataB0,	W	;judge user id low
			BTFSS		STATUS,		Z
			RET
			
			CALL		ReceiveData		;receive user id high
			BTFSC		IrStateB0,	B0	;judge ir err or right
			RET
			MOVLW		0FBH
			XORWF		IrDataB0,	W	;judge user id high
			BTFSS		STATUS,		Z
			RET
			
			CALL		ReceiveData		;receive ir key value low
			BTFSC		IrStateB0,	B0	;judge ir err or right
			RET
			MOVFW		IrDataB0
			MOVWF		IrKeyValueB0
			
			CALL		ReceiveData		;receive ir key value high
			BTFSC		IrStateB0,	B0	;judge ir err or right
			RET
			
			CALL		ReceiveFinishCode	;receive finish code
		;	BTFSC		IrStateB0,	B0
		;	RET
			BSF		IrStateB0,	B1
			BSF		IrStateB0,	B2
			RET
ReceiveRepeat:
			CALL		ReceiveLeadLow
			BTFSC		IrStateB0,	B0	;receive lead code
			RET
			
			CALL		ReceiveRepeatLeadHigh
			BTFSC		IrStateB0,	B0	;receive lead code
			RET
			
			CALL		ReceiveFinishCode	;receive finish code
		;	BTFSS		IrStateB0,	B0
			BSF		IrStateB0,	B1
			RET

;--------------------------------------------------------------
;
;			receive lead low
;
;--------------------------------------------------------------

ReceiveLeadLow:			
			MOVLW		98D	;30d			;lead low >3000us err
			MOVWF		IrHighLimB0
			MOVLW		82D	;20D			;lead low <2000us err
			MOVWF		IrLowLimB0
			
			BCF		IrStateB0,	B0

			CALL		ReceiveLow
			
			RET
;--------------------------------------------------------------
;
;			receive lead high
;
;--------------------------------------------------------------

ReceiveLeadHigh:			
			MOVLW		55D	;50D			;lead high >4800us err
			MOVWF		IrHighLimB0
			MOVLW		35D	;40D			;lead high <4200us err
			MOVWF		IrLowLimB0
			
			CALL		ReceiveHigh
			
			RET

;--------------------------------------------------------------
;
;			receive lead low
;
;--------------------------------------------------------------

ReceiveRepeatLeadHigh:			
			MOVLW		32D	;30d			;lead low >3000us err
			MOVWF		IrHighLimB0
			MOVLW		13D	;15D			;lead low <1500us err
			MOVWF		IrLowLimB0

			CALL		ReceiveHigh
			
			RET
;--------------------------------------------------------------
;
;
;
;--------------------------------------------------------------

ReceiveFinishCode:
			MOVLW		09D	;08D			;bit low>750us err
			MOVWF		IrHighLimB0
			MOVLW		02D	;03D			;bit low<350us err
			MOVWF		IrLowLimB0
			
			CALL		ReceiveLow
			
			RET
			
;--------------------------------------------------------------
;
;			receive ir data
;
;--------------------------------------------------------------

ReceiveData:
			MOVLW		08H
			MOVWF		IrBitsB0
ReceiveDataGo:
			MOVLW		08D			;bit low>750us err
			MOVWF		IrHighLimB0
			MOVLW		03D			;bit low<350us err
			MOVWF		IrLowLimB0
			CALL		ReceiveLow
			BTFSC		IrStateB0,	B0
			RET

			MOVLW		19D	;18D			;bit high>1850us err
			MOVWF		IrHighLimB0
			MOVLW		03D			;bit high<350us
			MOVWF		IrLowLimB0
			CALL		ReceiveHigh
			BTFSC		IrStateB0,	B0
			RET
			
			MOVLW		10D
			SUBWF		IrCountB0,	W	;Judge 1 or 0
			RRF		IrDataB0,	F
			
			DECFSZ		IrBitsB0,	F
			GOTO		ReceiveDataGo
			
			RET

;--------------------------------------------------------------
;
;			receive low of a bit
;
;--------------------------------------------------------------

ReceiveLow:
			CLRF		IrCountB0
ReceiveLowGo:
			MOVFW		IrHighLimB0
			SUBWF		IrCountB0,	W	;bit low>750us err
			BTFSC		STATUS,		C
			GOTO		IrLowErr
			
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			BTFSS		PBD,	B2	;IRPORT,		IRIN
			GOTO		ReceiveLowGo
			
			MOVFW		IrLowLimB0
			SUBWF		IrCountB0,	W	;bit low<350us err
			BTFSC		STATUS,		C
			RET		
IrLowErr:
			BSF		IrStateB0,	B0
			RET
			
;--------------------------------------------------------------
;
;			receive high of a bit
;
;--------------------------------------------------------------

ReceiveHigh:
			CLRF		IrCountB0
ReceiveHighGo:
			MOVFW		IrHighLimB0
			SUBWF		IrCountB0,	W	;bit high>1850us err
			BTFSC		STATUS,		C
			GOTO		IrHighErr

			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			GOTO		$+1
			BTFSC		IRPORT,		IRIN
			GOTO		ReceiveHighGo

			MOVFW		IrLowLimB0
			SUBWF		IrCountB0,	W	;bit high<350us
			BTFSC		STATUS,		C
			RET
IrHighErr:
			BSF		IrStateB0,	B0

			RET

⌨️ 快捷键说明

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