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

📄 111.asm

📁 keeloq滚动码解码大全
💻 ASM
📖 第 1 页 / 共 3 页
字号:
	goto    rmt01                   ; [0] no--error

	movf    cnt0,w                  ; [1] calibration counter
	movwf   cnt2                    ; [1] (nominally 75 for 300 us pulse)
	decf    cnt2,1			; [1] subtract 2 from final calib counter to compenate for this
	goto	$+1			; [2]
	nop				; [1]
					; total = 8 => 1 loop counter
dl2
	clrwdt                          ; [1] reset watchdog timer
	goto	$+1			; [2] waste time
	goto	$+1			; [2] waste time
	decfsz  cnt2,1			; [1]
	goto    dl2                     ; [2] cnt0 x 8 us [ cnt0 x te ]

sample2
	bcf     flags,bitin             ; [1]   clear bit position
	btfss   porta,rfin              ; [1.5] leave 0 if line high
	bsf     flags,bitin             ; [0.5] make 1 if line low
					; sub total = 3 cycles

	call    rot_shift               ; [11]+[2] csr shift + call
	bcf	csr7,7			; [1]
	btfsc   flags,bitin		; [1.5]
	bsf     csr7,7			; [0.5]
					; sub total = 16 cycles


	movf    cnt0,w                  ; [1] calibration counter
	movwf   cnt2                    ; [1] (nominally 75 for 300 us pulse)
	movlw	3			; [1] see calculation below
	subwf	cnt2,1			; [1]
	nop				; [1]
					; sub total = 5 cycle
					; total = 24 => 24/8 = 3 loop counters
					 
;*************************************************************************
; total = 24 instructions
; subtract 24/8 = 3 to compesate for updateing csr and other processing 
; after data sample is taken.
;*************************************************************************

dl3
	goto	$+1			; [2] waste time
	goto	$+1			; [2] waste time
	clrwdt                          ; [1] reset watchdog timer
	decfsz  cnt2,1                  ; [1]
	goto    dl3                     ; [2] cnt0 x 8 us [ cnt0 x te ]

sample3
	btfsc   porta,rfin              ; [2] input low?  third sample
	goto    rmt0                    ; [0] no--receive error

	call    tst_rtcc                ; [11] check rtcc

	decfsz  cnt1,1                  ; [1] last bit?
	goto    rcv8                    ; [2] ... no, get next bit
	goto	rmt1		     	; total = 14 cycles


rmt_0
rmt0	
rmt01	bsf	status,c		; invalid transmission
	retlw	1			; return

rmt1	bsf	porta,led		; valid transmission format, led on
	movlw	0fh			; force open button codes to zero
	andwf	ser_0,1
	clrc				; valid serial number => valid tx
 	retlw   0                    	; return 

;===========================================================================
;
; function     	: m_loop ()	      			
;
; description  	: main program routine
;
;===========================================================================

m_loop	bcf	porta,led		 
	btfss	porta,lrn		
	goto	learn		 	; test & handle learn button
	call	tst_rtcc		; update timer 
	call	tst_timer		; handle timer - update outputs
	call	receive			; receive transmission 
	bc	m_loop			; check if transmission valid

m_search
	clrf	txnum			; test first position
; ******* compare lower word of serial number ********
m_serial
	call	tx_lookup		; get tx base address
	bsf	address,1		; add 2 to base address
	call	eeread			; read lower 16-bits of ser# from eeprom
  		    
	movfw	tmp1			; compare rx and eeprom values
	xorwf	ser_2,w
	bnz	m_next			; if not equal check next
	movfw	tmp2			; compare rx and eeprom values
	xorwf	ser_3,w
	bnz	m_next			; if not equal check next
	
; ******* compare upper word of serial number ********
m_serial2
	incf	address,f		; point to next entry 
	call	eeread			; read upper 16-bits of ser# from eeprom

	movfw	tmp1			; compare rx and eeprom values
	xorwf	ser_0,w
	bnz	m_next			; if not equal check next

	movfw	tmp2			; compare rx and eeprom values
	xorwf	ser_1,w
	bnz	m_next			; if not equal check next

	btfss	flags,lrnf		; learn mode
	goto	m_hop			; found transmitter - decrypt

	bsf	flags,relearn		; set relearn flag
	goto	learn_f			; found transmitter - learn
		
; **** search next position for serial number *****
m_next	incf	txnum,f			; point to next transmitter position
	movlw	max_users		; test for last position
	subwf	txnum,w			
	btfss	status,c		; not found in map
	goto	m_serial		; try next position
m_nf
	btfss	flags,lrnf		; learn mode
	goto	m_loop			; no... invalid serial number 
	goto	learn_nf		; new transmitter - use pointer for learn

; ********** decrypt hopcode *********************
m_hop	
	call	decrypt			; decrypt hopcode 

; ********* test dicrimination value *************
m_dis	movfw	ser_3			; serial nuber lsb must be equal
	xorwf	code1,w			; to discrimination value
	bnz	m_loop

; *************** check counters valid ************
	bcf	flags,sec_cnt		; check first counter
m_cnt	call	tx_lookup		; point lower 16 bit counter
	btfsc	flags,sec_cnt		; if second counter is used
	incf	address,f		; increment address
	call	eeread			; read lower 16 bit counter from eeprom

