[分享KEELQ 滚动码解码源程序---1
[分享KEELQ 滚动码解码源程序---1LIST 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
DISC 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 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
页:
[1]