This is only a preview of the January 1996 issue of Silicon Chip. You can view 22 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Articles in this series:
Articles in this series:
|
By MIKE ZENERE
Build a magnetic card
reader & display
Have you ever wanted to find out what’s written
on your credit card or other magnetic stripe
cards? Now you can do it. This unit will enable
you to read and display the contents of track
two on any magnetic card and could be used as
the basis for an electronic door lock.
Magnetic cards have been around
for many years and have found their
way into many fields such as banking,
security and vending machines. Most
cards follow defined guidelines as to
their construction and layout and are
therefore very flexible to the designer.
40 Silicon Chip
Each card has three tracks but the most
commonly used is track two.
Recalling data from the card has
become relatively simple in the last
few years with modern card readers.
These generally have a single on-board
chip to decipher the raw data from the
read head. This looks much like the
record/play head in a cassette deck.
The on-board chip generally contains conditioning circuitry to pick up
the signal, reject noise and provide a
digital output. Most card readers interface via three wires which are Clock,
Data and Card Valid.
Assuming that a microprocessor is
hooked up to the card reader, a typical card read takes place as follows.
When a card is swiped through the
card reader, the Card Valid line goes
low after eight or nine flux reversals,
indicating that a valid card is present.
The microprocessor monitors the
clock line and waits until the Clock
Magnetic Card Standards
Most magnetic cards
adhere to defined standards
that describe the physical
as well as electrical layout.
The standards outline card
size, magnetic stripe and
track positioning, and format
information.
The information is recorded onto the card using
a technique known as
Two Frequency Coherent
Phase Recording or F/2F.
This allows for serial recording of self-clocking data on
each track. The data consists of data and clocking
bits together. When a flux
transition occurs between
Fig.1: the track layout on a magnetic card. Track 1 can record alphanumeric data,
clock cycles, a “one” is
while tracks 2 and 3 provide only numeric data.
obtained and when there is
an absence of flux between
encoded using 4-bit BCD with odd
start of the actual data to be read,
cycles a “zero” is obtained.
parity.
followed by the data, the end sentiStandard magnetic cards have
nel, LRC and finally, trailing zeros to
All tracks are recorded with the
three data tracks and each has its
the end of the card. The term LRC
least significant bit first and the parity
own subtle differences. Track 1 has
stands for “longitudinal redundancy
bit last. The higher density track three
a bit density of 210 bits per inch,
check” and is used for horizontal
holds up to 107 numerics while track
giving it the ability to hold a total of
error detection.
two holds only 40. The necessity for
79 characters over the entire length
start and end sentinels and other
By far the most commonly used
of the card. Each character on this
separating characters reduces the
track is track two. Although holding
track is made up of six data bits and
above storage capabilities to a cerless information than the others, this
one parity bit, providing 64 differtain extent.
track has all the data required to do
ent alphanumeric combinations to
a banking transaction. If there is a
choose from. The card and track
Reading or writing of data to the
need for the customer’s name to be
layout is shown in Fig.1.
card generally follows the same
present, then track one is used as it is
path for all three tracks. First, leadThe remaining tracks, two and
the only one that holds alphabetical
ing zeros are encoded to indicate
three, provide only numeric data
characters. The third track is special
the presence of data and to provide
and have a bit recording density of
in that data may be written or read
synchro
n isation. Next, the start
75 bpi and 210 bpi respectively. The
during a transaction.
sentinel is encoded to indicate the
character set for these two tracks is
line goes low, indicating that data is
present on the data line. The data bit is
collected and temporarily stored until
a succession of bits is gathered to make
a 5-bit word, with four data bits and
one parity bit. When the 5-bit word is
obtained and stored, the cycle repeats
itself until all the 5-bit characters have
been read into memory. The processor
can now go back over the data and
analyse it for parity.
Date rate & swipe direction
The data rate even for the high
density tracks is quite low, allowing
almost any microprocessor to sample
and collect the data. Let’s assume that
the card is passed through the reader
at around one metre per second.
This translates to around 9983 bps
or 1426 7-bit characters per second,
meaning that a new data bit is presented about every 100µs. Most card
readers are capable of reading two of
the three tracks in one swipe. Even
allowing for this extra load, most
microprocessors running at 1MHz or
more will handle this with ease.
Although data is written onto the
card in a particular format, there being
a start and end sentinel, this does not
limit the programmer to write software
to read a card when swiped forwards
or backwards.
In a “backward read”, the card data
is simply read as usual and stored in
memory but this time the last character
is first and the first character is last.
The program simply detects this by
looking for the start and end sentinels
and then corrects itself.
Card reader
The card reader and display unit to
be presented here is self-contained on
January 1996 41
42 Silicon Chip
Fig.2: the circuit is based on a magnetic card reader module with its own on-board decoding. The data from
this module is fed via three lines to the microprocessor (IC1) and this in turn drives a multiplexed 4-digit
display. The track 2 contents of four cards can be stored in the EEPROM (IC2) and this data can be used
as the basis of an electronic door lock. IC3 and its associated parts form a watchdog timer circuit and this
automatically resets the microprocessor if signal activity from pin 11 ceases, indicating that the processor
has “crashed”.
a PC board measuring 128 x 101mm.
As well as the card reader module
with its integral PC board, there is
a 4-digit display, a 28-pin 68705P3
microprocessor (IC1), a piezo buzzer
and three pushbuttons. The circuit is
shown in Fig.2.
The card reader and its integral PC
board has all the circuitry necessary
to decode and convert the raw data
coming from the card being read. The
data is transformed into logic levels
and is then sent out via three serial
lines to the processor. The card reader
is connected to the logic board via a
5-way cable, with three of the lines
for data and the other two for power.
The recording function of the circuit
is performed by a small serial EEPROM,
IC2. Once the unit is placed in the
record mode and a card is swiped
through, the data will be saved in the
EEPROM.
Because timing is not critical in this
project, a crystal for the microprocessor is not necessary. Instead, by placing
an 18kΩ resistor from pin 5 to the +5V
rail, an inbuilt oscillator is enabled,
causing the processor to run at near
full speed.
Beeper & relay driver
A DC self-oscillating beeper is
connected to port B, pin 12, on the
processor. Port B can sink up to 10mA
which is sufficient for this application
and is pulled low to turn on the beeper.
The relay is driven by transistor Q1
which is controlled by the line from
pin 24. This line is normally low and
the relay is off. When a valid card is
swiped through the reader, the proces
sor port pin 24 goes high for a period of
time and turns on Q1 which operates
the relay.
The display consists of four 7-segment common anode displays multi
plexed together. The cathodes are
driven directly by port lines from the
processor, while each display anode
is driven by its respective PNP driver
transistor (Q2-Q5).
The processor receives an interrupt
every 5ms from an internal timer. Each
time an interrupt is received, the processor switches off the current display
digit that it is driving and turns on
the next. In this manner, each digit is
only on for 5ms before the next digit is
updated. This gives each digit a total
on-time of around 250ms per second;
ie, a duty cycle of 25%.
The SHIFT LEFT and SHIFT RIGHT
buttons are used to move the display
laterally to enable the user to view the
entire number.
Construction
Begin assembly of the PC board
by mounting the four standoffs, one
at each corner. This done, install the
diodes, resistors, links and capacitors.
Note the polarity of the electrolytic
capacitors and the diodes. Install the
7805 regulator and fit it with a small
heatsink.
Next, install the transistors, the
two small ICs and the socket for IC1
but do not install the processor until
after the unit has been powered up
and a voltage check performed. When
installing the four 7-segment displays,
their decimal points should be close
to the edge of the PC board.
The remainder of the components
can now be mounted, noting the orientation of the pushbutton switches.
The card reader module is attached to
the PC board with screws fitted from
the underside. The back of the read
head should face the outside edge of
the board.
When all the assembly work is complete, apply 12V DC to the board and
check that +5V is present at pins 3 &
6 of the socket for IC1, at pin 8 of IC2,
pins 4 & 8 of IC3 and at the emitters
of Q2-Q5.
If this checks out, remove the power,
plug in the processor and connect the
card reader module. Reapply power
– the buzzer should beep four times
and the display should read “OPEr”.
The unit is now ready for a test drive.
Before you start, here are a few tips.
The mode button is used to cycle
through the various available modes.
Each time you press this button, the
next option appears on the display.
The modes are OPEr (operate), rEC
(record), d EL (delete), p LAY and
rEAd. When in the operate mode,
the display blanks out after about 30
seconds to conserve power. If any
button is pressed after this time the
display will light and programming
may continue.
Initial set up
If this is the first power-up you
will need to reset the memory of the
EEPROM and this is done by holding
down SHIFT LEFT and SHIFT RIGHT
and applying power. The EEPROM will
be cleared and the relay on-time will
be set to three seconds.
PARTS LIST
1 PC board, 128 x 101mm
1 magnetic card reader module
1 piezo buzzer
1 12V miniature SPDT relay
3 momentary contact pushbutton
switches
1 5-way connector
1 2-way connector
2 3-way PC-mount insulated
terminal blocks
4 PC standoffs
Semiconductors
1 MC68705P3 programmed
microprocessor (IC1)
1 93C46 EEPROM (IC2)
1 555 timer (IC3)
1 7805 5V 3-terminal regulator
(REG1)
4 HD11310 7-segment red LED
displays (DISP1-4)
3 1N4004 silicon diodes (D1-D3)
2 PN100 NPN transistors
(Q1,Q6)
4 PN200 PNP transistors
(Q2-Q5)
Capacitors
2 100µF 16VW electrolytic
1 1µF 16VW electrolytic
4 0.1µF monolithic
Resistors (0.25W, 5%)
1 1MΩ
1 1kΩ
1 33kΩ
7 330Ω
1 18kΩ
1 22Ω 0.5W
11 10kΩ
Miscellaneous
Screws, nuts, shakeproof
washers, solder.
Where to buy the parts
A complete kit of parts for the
magnetic card reader is available
from the author. This includes all
electronic components except for
the 12VDC power supply and a
case. The price is $75.00 plus
$7.50 for postage and packing.
Completely assembled and tested
units are also available at an extra
cost of $20.00. The documented
source code is a further $8.00 for
the print out.
Please make postal money orders
payable to Mike Zenere, 83 Head
ingley Road, Mt. Waverley, Vic
3149. Phone (03) 9803 3535.
Note: copyright© of the PC board
is retained by the author.
January 1996 43
Fig.3: install the parts on
the PC board as shown here,
taking care to ensure that
the displays, switches and
other polarised parts are
correctly oriented. The card
reader module is connected
to the main PC board via a
5-way cable.
The unit can be used in two modes
which enable the user to: (1) read and
display cards; and (2) operate the relay.
Let’s initially talk about the first option. After power-up, the unit should
be showing “OPEr” indicating that it
is in the door access mode. To change
this, push the mode button until the
display shows “rEAd”, indicating that
if a card is swiped, its track 2 contents
will be displayed.
Swipe any card through and you
should see some digits or letters on
the display. These will correspond to
the digits stored on the magnetic card
with the start sentinel (b) being the first
character. The display can only show
four numerics at a time so to view the
rest, push the SHIFT LEFT button once
to view the next character to the right.
Keep doing this until the display
shows the end sentinel (F) or until the
display shifts no further . While doing
this, look at the front of the card and its
embossed number. You should see this
number appear in the display as you
move along. If you wish, you can move
the display to the right by pushing the
SHIFT RIGHT button.
To view another card, simply swipe
it through the slot.
Door lock applications
The following functions relate to
the operate mode which is when the
44 Silicon Chip
unit is used as a door lock. After going
through the functions listed below,
place the unit in the operate mode by
hitting the mode button until “OPEr”
is displayed.
After a short time, the display will
blank out and the unit will now be
ready to compare swiped cards with its
memory contents. If a match is found,
the door release relay will operate for
a set time and a single beep will be
heard. If no match is found, two beeps
will be heard.
Recording a card
The unit can store up to four cards
in the serially fed EEPROM. The MODE
button is hit until the “rEC” message is
displayed. If the memory is full, there
being four cards stored already, the
display will alternate between “FULL”
and “rEC” and you will not be able to
store any more cards until you have
used the delete function. Each time a
card is entered, the unit jumps back
to the operate mode until the function
key is once again hit.
Deleting a card
You can delete a previously entered
card by first hitting the mode button
until “dEL” is displayed. Swipe the
card to be deleted through the slot
and if the card is found and deleted
from memory, a single beep is heard.
If the card is not found the unit will
beep twice.
Relay operation
When a card has been successfully
recognised by the unit, it will operate
the relay for a set time which will be
between one and nine seconds. To set
this time, hit the MODE button until
the “rLAY” message is shown. Hit
either of the SHIFT buttons to display
the current setting.
Using the SHIFT LEFT and SHIFT
RIGHT buttons, set the relay on-time
in the display to the desired number;
eg, the display may show something
like 0002, indicating that the relay will
operate for about two seconds.
Hit the mode button again to save
the new number in memory.
If using the unit as a door lock, you
can remove the magnetic card reader
module from the PC board and extend
its con
necting cables to enable the
two sections to be housed separately.
The two separated units can then be
mounted on either side of the wall to
provide greater security.
Battery back-up
Provision has been made for battery
back-up in case of a power failure. The
battery GND is commoned to the power
supply ground and the battery +12V
SC
is connected via D2.
|