; ************ check counter windows ***********
m_sub
	movfw	tmp2			; 16 bit counter substraction
	subwf	cntr_lw,w
	movwf	tmp2			
	skpc				; skip if no borrow
	incf	tmp1,f			; ... else incr hi byte
	movfw	tmp1
	subwf	cntr_hi,w
	movwf	tmp1

	bcf	tmp1,0			; make accepted window 512

m_check0
	movfw	tmp1			; test if in window ( upper byte )
	btfsc	status,z
	goto	m_check2		; go and check lower byte

	btfsc	flags,sec_cnt		; if second counter
	goto	m_loop			; error - goto main loop		

	bsf	flags,sec_cnt		; set flag for second counter check
	goto	m_cnt			; and check it

m_check2
	movfw	tmp2			; check lower byte
	bz	m_tzero			; if repeat - reset timeout counter

; ************ update eeprom counter ***********
m_update
	call	tx_lookup		; get current tx base address
	call	load_cnt_vals		; load counter values
	call	eewrite			; update first counter
	call	load_cnt_vals		; load counter values	
	call	eewrite			; update second counter

; ******** update output with current button code ********

m_output 
	movlw	0f0h			; mask only button codes
	andwf	func,1
	swapf	func,1			; get button code from func byte
	
	btfsc	func,0			; change button to s-output format
	bsf	func,4			; [ s2 s1 s0 s3 ]
	clrc				
	rrf	func,w			
	
m_output1
	iorlw	b'10000000'		;+++++
	movwf	portb			; update port with function code
	
m_tzero clrf	cnt_hi			; reset rtcc clock
	clrf	cnt_lw			

m_end	
	goto	m_loop			; wait for next tranmission

;===========================================================================
;
; function     	: learn ()	      			
;
; description  	: learn routine
;
;===========================================================================

learn
	clrf	cnt_lw			; reset timer
	clrf	cnt_hi
	
	
learn1	bsf	porta,led		; led on
	call	tst_rtcc		; update timer
	btfsc	porta,lrn		; test for button release		
	goto	learn2			; enter learn mode
	btfss	cnt_hi,0		; test for erase all
	goto	learn1			; loop back

; ******* eeprom erase all ******************

	bcf	porta,led
erase_all
	clrwdt				; clear watchdog timer
	btfss	porta,lrn		; wait for button release
	goto	erase_all		; loop back

  	movlw	30h			; erase enable command
	movwf   outbyt               	
        call    sendc			; send command to eeprom
  	movlw	20h			; erase all command
	movwf   outbyt               	
        call    sendc			; send command to eeprom
	call	waitack			; wait for erase ack
	goto	reset			; start over
	
learn2
	bcf	porta,led		; clear led
	bsf	flags,lrnf		; set learn flag

learn3
	call	tst_rtcc		; update timer
	call	tst_timer		; check for learn timeout
	call	receive			; receive transmission 
	bc	learn3			; check if transmission valid
 	goto	m_search		; check if serial number is in map


learn_nf		;read learn_pointer


; *** if serial not in map read selflearn pointer ***

	movlw	lrnptr			; point to learn pointer
	movwf	address
	call	eeread			; read learn pointer from eeprom

	movf	tmp2,w			; check lower byte
	movlw	0h			; load 0 default
	btfsc	status,z		; if lower != 0 learn on 0
	movf	tmp1,w			; else learn on tmp1 value
	movwf	txnum			; load txnum


learn_f			;write sn

	call	tx_lookup
	bsf	address,1		; add 2 to base address
	movfw	ser_2			; get lower 16 bit of serial number
	movwf	tmp1
	movfw	ser_3
	movwf	tmp2
	call	eewrite			; ... and write to eeprom
	
	movfw	ser_0			; get upper 16 bit of serial number
	movwf	tmp1
	movfw	ser_1
	movwf	tmp2
	call	eewrite			; ... and write to eeprom

; *** decrypt hop code ***

learn_dec
	call	decrypt			; decryption routine

; *** check discrimination value ***

learn_chk
	movfw	ser_3			; check lower byte of serial number
	xorwf	code1,w			; against discrimination value
	bz	learn_up		; update learn pointer
	goto	cancel_learn		; error cancel learn mode

; ********* update learn pointer **********
learn_up
	call	tx_lookup		; get current tx base address
	call	load_cnt_vals
	call	eewrite			; write lsb word of counter to eeprom

	btfsc	flags,relearn		; if relearn
	goto	bypass_pointer_write	; dont update pointer

	incf	txnum,f			; increment learn pointer	       
	movlw	max_users     		; allow 0 .. max_users - 1
	subwf	txnum,w			
	movlw	0h			; if max wrap to 0
	btfss	status,c
	movf	txnum,w			; else use txnum
	movwf	tmp1			; for write operation

	clrf	tmp2			; clear lower byte
	
	movlw	lrnptr			; point to learn pointer
	movwf	address
	call	eewrite			; update learn pointer in eeprom

bypass_pointer_write

	bsf	porta,led		; led on to indicate valid learn

	clrf	cnt_lw			; clear counter low byte

success
	call	tst_rtcc		; indicate successful learn
	btfss	cnt_lw,4		; led on for 0.5 sec
	goto	success			; loop back

cancel_learn
	bcf	flags,lrnf		; clear learn flag
	bcf	flags,relearn		; clear relearn flag
	goto	m_loop			; return to main loop - led off

;===========================================================================
; end of file : simdec10.asm
;===========================================================================

	org	1ffh
	goto	reset
	end


⌨️ 快捷键说明

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