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

📄 111.asm

📁 keeloq滚动码解码大全
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;------------------------------------------------------------------------------
;  microchip keeloq code hopping simple decoder
;
;------------------------------------------------------------------------------
;  legal notice
;
;  the information contained in this document is proprietary and 
;  confidential information of microchip technology inc.  therefore all 
;  parties are required to sign a non-disclosure agreement before 
;  receiving this document.
;------------------------------------------------------------------------------

;===========================================================================
; simple decoder with one step learn and single key
;===========================================================================
;
;program information:	file:	simdec10.asm	
;			date:	08/15/96 
;			ver.:	1.0
;			cksm:	xxxxh - fuses:rc,wdt=on,cp=on
;			asm.: 	mpasm version 1.40 used
;			incl:	none
;			tabs:   8
;===========================================================================
; configuration control:
; 
; date		version	line	changes
; 08/14/96	1.0		first version
;===========================================================================
;	list p=16c54,r=dec
;===========================================================================
;******user definitions******
max_users	equ	15
; this is the maximum number of transmitters that the system is able to 
; learn (1 to 15).  
;===========================================================================

; general purpose registers

ind	equ	00h		; indirect address register
rtcc	equ	01h		; real time counter clock
pc	equ	02h		; program counter
status	equ	03h             ; status register
fsr	equ	04h		; file select register
porta   equ     05h		; port a
portb   equ     06h		; port b

; user defined register

flags	equ	07h		; user flag register
address	equ	08h		; address register
txnum	equ	09h		; current tx
outbyt	equ	0ah		; general data register
mask	equ	outbyt		; mask register used in decryption
tmp_cnt	equ	outbyt		; temporary counter

; counter registers

cnt0    equ     0bh		; loop counters
cnt1    equ	0ch		
cnt2    equ     0dh		

cnt_hi	equ	0eh		; 16 bit clock counter
cnt_lw	equ	0fh		

; circular buffer register

csr0    equ     10h            	; 64 bit receive shift register
csr1    equ     11h            
csr2    equ     12h            
csr3    equ     13h            
csr4    equ     14h            	
csr5    equ     15h            
csr6    equ     16h            
csr7    equ     17h            

; temp registers
tmp1	equ	18h		; temp register for read and write
tmp2	equ	19h		; temp register for read and write
reg	equ	1ah		; not used
reg1	equ	1bh		; not used

key0	equ	1ch		; 64 bit key shift register
key1	equ	1dh
key2	equ	1eh
key3	equ	1fh
key4	equ	cnt2
key5	equ	csr5
key6	equ	csr6
key7	equ	csr7

; ***** user register re-mappings ***************

hop1	equ	csr0		; 32 bit hopcode register
hop2	equ	csr1
hop3	equ	csr2
hop4	equ	csr3

; received transmission open 32 bits 

ser_0	equ	csr7		; 28 bit serial number
ser_1	equ	csr6
ser_2	equ	csr5
ser_3	equ	csr4

; received transmission encrypted 32 bits 

func	equ	csr3		; button code & user bit function byte
code1	equ	csr2		; discrimination value
cntr_hi	equ	csr1		; 16 bit rx counter high byte
cntr_lw	equ	csr0		; 16 bit rx counter low byte

; ********* eeprom memory *******
lrnptr	equ	01h		; learn pointer

; ********* porta bit definitions *******

res0	equ	0h		; reserved pin
rfin	equ	1h		; rf input
lrn	equ	2h		; learn button
led	equ	3h		; learn indicator led output - valid signal

; ********* portb bit definitions *******

s0	equ	0h		; s0 output
s1	equ	1h		; s1 output
s2	equ	2h		; s2 output
s3	equ	3h		; s3 output

dio	equ	4h		; eeprom data line
clk	equ	5h		; eeprom serial clock
cs	equ	6h		; eeprom chip select
res1	equ	7h		; reserved pin

; ********* compiler defines ******************
nbits   equ     64      	; maximum transmission bit length
min     equ     560            	; transmission header minimum length [鍿]
trisa	equ	0111b		; porta: tri-state value
wrcfg	equ	00000000b	; portb: eeprom write tri-state value
rdcfg	equ	00010000b	; portb: eeprom read tri-state value

;****** flags definitions **************
bitin	equ	0h		; rf bit value 
lrnf	equ	1h		; learn flag
sec_cnt	equ	2h		; second counter is being checked
relearn	equ	3h		; relearning a transmitter

;****** status register bit definitions *****************
c       equ       0		; carry
dc      equ       1		; digit carry
z       equ       2		; zero
pd      equ       3		; power down
to      equ       4		; timeout
pa0     equ       5		; not used
pa1     equ       6		; not used 

;===========================================================================
; page 0: 
;===========================================================================
	org 00h

