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

📄 3in1.asm

📁 红外解码程序
💻 ASM
字号:
;----------------------------------------------------
;	Remote control in Triplex 3@1(gator)
;		
;	date 2003.08.26
;----------------------------------------------------
;0826:updata:
;a,portb.7=low,load data to portb 0-6,while portb7=1-0
;b,
;1.quickly send function,
;2.this version should OUTPUT DATA TO PORTb 0-4,5 FOR ENABLED REMOTE,<40ms
;then check data is true,do with the table_code,send the transfer code to portb.
;NOTE:	P16C54&P16F73 have diffrent:
;	tris		trisa
;	bank0		bank0,1
;	no sublw	sublw
;	retlw	0	return

#include "p16C5x.inc"
	CONSTANT	VAR=0X06 
	CONSTANT	Data1=0X33	
	CONSTANT	Data2=0X31
	CONSTANT	Data3=0x04
	CONSTANT	Delay10=.10
	CONSTANT	Delay110=.110
;Var. define

#define iCount	   VAR+1
#define iLOOP2	   VAR+2
#define	iLOOP1     VAR+3
#define iDataNum   VAR+4
#define firstbyte  VAR+5
#define	secondbyte VAR+6
#define thirdbyte  VAR+7
#define forthbyte  VAR+8
#define temp_code  VAR+9
#define Error_Status VAR+10
#define System_Status VAR+11
#define Contine_Send_Counter VAR+12
#define	CheckData VAR+13
#define Check_Send_Continue System_Status,0

;Port define
#define irDA	PORTA,1
#define iLight	PORTA,0

#define iLegal1 PORTB,6		; GPIO20
#define iHj_Clk PORTB,7		; GPIO21
#define Result  PORTB,5		; GPIO7


	ORG	0x000
	nop
CheckID:


Start
	nop
	nop
	CLRF	PORTA		; PLEASE BE SURE PORTA PIN 2,3 =(0,0) S
	movlw	0x80
	movwf	PORTB		; GPIO21=1 GPIO20=0 PORTD PIN5 LOW ,FOR DISABLE
	clrf	System_Status	; 

	bsf	iLight		; off light
	movlw	0XF2	
	TRIS 	PORTA		; porta 1: remote data input port,pin 0: flash indication for a ir'command ,pin 2,3for audio setting output ,no run this
	
	movlw	0x00
	TRIS	PORTB		; pin 0-5 for code output, pin 6,7for secret checking line
;add encrydata for 3in1

Init:
	movlw	.32
	movwf	iDataNum
	movlw	0x00
	movwf	firstbyte
	movwf	secondbyte
	movwf	thirdbyte
	movwf	forthbyte
Main:
			
	bcf	iLight		; Light on
	btfss	irDA
	goto	ReadyReceive
	goto	Main
;***************************************************************
; Check receiving data ,because the width of the data's pulse 
; (0 or1)have 1.125/2 low level and high level
;***************************************************************

ReadyReceive
	movlw	.24	;delay 600us
	movwf	iCount
Wait1
	call	DELAY_SHORT	
	decfsz	iCount,F
	goto	Wait1
	btfsc	irDA
	goto	Main

	movlw .10		; 10 msec delay
	movwf  iLOOP1

Outter:
	movlw	.110		; close to 1.0 msec delay when set to .110
	movwf 	iLOOP2
Inner:
	
	btfss	irDA
	goto	Innext
	goto	ReceiveData
Innext	
	nop
	nop
	nop
	decfsz	iLOOP2, F	; decrement and leave result in LOOP2 
	goto Inner
	decfsz 	iLOOP1, F
	goto Outter
	movlw	.1		; 10ms low level timeover
	goto Err1
	

ReceiveData			; this process include 4.5ms high level,
	btfsc	Check_Send_Continue
	goto	Send_Continue
	
	movlw .5		; 5 msec delay
	movwf  iLOOP1

Outter1:
	movlw	.110		; close to 1.0 msec delay when set to .110
	movwf 	iLOOP2
Inner1:
	
	btfsc	irDA
	goto	Innext1
	goto	ReceiveBit	
Innext1	
	nop
	nop
	nop
	decfsz	iLOOP2, F	; decrement and leave result in LOOP2 
	goto Inner1
	decfsz 	iLOOP1, F
	goto Outter1
	movlw	.2		; 4.5ms high level timeover
	goto Err1

ReceiveBit			; include for bit high level edge
	movlw 	.2		; 2 msec delay
	movwf 	iLOOP1

Outter2:
	movlw	.110		; close to 1.0 msec delay when set to .110
	movwf 	iLOOP2
Inner2:
	
	btfss	irDA
	goto	Innext2
	goto	ReceiveByte	
Innext2	
	nop
	nop
	nop
	decfsz	iLOOP2, F	; decrement and leave result in LOOP2 
	goto Inner2
	decfsz 	iLOOP1, F
	goto Outter2
	movlw	.3		; receive data low level timeover
	goto Err1
;***************************************
;after  840us ,check data for bit value.
;***************************************
ReceiveByte
	movlw	.34	;delay 840us 34*25=850us
	movwf	iCount
Wait2
	call	DELAY_SHORT	
	decfsz	iCount,F
	goto	Wait2
	
	btfsc	irDA
	goto	onebit
	bcf	STATUS,C	; follow to saving bit value=0,
	rrf	firstbyte	; high 
	rrf	secondbyte
	rrf	thirdbyte
	rrf	forthbyte
	decfsz	iDataNum,F
	goto	ReceiveBit	
	goto	Check_data
