" DECODE2.BS2 "
by 'radioman'
WA6BRM
Portland, OR

ver. 2.8
Aug. 1996
( origional version )


Here is a sample DTMF decoded combination lock program for the
Basic Stamp 2 . It was designed to use the CM 8880 Touch-Tone
encoder/decoder chip . The "Listen" routine is based on Scott
Edwards' DTMF_RCV.BS2 program. Pin 4 is the "register-select"
pin ( 0=data ). Pin 5 is the R/W pin ( 0=write ). Pin 6 is the
"chip-select" pin ( 0=active ). Contact Scott Edwards Electronics
for CM8880 chips, DTMF programs, and circuit diagrams ...

The following program uses the sequence of " *1234567# " as the
"code" for the Lock portion of the program . The "code" is placed
in the Lock lookup string, 1 to 9 digits in length, which has 16
corresponding string positions : D,1,2,3,4,5,6,7,8,9,0,*,#,A,B,C .

The "value" at each position of the string is the key sequence of
that digit . A string value of "0" forces a reset ( wrong digit )
and is used to turn off the relay latched output device. A "zero"
is used for all remaining digits NOT used in the combination code.

With incorrect code attempts, one needs to input an additional
"reset" DTMF tone ahead of the "code" string ( any unused digit )
for proper reset before use .

When the proper sequence is received, a relay routine is
activated as an output device. Applications and all circuit
descriptions are listed after the end of this program :





T var byte . . . . . . . . . . . . . . . . . . . . . . . Received DTMF digit
df var bit . . . . . . . . . . . . . . . . . . . . . . . . DTMF-received flag
ds var INL.bit2 . . . . . . . . . . . . . . . . . . . DTMF-detected status bit
C var word . . . . . . . . . . . . . . . . . . . . . . Tones rcvd counter variable
G var byte . . . . . . . . . . . . . . . . . . . . . . . Sequence counter variable
J var byte . . . . . . . . . . . . . . . . . . . . . . . Table counter variable


OUTL = %01111111 . . . . . . . . . . . . . . . . . . . . pin 7 low, pins 0-6 high
DIRL = %11111111 . . . . . . . . . . . . . . . . . . . . set up write to 8880 (out)
OUTL = %00011000 . . . . . . . . . . . . . . . . . . . . set up CRA; write to CRB
high 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .low 6 to high 6 = "write"
OUTL = %00010000 . . . . . . . . . . . . . . . . . . . . clear CRB; rdy/snd DTMF
high 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . low 6 to high 6 = "write"
DIRL = %11110000 . . . . . . . . . . . . . . . . . . . . . set 4-bit bus to input
high 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . set R/W to "read"


Off: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Off routine
. low 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . turn off output device

Begin: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Reset routine
. C=0 : G=0 : J=0 . . . . . . . . . . . . . . . . . . . . . . . clear all variables to zero

Listen: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Listen for DTMF
. high 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . read status register
. low 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . activate chip-select pin
. df = ds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . store DTMF-det bit in flag
. high 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . de-activate chip-select pin
. if df = 1 then Lock . . . . . . . . . . . . . . . . . . . . . . if tone, then continue
. goto Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . listen again

Lock: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tone detected, test code
. low 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . get DTMF data (low rs pin)
. low 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . activate chip-select pin
. T = INL & %00001111 . . . . . . . . . . . . . . . . . . remove upper bits using AND
. high 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . de-activate chip-select pin
. C=C+1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . increment tone counter
. if C>2000 then Begin . . . . . . . . . . . . . . . . . . . . resets >2000 wrong entries
. lookup T,["0234567800019000"],J . . . . . . . . . convert tone to string
. J=J-48 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . convert string to value
. if J=0 then Off . . . . . . . . . . . . . . . . . . . . . . . . . . wrong digit "reset"
. if C=1 and J=1 then Key . . . . . . . . . . . . . . . . . . IF all digits are in the
. if C=2 and J=2 then Key . . . . . . . . . . . . . . . . . . correct order, AND after
. if C=3 and J=3 then Key . . . . . . . . . . . . . . . . . . only one attempt, THEN
. if C=4 and J=4 then Key . . . . . . . . . . . . . . . . . . increment the sequence
. if C=5 and J=5 then Key . . . . . . . . . . . . . . . . . . counter variable : "G" ...
. if C=6 and J=6 then Key .
. if C=7 and J=7 then Key .
. if C=8 and J=8 then Key .
. if C=9 and J=9 then Key .
. goto Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . listen again