;===========================================================================
;
; function     : reset ()	      			
;
; description  : program reset routine
;
;===========================================================================

reset	
	movlw	000111b			; setup rtcc prescaler
	option

	clrf	porta			; reset porta
	clrf	portb			; reset portb

	movlw	trisa			; setup porta
	tris	porta
	movlw	wrcfg			; setup portb
	tris 	portb

	clrf	flags			; reset flags

	goto	m_loop			; goto main program loop

;===========================================================================
;
; function     	: rot_shift()	      			
;
; description  	: right rotate 64 bit receive shift register
;
; note		: this routine must be in the lower half of the page
;
;===========================================================================

rot_shift
        rrf     csr7,f
        rrf     csr6,f
        rrf     csr5,f                     
        rrf     csr4,f                     
        rrf     csr3,f                     
        rrf     csr2,f                     
        rrf     csr1,f                    
        rrf     csr0,f                    
	retlw	0

;===========================================================================
;
; function     	: tx_lookup ()	      			
;
; description  	: transmitter address calculation
;
; note		: this routine must be in the lower half of the page
;
;===========================================================================

tx_lookup
	movf	txnum,w			; use transmitter number to calculate 
	movwf	address			; address of transmiter block
	clrc				; multiply by 4 
	rlf	address,f
	rlf	address,f
	movlw	04h			; and add 4
	addwf	address,f
	retlw	0			; return

;===========================================================================
;
; function     	: tst_rtcc ()	      			
;
; description  	: update rtcc counter 
;
; note		: this routine must be in the lower half of the page
;
;===========================================================================
tst_rtcc
	clrwdt				; reset watchdog timer
	movlw	trisa			; update tri-state register for porta
	tris	porta

	btfss	rtcc,7			; test for 32ms timeout	on rtcc msb
	retlw	0			; ... do quick return to receive routine

; **** increase 16 bit clock timer *******

	bcf	rtcc,7			; clear msb of rtcc
	incf	cnt_lw,f		; increase 16 counter
	skpnz				; increase upper byte if zero ( overflow )
	incf	cnt_hi,f
	retlw	0

;===========================================================================
;
; function     	: tst_timer()	      			
;
; description  	: test 32ms timer and update outputs if required
;
; note		: this routine must be in the lower half of the page
;
;===========================================================================

tst_timer
; ***** test for 500 ms timemout on outputs **********
	btfss	cnt_lw,4		; test for 500 ms timeout
	goto	tst_30			; ... if not test 30s timeout

	movlw	070h;07fh;+++++0f0h
	andwf	portb,f			; down all pulse outputs 

 ; ********* test for 30 s learn timeout *************
tst_30	btfss	flags,lrnf
	goto	tst_end
	
	btfsc	cnt_hi,2		; test for learn timeout
	goto	reset			; ... if learn timemout force soft reset 

tst_end	
	retlw	0h

;===========================================================================
;
; function     	: sendc ()	      			
;
; description  	: send eeprom command 
;
; note		: this routine must be in the lower half of the page
;
;===========================================================================

sendc
	clrwdt				; reset watchdog timer

        bcf     portb,cs                ; reset cs state
        bcf     portb,clk               ; reset clk state
        bcf     portb,dio               ; reset dio state

        movlw   wrcfg
        tris    portb                   ; dio = output
        goto    $+1                     ; wait for outputs to settle
        bsf     portb,cs                ; select eeprom
        setc                            ; start bit = 1
        movlw   9d                 	; start bit + 8 data bits
	movwf	cnt1

sendc2
        skpc                            ; test bit
        bcf     portb,dio               ; write to dio
        skpnc                           ; test bit
        bsf     portb,dio               ; write to dio
        goto    $+1                     ; wait 2 us
        rlf     outbyt,f                ; get next bit into carry
        bsf     portb,clk               ; clock high
        goto    $+1                     ; wait 2 us
        goto    $+1                     ; wait 2 us
        bcf     portb,clk               ; clock low
	decfsz	cnt1,f			; loop counter
        goto	sendc2
        bcf     portb,dio               ; avoid contention with read
        retlw   0

;===========================================================================
;
; function     	: eewrite ()	      			
;
; description  	: write 16 bit value to eeprom 
;
; note		: this routine must be in the lower half of the page
;
;===========================================================================

eewrite

; ******* eeprom write enable ******************

write0  movlw	30h			; write enable command
	movwf   outbyt               	
        call    sendc			; send command to eeprom
        bcf     portb,cs                ; end command, deselect

; ******** write 16-bit word to eeprom *********

write1  movfw   address			; get eeprom address
	movwf	outbyt
        bsf     outbyt,6		; write command
        call    sendc                   ; send command to eeprom

	movlw	16d			; 16 data bits
        movwf   cnt1	                

write2
        btfss   tmp1,7			; test msb of 16 bit word

⌨️ 快捷键说明

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