onebit				; follow to saving bit value=1
	bsf	STATUS,C
	rrf	firstbyte	; high
	rrf	secondbyte
	rrf	thirdbyte
	rrf	forthbyte
	decfsz	iDataNum,F
	goto	ReceiveData
; Is the received data true?
Check_data:

	movlw	0xff
	movwf	CheckData
	movf	thirdbyte,W
	subwf	CheckData
	btfsc	STATUS,Z
	goto	Check_Forthbyte	
	movlw	.6		; error =6 code error
	goto	Err1

Check_Forthbyte:
	clrf	CheckData
	movf	forthbyte,W
	addwf	CheckData,W
	btfsc	STATUS,Z
	goto	Check_second_firstbyte
	movlw	.7
	goto	Err1	
Check_second_firstbyte:	
	movlw	0xff
	movwf	CheckData
	movf	secondbyte,W
	addwf	firstbyte,W
	subwf	CheckData	; 0xff-w
	btfsc	STATUS,Z
	goto	Senddata
	movlw	.4
	goto	Err1

; Senddata to portd
Senddata:
	clrf	temp_code
Search_code:
	movf	temp_code,W
	call	Table_code		; send code
	subwf	secondbyte,W
	btfss	STATUS,Z
	goto	Check_next
	btfss	iLight
	goto	OffLight2
	bcf	iLight
Continue_Search_code:
	movf	temp_code,W
	XORLW	0X80
	movwf	PORTB
	bsf	PORTB,5
	movlw	.110
	call	Delay_Xms		; long delay
	movlw	0x80
	movwf	PORTB	

	goto	Clear_data

OffLight2:
	bsf	iLight
	goto	Continue_Search_code

Check_next:
	movlw	.32
	movwf	CheckData
	incf	temp_code
	movf	temp_code,W
	subwf	CheckData
	btfss	STATUS,Z
	goto	Search_code
	movlw	.5
	goto	Error_Status		; error data
Clear_data:	
	movlw	.32
	movwf	iDataNum
	movlw	0x00
	movwf	firstbyte
	movwf	secondbyte
	movwf	thirdbyte
	movwf	forthbyte
	bsf	Check_Send_Continue
	movlw	.10
	movwf	Contine_Send_Counter
	nop
	goto	Main
; check 2.25ms+.28ms irDA=0?
Send_Continue:
	movlw	.84			; delay time=84*30=2520us
	movwf	iLOOP1
Loop_Send_Continue:
	call	DELAY_SHORT
	decfsz	iLOOP1
	goto	Loop_Send_Continue
	btfsc	irDA
	goto	Receive_data
	movlw	.0
	addwf	Contine_Send_Counter
	btfsc	STATUS,Z
	goto	Show_FF
	decf	Contine_Send_Counter,F
	goto	Main
Show_FF:
	btfss	iLight
	goto	OffLight1
	bcf	iLight
ContinueShow:
	movlw	0x9f
	movwf	PORTB
	bsf	PORTB,5
	movlw	.110
	call	Delay_Xms
	movlw	0x80
	movwf	PORTB
	movlw	.10
	movwf	Contine_Send_Counter
	goto	Main
OffLight1:
	bsf	iLight
	goto	ContinueShow

; new key press
Receive_data:
	bcf	Check_Send_Continue
	goto	ReceiveData

		

;***************************************************************
;	Error_Status:
;		1.9ms low level timeover ,occure.
;		2.4.5ms high level timeover occure.
;		3.receive data pulse low level timeover occure.
;		4.receive data from IR,code2+code3!=0xff
;		5.code3 isn't exist include table_code.
;***************************************************************
Err1:
	movwf	Error_Status
	goto	Init

DELAY_SHORT:		; provides nominal 25 usec delay
	movlw .5
	movwf iLOOP2
DELAY_SHORT_1:
	nop
	decfsz iLOOP2, F
	goto DELAY_SHORT_1
	RETLW	.0	
;******************************************
; w=iLoop1,Example: w=110,then delay 110ms
;******************************************
Delay_Xms:
	movwf	iLOOP1
Loop110ms_1:
	movlw	.110
	movwf	iLOOP2
Loop110ms_2:
	nop
	nop
	nop
	nop
	nop
	nop
	decfsz	iLOOP2
	goto	Loop110ms_2
	decfsz	iLOOP1
	goto	Loop110ms_1
	RETLW	.0

Table_code:
	addwf	PCL
	retlw	0x10
	retlw	0x03
	retlw	0x01
	retlw	0x06
	retlw	0x09
	retlw	0x1d
	retlw	0x1f
	retlw	0x0d
	retlw	0x19
	retlw	0x1b
	retlw	0x11
	retlw	0x15
	retlw	0x17
	retlw	0x12
	retlw	0x16
	retlw	0x4c
	retlw	0x40
	retlw	0x48
	retlw	0x04
	retlw	0x00
	retlw	0x02
	retlw	0x05
	retlw	0x54
	retlw	0x4d
	retlw	0x0a
	retlw	0x1e
	retlw	0x0e
	retlw	0x1a
	retlw	0x1c
	retlw	0x14
	retlw	0x0f
	retlw	0x0c



	org	0x1ff
	goto	CheckID

	end

;/////////////////////////////////////////	








	
		
	
	
	

⌨️ 快捷键说明

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