Key: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Sequence counter
. G=G+1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . increment
. if C=9 and J=9 and G=9 then Relay . . . . . . . . . . activate output device
. goto Listen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . listen again

Relay: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relay output routine
. pause 800 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . wait time delay
. high 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . turn on output device
. pause 200 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . wait time delay
. goto Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . begin again





The output routine, Relay, can be set-up to latch on and reset off
an LED connected from ground; through a 4700 ohm series resistor, to
pin D7. The particular LED, by Radio Shack, draws a maximum of about
2 ma of current. With the series resistor, it draws about 1 ma here.
The Relay routine, is used to turn on an appliance - until a reset
tone is received to then turn off that appliance. With 9 digit code
sequence, the possible combinations are : 4,151,347,200 in all !

The final circuit used a 1000 ohm series limiting resistor which
is connected to the output pin D7 and to the Base input of a small
2N2222 transistor. A 0.047 uFD disk also connects from the Base to
ground as an RF bypass cap. The Emitter grounds, and the Collector
connects to a 500 ohm, 9 volt relay coil, with a reverse diode
( 1N4148 ) across the coil. The free end of the relay coil goes to a
+9 volt unregulated power cube, which is regulated down to +5 volts
by Stamp 2 for itself, and the CM8880 DTMF chip. The isolated N.O.
relay output (switch) was used to drive a large power relay circuit.

Output D7 "pin" on the BS2 is actually chip pin # 12 .
Additionally, a pair of 1N4148 diodes can be connected to D7 ahead
of the 1000 ohm resistor, with one cathode, and one anode connected
to D7. The free anode goes to ground, and the free cathode goes to
+5 volts. Like a reverse diode across the relay coil, these diodes
protect the Stamp 2 from voltage spikes . Final circuit has a 10K
pull-up resistor to 5 volts connected to pin 13 of the CM8880, as
well as a fixed 1000 ohm 1 watt resistor to the audio input CM8880's
pin 2. An additional 10 ohm 10 watt load resistor connected from
audio "hot" output to ground from the scanner's speaker output jack
as a replacement speaker load.

This application used a 2-meter ham radio scanner receiver as a
DTMF audio source, and the output power latch relay to activate an
electric door strike ( solenoid and "dead bolt" ). Alternatively,
the relay can switch on a speaker from the radio, for traditional
ham radio "selective call" use. Slightly different crystals can be
used in place of the 3.579545 MHz crystal for NON-standard DTMF
tones that can pass through 2-meter "ham" repeaters as well ...
The applications are endless ... enjoy!



73's ( best wishes )
J. Altieri


1/12/97


internet : radioman@seasurf.com

http://seasurf.com/~radioman/


A.L.O.A. # 021428

(previous version 2.7 - total downloads = 160 : 1/96)
(download at : ftp.parallaxinc.com - decode2.bs2)



"Saving to Disk"

DOWNLOAD :

The "software" - this BASIC Stamp II Program : decode2.bs2
more software - the 2-digit Ham Radio version : select.bs2
*new* software - 8/97 "beta" : decode *new*.bs2
*new* newsletter - 10/97 : newsletter
The "hardware" - the Schematic Diagram/Tech Info. : tone.pdf
( A free PDF file viewer - Adobe Acrobat Viewer 3.0 )




<<BACK