M
Author:
AN672
FIGURE 1:
MICROCHIP MIDRANGE
DECODER
1
2
3
4
5
6
7
8
9
18
17
16
15
14
13
12
11
10
RFIN
NC
OSCIN
OSCOUT
VDD
S_DTA
EE_CS
EE_CLK
EE_DIO
PICmicro™ Midrange MCU Code Hopping Decoder
Vivien Delport
Microchip Technology Inc.
OVERVIEW
This application note describes the working of a
K
EE
L
OQ®
code hopping decoder implemented on a
Microchip Midrange MCUs (PIC16C6X, PIC16C7X,
PIC16C62X) The software can be used to implement a
stand alone decoder or be integrated with the user
application. The decoder supports the Microchip’s
HCS200, HCS201, HCS300, HCS301, HCS360, and
HCS361 K
EE
L
OQ
hopping code encoders. The decoder
supports normal and secure learning. Two manufactur-
ers codes allow different manufacturers to share a pub-
lic key, but retain their own private keys.
LRNIN
LRNOUT
NC
MCLR
GND
S0
S1
S2
S3
KEY FEATURES
• Supports two manufacturer’s codes
• Compatible with Microchip’s HCS200, HCS201,
HCS300, HCS301, HCS360 and HCS361
encoders.
• PIC16C6X, PIC16C7X and PIC16C62X platforms
• Automatic baud rate detection
• Automatic Normal or Secure learn detection
• Four function outputs
• Six learnable transmitters
• RC Oscillator
• Serial interface
FUNCTIONAL INPUTS AND OUTPUTS
TABLE 1:
Mnemonic
RF IN
LEARN INIT
LEARN INDICATION
MICROCHIP DECODER FUNCTIONAL INPUTS AND OUTPUTS
Pin Number
18
I
2
Input / Output
I
1
O
Function
Demodulated PWM signal from RF receiver. The decoder
uses this input to receive encoder transmissions.
Input to initiate learning.
Output to show the status of the learn process (in an inte-
grated system this will be combined with the system sta-
tus indicator).
Serial data string output which contains the function code,
V
LOW
bit and function code match bit.
Function outputs, correspond to encoder input pins.
External Serial EEPROM Interface lines.
S_DTA
S0, S1, S2, S3
EE_CS
EE_CLK
EE_DIO
13
6, 7, 8, 9
10,11,12
O
O
I/O
K
EELOQ
is a registered trademark of Microchip Technology, Inc.
PICmicro is a trademark of Microchip Technology, Inc.
Microchip’s Secure Data Products are covered by some or all of the following patents:
Code hopping encoder patents issued in Europe, U.S.A., and R.S.A. — U.S.A.: 5,517,187; Europe: 0459781; R.S.A.: ZA93/4726
Secure learning patents issued in the U.S.A. and R.S.A. — U.S.A.: 5,686,904; R.S.A.: 95/5429
©
1998 Microchip Technology Inc.
DS00672C-page 1
AN672
PUBLIC AND PRIVATE
MANUFACTURER’S CODE
The decoder supports two manufacturer’s codes,
called the public manufacturer’s code and private man-
ufacturer’s code. This feature allows two manufacturers
to share one public manufacturer’s code, but retain
their own private manufacturer’s code. The decoder
uses the public manufacturer’s code first to drive the
encoder’s decryption key, but if learn fails, it will retry
using the private manufacturer’s code.
TRANSMITTER LEARN FLOW
To be able to use a transmitter with the decoder, the
transmitter must first be learned into the decoder. Add-
ing a transmitter is done by pressing the learn button. If
the button is pressed for longer than 10 seconds, the
decoder executes an “erase all” function, which will
remove all the transmitters learned.
Normal Secure Learn Selection:
In learn mode, the
decoder monitors transmissions for 4 seconds. If two
codes are received with different serial numbers, the
first code is used as the hop code and the second as
the seed for the secure learn algorithm. If the two serial
numbers are the same, the first received code will be
used for the normal learn algorithm.
Manufacturer’s Code Selection:
The decryption key
is derived using the public manufacturer’s code stored
in a ROM table. The received hopping code is validated
by comparing the received transmission’s discrimina-
tion bits with the lower bits of the serial number. If the
decryption validation fails, the decoder will derive the
decryption key again by using the private manufac-
turer’s code, also store in a ROM table. If the decryption
validation was successful, the decoder will calculate a
checksum value on the transmission’s serial number.
All of the information is then stored in an unused block
in the EEPROM. The same memory block will be used
if the transmitter was already learned. The result of the
learn sequence is displayed on the LED.
PROGRAM FLOW
The decoder software will run on any PIC6C6X/7X with
1K program memory. The operating frequency is
4 MHz. The clock speed is important as the reception
routine (
RECEIVE
) has some critical timing specifica-
tions. Other decoder functions that rely on a 4 MHz
clock speed are the hold times of the various outputs,
time-outs, etc. The compiler used is MPASM.
A high-level description of the main program flow, the
transmission validation flow, and the transmitter learn
flow are described in the following sections. More
detailed descriptions of the other modules can be found
in Application Note AN642.
MAIN PROGRAM FLOW
After reset, the decoder enters the main loop where it
spends most of the time. The main loop checks the
learn button and if pressed (
TST_LEARN
) enters the
learn mode. The microcontroller checks transmissions
from the encoders (
RECEIVE
). Once 65 bits are
received, the microcontroller validates the transmis-
sion. When a valid transmission is received from a
learnt encoder, the decoder sends out a serial data
string containing the function code (
TX_FUNC
) and sets
the appropriate function outputs (
M_BUT
).
COMPILER OPTIONS
Delayed Increment:
When this option is enabled, the
decoder will automatically increment the synchroniza-
tion counter by twelve, 30 seconds after the last valid
reception. The synchronization window is increased
from 16 to 256 in this mode. Delayed increment is used
to defeat jamming code grabbers in single button trans-
mitters. This option is enabled by setting the define vari-
able
DLY_INC
to 1 and recompiling the code.
TRANSMISSION VALIDATION FLOW
After reception of a code, the decoder will first check if
the transmitter is learnt on the decoder. This is done by
calculating the checksum on the received transmis-
sion’s serial number and then searching through the
transmitter blocks stored in EEPROM to find a match.
If a match is found, the decoder reads the decryption
key stored for that transmitter and decrypts the hopping
code portion. The 10 LSBs of the discrimination value
are compared to the 10 LSBs of the serial number. The
16-bit synchronization counter is validated by checking
if the received counter is in the blocked window. The
decoder then checks if the counter is in the double
operation window. If this is the case, the decoder will
wait for the next sequential transmission to synchro-
nize. If the counter is within the single operation win-
dow, the decoder updates the EEPROM counters and
then generates the appropriate function output.
SERIAL FUNCTION STRING OUTPUT
The decoder’s serial output sends out a function byte
which consists of the function code, battery low status
flag, and a function code match bit. After the last bit
was clocked out, the line will go high for 500 ms.
Repeated transmissions will, as with the binary func-
tion outputs, extend this 500 ms time-out. Start bit is
one and the stop bit is zero.
The data byte format for this output is shown in Figure 2
DS00672C-page 2
©
1998 Microchip Technology Inc.