This is only a preview of the July 2003 issue of Silicon Chip. You can view 27 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. Items relevant to "PowerUp: Turns Peripherals On Automatically":
Items relevant to "A "Smart" Slave Flash Trigger":
Items relevant to "A Programmable Continuity Tester":
Articles in this series:
Purchase a printed copy of this issue for $10.00. |
New design programs blank
Gold wafer smart cards
By PETER SMITH
Smart card reader
& programmer
This unit allows you to program both the microcontroller and EEPROM in the popular “Gold”
wafer smart cards. It hooks up to the serial port
of your PC and can be operated as a freestanding unit or installed in a PC drive bay.
B
ACK IN THE January 2003 issue of
SILICON CHIP, we described a basic
smart card reader and programmer
that is capable of accessing the EEPROM (data) memory component of
Gold wafer cards over a Phoenix-type
interface.
This type of programmer is all that’s
needed for cards that contain pre-programmed PICs. For blank cards, how22 Silicon Chip
ever, it’s only half of the solution. Read
on to find out why.
Smart card smarts
Smart cards come in dozens of different configurations, with different
microcontrollers, memory sizes and
even contact positions. However, the
cards that we’re interested in conform
to a recognised set of ISO standards,
described in ISO-7816 and entitled
“Identification Cards – Integrated
Circuit Cards with Contacts”.
Parts 1-3 of this document define
things like physical dimensions, contact size and position, and interface
AC & DC characteristics. They also
describe the protocol used to exchange
information across the card interface.
Gold wafer cards
Due to their lower cost and available
software support, this project targets
the “Gold” wafer smart card variety.
The Gold card incorporates just two
ICs: a PIC16F84(A) and a 24(L)C16
EEPROM.
Reproduced from the January 2003
article, Fig.1 depicts the internal insiliconchip.com.au
terconnections. As you can see, the
EEPROM is not wired to the interface
contacts but is controlled exclusively
by the PIC.
In a real application, the PIC is
programmed with a card operating
system. The function of this operating
system depends entirely on the card’s
application but at least one of its tasks
is to provide access to EEPROM data
via the interface.
With this arrangement, the requirements for EEPROM access are quite
straightforward. They entail a relatively simple hardware interface to
the card and some software that can
speak the ISO protocol. This was the
basis of the first reader/programmer
design.
Blank cards
But what happens if the PIC’s program (Flash) memory is blank? With
no card operating system, how do we
access the EEPROM? The answer is,
of course, that it can’t be done with
this type of card (or with the original
reader/programmer design).
So how is the PIC programmed?
Well, the connections between the
PIC and the card contacts have been
designed for dual purposes. As well as
supporting “normal” operation, they
also allow the PIC to be programmed
in-circuit.
Unlike the previous design, then,
this new design includes the ability
to program the PIC on a blank card.
Of course, you can also erase and
reprogram the PIC on a used card too,
if so desired.
Fig.1: this diagram
shows the internals
of a Gold wafer
card. If you want to
know more about
the PIC16F84A
and 24LC16 chips,
detailed data
sheets can be
downloaded from
www.microchip.com
Smartmouse or Phoenix-type interface
is required. On the other hand, to read
or program the PIC’s internal memories, a PIC programming interface is
required.
Our design solves this conundrum
by providing both types of interfaces.
A 4-pole 2-position pushbutton switch
(S1) is used to select between the two
interfaces, or “modes”.
Fig.2 shows the circuit details for
the Smart Card Reader/Programmer.
This shows S1 set to the Smartmouse/
Phoenix (“normal”) position so we’ll
look at the circuit operation in this
mode first.
Smartmouse/Phoenix mode
In this mode, the interface consists
of four signal lines: I/O (Input/Output), CLK (Clock), RST (Reset) and
Card Detect.
All information exchange between
the card and the outside world occurs
in half-duplex serial format on the I/O
interface line. To help with the explanation, we’ll refer to this information
as “data”. However, actual information
exchange may consist of commands
(to the card), status (from the card)
and EEPROM memory data (to and
from the card).
Data from the PC to the smart card
is transmitted on the serial port TXD
line. It arrives on CON4 (pin 3) and is
converted to digital logic levels by the
15kΩ & 100kΩ resistors and clamp diodes D4 & D5. IC2f buffers and inverts
the data and it is then applied to the
smart card I/O (C7) line via a 4.7kΩ
isolation resistor and S1d.
Tracing the I/O line back from the
smart card socket, it connects to pin
11 of IC1 via a 470Ω resistor. This
path carries data from the smart card
back to the PC. It is transmitted on
the serial port RXD line (CON4, pin
2) after conversion to RS232 voltage
PC connection
Initially, Gold cards and their predecessors were designed for use in
set-top boxes and the like. However, it
wasn’t long before someone interfaced
one to a PC serial port and wrote some
software to access the internals. This
is probably the origin of the so-called
“Phoenix” interface.
With a tiny change to the Phoenix
interface, it becomes a “Smartmouse”
interface, another popular “standard”
among the card community. Our new
design is compatible with both of these
interfaces.
How it works
As outlined earlier, the cards that
we wish to read and write contain two
separate ICs: a PIC microcontroller and
an EEPROM. To access the EEPROM, a
siliconchip.com.au
We fitted our prototype to a standard 3.5-inch to 5.25-inch drive mounting kit
which was then slotted into a spare drive bay.
July 2003 23
Parts List
1 PC board, code 07107031,
141mm x 101mm
1 ICA-700 smart card socket
(landing contact style) (CON1)
1 9-way 90° PC-mount female ‘D’
connector (CON4)
1 4PDT PC-mount slide switch
with green LED indicator (S1
& LED3)
2 M205 fuse clips
1 M205 500mA quick blow fuse
2 3-way 2.54mm SIL header strips
2 jumper shunts
1 9-way RS232 cable (D9 male
to D9 female, see text)
240mm (approx.) length of
0.71mm tinned copper wire
Semiconductors
1 MAX232 RS232 receiver/driver
IC (IC1)
2 74HC04 hex inverters (IC2, IC3)
1 2N3906 PNP transistor (Q1)
1 2N3904 NPN transistor (Q2)
1 78L05 +5V regulator (REG1)
1 1N4004 diode (D1)
4 1N4148 diodes (D2-D5)
1 13V 1W zener diode (ZD1)
1 3.579545MHz crystal (X1)
1 6MHz crystal (X2)
1 3mm red LED (LED1)
1 3mm yellow LED (LED2)
Capacitors
1 100µF 25V PC electrolytic
2 10µF 16V PC electrolytic
7 1µF 50V monolithic ceramic
1 220nF (0.22µF) 50V monolithic
ceramic
1 100nF (0.1µF) 50V monolithic
levels by IC1, a MAX232 receiver/
driver IC.
Before communication can be established with a card, it must first be
initialised to a known state. This is
accomplished with the Reset signal,
which is controlled by the serial port
RTS line (CON4, pin 7). Again, IC1
converts this to a logic-compatible
(0-5V) level, after which it is applied
to the RST (C2) line of the card via
switch S1b.
With jumper JP1 positioned as
shown, the RST signal polarity is
compatible with the Phoenix-type
interface. However, by moving the
jumper to position 2-3, the RST signal
24 Silicon Chip
ceramic
2 22pF 50V ceramic disc
Resistors (0.25W, 1%)
1 1MΩ
3 4.7kΩ
1 100kΩ
2 1.5kΩ
3 47kΩ
3 1kΩ
1 15kΩ
6 470Ω
1 10kΩ
1 47Ω
Additional parts for freestanding version
1 2.5mm PC-mount DC socket
(CON2)
9V DC 150mA (min.) plugpack
4 small stick-on rubber feet
Additional parts for PC drive
bay-mounted version
1 90° PC-mount disk drive power
connector (CON3)
1 3.5-inch to 5.25-inch disk drive
mounting adapter & screws
(Jaycar XC-4630 & www.
pccasegear.com.au)
3 M3 x 10mm cheese head screws
3 M3 nuts
6 M3 flat washers
Where to buy a kit
The design copyright for this project
is owned by Jaycar Electronics and
complete kits of the freestanding
version will be available from Jaycar
by the time this article appears in
print (kit includes the PC board plus
all on-board components). Note: the
Jaycar kit will be supplied with standard IC sockets instead of machined
IC sockets, as used on the prototype.
is inverted by IC3b and the interface
becomes Smartmouse compatible.
If you’ve worked with PIC micros
before, you’ll know that apart from
power (Vcc) and ground (GND), they
also require a clock source to function. This is supplied on the CLK (C3)
interface line and is generated by a
conventional Pierce oscillator formed
by IC2e, a crystal and a few passive
components.
To ensure compatibility with a
wide range of cards and software, the
oscillator frequency can be set to either 3.5795MHz (crystal X1) or 6MHz
(crystal X2), depending on the position
of JP2. IC2d buffers the oscillator out-
put and series termination is provided
with a 47Ω resistor.
Card detection
When a card is inserted, it makes
physical contact with a switch at the
rear of the socket. One side of the
switch is connected to ground, while
the other is pulled up to +5V with
a 10kΩ resistor. When the contacts
close, signalling a fully inserted card, a
connection to ground is made through
the switch, pulling pin 10 of IC1 low.
After conversion to RS232 levels
by IC1, the Card Detect signal appears
on serial port lines CD and CTS. Both
lines are driven in order to be compatible with various card applications.
Well, that’s all there is to the Phoenix/Smartmouse interface. It’s very
similar to the circuitry used in the
reader/programmer described last
January. Now let’s look at the PIC programming interface, selected when S1
is in the alternative position.
PIC programming mode
Although this mode utilises the
same physical connections to the card
as those described above, the electrical
characteristics of the signals, as well
as their connections to the PC serial
port, are quite different.
With S1 in the alternative (righthand) position, the board is transformed into a Ludipipo/JDM-compatible PIC programmer. Compatibility with these types of programmers
enables us to take advantage of the
many free PIC programming software
packages available on the Internet.
In this mode, only three signals are
required: DATA, CLK & MCLR/VPP.
As before, data is exchanged over
a single interface line, now named
“DATA”. However, in this mode,
transmission from the PC occurs on
the serial port DTR line (CON4, pin 4).
The incoming data is first converted to
logic levels by IC1 and then inverted
by IC3e. A 4.7kΩ resistor provides the
necessary isolation before the signal
is piped into the card via S1d on the
DATA (C7) line.
Conversely, outgoing data is first
inverted by IC3c and is fed via S1c
and a 470Ω resistor to IC1 for level
conversion and transmission on the
CTS serial line.
When in programming mode, PIC
micros do not require a conventional
clock (oscillator) source. Instead, a
signal timed specifically for the prosiliconchip.com.au
Fig.2: the complete circuit diagram of the Smart Card Reader/Programmer. Slide switch (S1) is central to its operation,
routing signals between the PC’s serial port and the card interface according to the selected mode.
gramming sequence must be provided
on the RB6 pin. Just to confuse matters, this signal is still referred to as
“CLOCK”.
siliconchip.com.au
The CLOCK signal originates from
the serial port RTS line. Once again,
IC1 does the level conversion after
which the signal is inverted by IC3b
and fed to the card via S1a.
Vpp generation
Many early PIC micros, including
July 2003 25
Table 2: Capacitor Codes
Value
220nF
100nF
22pF
µF Code EIA Code IEC Code
0.22µF
220n
224
0.1µF
100n
104
22pF 22p 22
the PIC16F84(A), must be supplied
with a high voltage (12.5V - 13.5V)
during programming of the internal
Flash and EEPROM memories. Our
design uses a unique method of generating this programming voltage (Vpp).
The voltage boosting circuitry is
based around IC1, a MAX232 RS232
line driver and receiver IC. Of interest is the method that this chip uses
to generate the ±10V needed for the
RS232 interface.
Basically, internal switches combined with four external 1µF capacitors form two charge-pump voltage
circuits, one doubling the supply
(Vcc) voltage to +10V (nominal) and
the other inverting the result to obtain
-10V.
By adding diodes D2 & D3 and a
1µF capacitor to pin 4, we’ve extended
the capability of the chip to create a
voltage quadrupling circuit.
With the losses across the diodes,
as well as the loading imposed by the
RS232 drivers and the Vpp regulation
circuitry, the result at the cathode
of D3 is less than four times the Vcc
supply (around 15.6V). However,
this is more than adequate for our
purpose.
Zener diode ZD1 and its 1.5kΩ
series resistor form a shunt regulator,
ensuring a reliable 13V Vpp supply.
We’ve biased the zener with as little
current as possible to minimise load-
Fig.2: refer to this full-size overlay diagram when assembling the board.
Be careful not to install any of the diodes, electrolytic capacitors or ICs
in reverse. They must be oriented exactly as shown here.
Table 1: Resistor Colour Codes
o
No.
o 1
o 1
o 3
o 1
o 1
o 3
o 2
o 3
o 6
o 1
26 Silicon Chip
Value
1MΩ
100kΩ
47kΩ
15kΩ
10kΩ
4.7kΩ
1.5kΩ
1kΩ
470Ω
47Ω
4-Band Code (1%)
brown black green brown
brown black yellow brown
yellow violet orange brown
brown green orange brown
brown black orange brown
yellow violet red brown
brown green red brown
brown black red brown
yellow violet brown brown
yellow violet black brown
5-Band Code (1%)
brown black black yellow brown
brown black black orange brown
yellow violet black red brown
brown green black red brown
brown black black red brown
yellow violet black brown brown
brown green black brown brown
brown black black brown brown
yellow violet black black brown
yellow violet black gold brown
siliconchip.com.au
ing on the MAX232. If the add-on
circuitry were to draw more than a
few mA, it would load down the converter circuitry, lowering the RS232
voltage levels below the specified
minimums.
During PIC programming and verification, the 13V (nominal) Vpp voltage
is switched through to the MCLR/Vpp
(C2) line of the card socket with the
aid of transistors Q1 & Q2 and their
associated bias resistors.
The Vpp enable signal originates
from the serial port TXD line. It is first
converted to logic (0-5V) levels by the
15kΩ & 100kΩ resistors and clamp
diodes D4 & D5. Next, it is inverted
by IC2f and inverted again by IC2b
before driving the base of switching
transistor Q2.
When Q2 switches on, it pulls Q1’s
base towards ground, turning it on
and thus switching Vpp through to the
card socket (via S1b). A 47kΩ resistor
from MCLR/Vpp to ground ensures
that the PIC is held in the reset state
when the Vpp supply is switched
off.
Note that the (newer) PIC16F87X
and PIC16F62X series micros used in
the Silver and Emerald cards do not
require high voltage for programming.
However, Microchip has retained
support for this programming method
to ensure backward compatibility.
Therefore, this project should be able
to successfully program the PICs in all
of these cards, given the appropriate
software.
Read/Write LED
LED1 indicates activity on the I/O
signal line. Due to the inversion of
data between Normal and PIC Programming modes, this LED will either
pulse dimly or appear to be mostly on,
with a perceptible flicker during data
exchange.
Power supply
When used as a free-standing unit,
a 2.5mm DC socket (CON2) accepts
power in the 9-12V DC range. This is
suitable for connection to a low-cost,
9V DC unregulated plugpack (positive
to centre pin).
For use with a laptop PC, the unit
can also be powered from a 9V battery.
The PC board will accept a pair of 1mm
pins for connection to the battery leads
(see Fig.3). Note that you’ll need to fit
an in-line switch, as the current drain
is quite high (about 35mA with the
siliconchip.com.au
The Smart Card Reader/Programmer board connects to a spare serial port on
your PC via a standard RS232 cable (D9 male to D9 female). Note that this
prototype includes both power sockets (only one normally required).
card inserted) and this would quickly
exhaust a PP3 battery.
When installed in a PC drive bay,
12V DC is sourced from the PC power
supply via CON3, which is a disk drive
power socket.
Regardless of the power source,
diode D1 provides reverse polarity
protection. A 500mA series fuse is
included for safety reasons and will
open only in the case of serious failure.
Following the fuse, a 100µF capacitor smooths the input before it is
applied to a conventional 3-terminal
regulator (REG1). All circuit elements
are powered from the regulator’s +5V
output. In addition, the regulator’s
inbuilt current limiting feature, which
comes into play at about 140mA, protects the board if a faulty smart card
is inserted.
Construction
All components mount on a single
PC board, measuring 141mm x 101mm
and coded 07107031. Referring to the
overlay diagram in Fig.3, begin by installing all 12 wire links using 0.7mm
tinned copper wire or similar.
Follow up with all the low-profile
components. Resistors first, then diodes (D1-D5, ZD1), transistors (Q1,
Q2), regulator (REG1) and capacitors.
Note that the diodes must be installed
July 2003 27
Silicon Chip
Binders
REAL
VALUE
AT
$14.95
PLUS P
&
P
Fig.4: to enable the serial/parallel port
driver, check the “Enable NT/2000/XP
Driver” box (see text). Note that this
option is disabled on Windows 9x/Me,
as the driver is not needed for these
versions of Windows.
These binders will protect your
copies of S ILICON CHIP. They
feature heavy-board covers & are
made from a dis
tinctive 2-tone
green vinyl. They hold 12 issues &
will look great on your bookshelf.
H 80mm internal width
H SILICON CHIP logo printed in
gold-coloured lettering on spine
& cover
H Buy five and get them postage
free!
Price: $A14.95 plus $A10.00 p&p
per order. Available only in Aust.
Silicon Chip Publications
PO Box 139
Collaroy Beach 2097
Fig.5: this is what your hardware
settings should look like. You may
need to increase the I/O Delay slider
by a few points if you get the
occasional verify error but start off
with the default value of (6).
Or call (02) 9939 3295; or fax (02)
9939 2648 & quote your credit
card number.
Use this handy form
Enclosed is my cheque/money order for
$________ or please debit my
Visa Mastercard
Card No:
_________________________________
Card Expiry Date ____/____
Fig.6: the default values for IC-Prog’s
smart card settings. Not all cards
support the 6MHz clock rate, so select
the “3.58MHz” setting for maximum
reliability. Jumper JP2 on the PC
board should be set to agree with the
frequency selected here.
Signature ________________________
Name ____________________________
Address__________________________
__________________ P/code_______
28 Silicon Chip
with the cathode (banded) ends oriented as shown.
Orientation of the 10µF and 100µF
electrolytic capacitors is important
too. Their positive sides must be
Fig.7: if you can’t get PIC
programming mode to work, IC-Prog’s
“Hardware Check” feature might
help. Clicking in these boxes toggles
the indicated signal lines, providing a
very useful fault-finding aid.
Fig.8: make
sure that
there is a tick
against the
“Smartcard
(Phoenix)”
option on
the Settings
menu.
aligned as indicated by the “+” symbol
on the overlay.
The two crystals (X1, X2) can go
in next. They mount in a horizontal
fashion, so bend the leads at 90° (about
2mm from the body) before installation. After installation, connect the
crystal cans to ground by soldering
a short length of tinned copper wire
to the top of each can and to the pad
directly underneath (see photos).
Fit the connectors (CON1-CON4),
the two 3-way jumper headers (JP1 &
JP2) and mode switch (S1) next. Take
care to ensure that these components
are seated all the way down on the PC
board surface before soldering them.
Note that it is not necessary to install both CON2 and CON3. If you’ll
be mounting the finished project in a
PC, install CON3. If you’ll be using
it stand-alone, install CON2 instead.
Install the two fuse clips next. Note
that the small retaining lug on each
clip must be positioned to the outer
(fuse end) side, otherwise fuse installation will be impossible.
The three ICs (IC1-IC3) and the
two LEDs (LED1 & LED2) should be
installed last of all. The orientation of
these devices is very important. Align
the “notched” end of the ICs (the pin
1 end) as shown in Fig.3.
If you’re building a freestanding
unit, you can also install the LEDs
now. The flat (cathode) sides should
siliconchip.com.au
Fig.9: this shot was taken just before we hit the “Write
All” button. We’ve selected the correct type of PIC, loaded
the .HEX file and double-checked the configuration bits.
Note that if the CP (code protect) bit is enabled, it will be
impossible to read or verify the PIC after programming.
face the smart card socket. If you intend fitting the board in a PC or other
enclosure, it’s best to leave the LEDs
out until you’ve prepared the front
panel and can gauge the required
lead length.
Testing
It’s a good idea to apply power and
perform a few quick checks before
inserting a smart card, so let’s do that
next.
Plug in your chosen power source
and switch on. No smoke? Good! Set
your multimeter to read volts and
measure between pins 7 & 14 of both
IC2 and IC3. Your meter should read
about 5.0V in both cases.
For the remaining tests, connect the
negative probe of your meter to any
handy ground point (say, the anode of
D5 or one of the crystal cases). Now
measure pin 2 of IC1 with the positive
probe. The reading should be about
8.7V or more. Now move to pin 6 of
IC1 - expect at least -7.8V here.
Next, measure the cathode (banded)
end of D3. If all is well, there should
be 15.6V or more at this point. Finally, measure at the cathode of ZD1.
Assuming that the shunt regulator is
doing its job, the Vpp voltage will be
pretty close to 13.0V.
Housing
For a freestanding unit, all you need
do is fit four small self-adhesive rubber
feet to the underside of the board.
Alternatively, the board can be insiliconchip.com.au
Fig.10: once the PIC has been successfully programmed,
select the 24C16 device from the drop-down menu. The
card’s EEPROM should then be fully accessible.
stalled in a spare drive bay in your PC.
The preferred method is to first mount
the board in a 3.5-inch to 5.25-inch
plastic disk drive adapter and then fit
this into a spare 5.25-inch drive bay,
as shown in the photos.
If your power supply lacks a spare
drive power connector, you can purchase a “Y” cable splitter from most
computer outlets (eg. Jaycar Cat. PL0750).
The serial port cable can be routed
out through any convenient exit point
at the rear of the case for connection
to a free serial port.
We cut down an old 5.25-inch drive
blanking plate to fill the hole in the
front of the adapter. To save time and
effort, you could also use a piece of
much thinner plastic or even cardboard for the job. You can photocopy
the front panel label in Fig.12 and use
it as a template for the hole and slot
positions.
Installing the software
Being compatible with several
popular serial port-connected programmers, your new board will work
with much of the freely available card
software on the Internet. We’ve selected “IC-Prog” for our demo, primarily
because it runs on all recent versions
of Windows (Win9x/Me and Windows
NT/2000/XP) and also because it can
program both the PIC and EEPROM
in Gold cards.
You can obtain the latest version
of IC-Prog from www.ic-prog.com
Fig.11: this
message will
appear if IC-Prog
can’t talk to the
PIC. Assuming
that the PIC has
been successfully programmed (with
the correct loader), it probably means
that you haven’t switched modes. It
might also mean that the crystal
oscillator either isn’t oscillating or is
set to 6MHz when it should be
3.58MHz. Also, make sure that the
positions of JP1 and JP2 match the
complementary settings on the
“Smartcard” tab.
In all, you’ll need to download three
files: the application (icprog105a.zip),
the driver for Windows NT/2000/XP
(icprog_driver.zip) and the help file
(icprog.chm). Note that the filenames
will change over time as IC-Prog is
improved and updated.
Unlike most Windows applications, IC-Prog is not self-installing,
so you’ll need to manually create a
folder to contain the files. We named
ours “C:\IC-Prog”. It’s then just a
matter of unzipping the first two files
into the new directory, and creating
a shortcut on your desktop (or Start
menu) to “icprog.exe”. The help file
(icprog.chm) should also be saved in
this new folder.
Installing the port driver
For Windows NT/2000/XP users,
the serial/parallel port driver should
be installed as the next step.
Launch IC-Prog (ignore any error
messages) and from the main menu
select Settings -> Options. Click on
July 2003 29
This view shows how the PC board is fitted to a standard 3.5-inch to 5.25-inch
drive mounting kit. We cut down an old 5.25-inch drive blanking plate to fill the
hole in the front of the adapter.
the Misc tab and from the list of displayed options, click on the “Enable
NT/2000/XP Driver” check box (do
not change any other settings on this
tab!). Follow the prompts to restart
your machine so that the driver can
be installed and started.
Note: if the port driver is not properly installed, you will get a “Privileged Instruction” error whenever ICProg attempts to access the serial port.
Before use, IC-Prog must be set up to
suit the programming hardware. Let’s
do that next.
Setting up IC-Prog
From the main menu, select Settings
-> Hardware to bring up the “Hardware
Settings” dialog (see Fig.5). Choose “JDM
Programmer” as the programmer type
and “Direct I/O” as the interface method.
You should also select the COM port that
you’ll be using with the programmer. No
other settings in this dialog should be
changed (do not check any of the “invert
signal” options!) at this stage.
Next, select Settings -> Options
and click on the Smartcard tab. From
the drop-down list, select the appropriate COM port. If your card is set
for Smartmouse compatibility (JP1
pins 2-3 shorted), you should select
the “Invert Reset” option. From the
remaining settings, choose “Multimac
2.14”, “16F84” and “3.58MHz”. Now
click on the OK button to save the
settings and close the dialog.
Finally, select Settings -> Smartcard
(Phoenix). A tick should now appear
against this option in the Settings
menu, indicating that smart card
programming mode is enabled (see
Fig.8).
Programming the PIC
If you’re an old hand at card programming, then you’ll probably have
all the necessary files ready to go. In
this case, IC-Prog includes a “Card
Wizard” feature to enable you to program your card in short order. However, much more flexibility is afforded
if we bypass the Wizard and perform
each task individually.
For blank cards, the first task is to
program an operating system (OS) into
the PIC micro. This operating system
will then enable us to access the oncard EEPROM. This is often referred to
as “through-PIC programming”.
The operating system can be any
generic one that provides full EEPROM access over a Phoenix/Smartmouse-type interface. Various versions
are freely available on the Internet and
are often called “loaders”, after the fact
that they’re sole purpose is to “load”
the EEPROM.
Not all loaders are created equal.
Look for one in Intel HEX file format
(.hex or .h8) that is Multimac 2.14
(or later) compatible and targeted for
the 16F84. We downloaded our card
OS from www.maxking.com/ZIPS/
rb7hex.zip
To program the loader into the PIC,
select the appropriate PIC device from
the drop-down list on the main menu.
For Gold cards, choose the PIC16F84A.
Next, select File -> Open File and
navigate to wherever you unzipped
the loader. Double-click on the file to
open it, and the contents will appear
in the main IC-Prog window.
Before you “torch” your card, double-check that the micro configuration
bits (displayed on the right side of the
main window) are set correctly. The
oscillator type should always be set to
“XT” for smart cards. For the 16F84(A),
the WDT & PWRT bits should be disabled (not checked) unless the loader
documentation indicates otherwise.
It’s also unlikely that you’ll want the
CP (Code Protect) bit enabled.
Make sure that the programmer is in
PIC programming mode (switch out)
and that the power is on. Now insert a
blank card (contacts facing down and
towards the slot) into the programmer.
You should feel it slip all the way home
Fig.12: photo-copy
this diagram and
use it as a drilling
& cutting template
for the drive bay
blanking plate.
30 Silicon Chip
siliconchip.com.au
with a slight click and the “Card In
Place” LED should light. OK – hold
your breath and click on the “Program
All” button on the toolbar.
If all goes well, the PIC will be programmed and then verified successfully. If the verify fails, try erasing the
PIC (click on the “Erase All” button)
and re-run the programming.
Programming the EEPROM
Once PIC programming completes
successfully, switch the programmer
to Phoenix/Smartmouse (normal)
mode (switch in). Now select the appropriate EEPROM device from the
drop-down list on the main menu. For
Gold cards, this is the 24C16 device.
At this point, you can read and/or
write to the 24C16 EEPROM inside
the card. You can read the contents
and edit them directly in the IC-Prog
window, or load and write whatever
data file you desire to the EEPROM.
Note: to be able to access the oncard EEPROM, you must have enabled
IC-Prog’s smart card programming
mode, as described under “Setting up
IC-Prog” above.
Preventing card damage
The smartcard socket specified for
this project uses “landing contact”
technology. This means that the socket
contacts do not touch the contacts on
the card until it is almost fully inserted.
The advantage of this method is that
there is little possibility of power and
ground being momentarily connected
to the wrong set of pins, as might occur
with wiping contacts. It also results in
less card wear.
However, to further minimise the
possibility of damage to the electronic
circuitry, it’s important to follow a few
simple rules during use. First, before
inserting or removing a card, the programming software should be running
(but not reading or programming, of
course!). This is necessary to ensure
that the serial port is in a known state
and that all the control lines are properly initialised.
Second, do not switch modes when
reading or programming is under way.
If you find you’ve inadvertently left
the mode switch in the wrong position
before initiating a read or write, then
simply let it complete (no damage will
occur) before switching over.
Programming other cards
Our descriptions have dealt exclusiliconchip.com.au
ELAN Audio
The Leading Australian Manufacturer
of Professional Broadcast Audio Equipment
2 Steel Court South Guildford
Western Australia 6055
Phone 08 9277 3500
Fax
08 9478 2266
email poulkirk<at>elan.com.au
www.elan.com.au
RMA-02
Studio Quality
High Power
Stereo Monitor
Amplifier
Designed for Professional Audio Monitoring during Recording and Mastering Sessions
The Perfect Power Amplifier for the 'Ultimate' Home Stereo System
For Details and Price of the RMA-02 and other Products, Please contact Elan Audio
sively with the Gold-type wafer cards.
However, this project is capable of
reading and programming most PICbased cards. It has been successfully
tested with the Emerald (PIC16F628
& 24LC64) and Silver (PIC16F877 &
24LC64) cards.
Both of these cards can be programmed with IC-Prog (don’t use
the Card Wizard function). However,
separate loader programs are required
for each of the cards, as the PIC16F84
version (used with the Gold card) will
not work with these newer devices.
We’re yet to find a source for PIC
16F628 & PIC16F877 loaders.
Note: this project will not work with
any Atmel-based cards, such as the
“Fun” card.
Now what?
Now that you can read and write a
smart card, what do you do with it?
We found several simple applications, including door access control,
identity card, time clocking and PC
security at www.maxking.co.uk You
can download these free of charge but
note that they are only demos and
some can be a little “buggy”!
If you can program in Visual Basic
or C/C++, then you’ll find a well-doc-
umented API DLL for Windows at
www.gis.co.uk/p75_dl.htm This
library gives full access to the Smart
mouse interface, considerably easing
the programming task.
Note that the site lists files for a
number of different card readers. This
project is compatible with the SM1RS232 model.
The files of interest are named “sm12dll.exe” and “usref3_0.pdf”.
More information
As usual, information on the ISO7816 smart card standard abounds on
the Internet. Point your browser to www.
google.com and search for “ISO7816”.
Microsoft and others are involved
in defining standards for smart cards
connected to PCs. Check out http://
msdn.microsoft.com/library/en-us/
dnscard/html/msdn_smart_card.asp
and www.pcscworkgroup.com for
details.
We’ve yet to find applications of
a non-commercial nature that have
exploited the full potential of these
useful little devices. Sadly, much of
the information on the Internet is related to card “hacking”. Perhaps you
could be one of the first enthusiasts to
SC
put them to real use!
Project Reprints – Limited Back Issues –Limited One-Shots
If you’re looking for a project from ELECTRONICS AUSTRALIA, you’ll find it at SILICON CHIP! We can now
offer reprints of all projects which have appeared in Electronics Australia, EAT, Electronics Today,
ETI or Radio, TV & Hobbies. First search the EA website indexes for the project you want and then
call, fax or email us with the details and your credit card details. Reprint cost is $8.80 per article
(ie, 2-part projects cost $17.60). SILICON CHIP subscribers receive a 10% discount.
We also have limited numbers of EA back issues and special publications. Call for details!
visit www.siliconchip.com.au or www.electronicsaustralia.com.au
July 2003 31
|