Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Make The Smartpic Serial Programmer: Feature Article

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

and no parity.

The programmer acts as


a DCE slave device that communi-
FEATURE cates with the computer acting as a
DTE device. 16CxxPRG.EXE is a mas-

ARTICLE ter program for IBM-compatible PCs.


See the 16CxxPRG model A users
manual for details.
Duane Perkins
SMART FEATURES
The programmer contains an em-

Make the SmartPIC bedded PIC16C71 microcontroller (a


PIC16C61 or PIC16C84 will also
work) that is programmed to commu-

Serial Programmer nicate with a master program via


asynchronous serial I/O at 9600 bps.
Most of the smart features are in-
voked by the way it communicates
with the master program, including
hardware handshaking. The master
program must act on these signals in

When picking a PIC


p IC microcontroll-
ers have become
popular because of
an appropriate manner in order to
realize their full potential.
When the programmer is connected
to an active serial port, it is held in a
reset state until DTR is asserted.
their speed, versatility, Once DTR is asserted, it waits for the
programmer, you may and low cost. There are now so many computer to assert RTS. Once RTS is
different types that its becoming hard asserted, it asserts CTS and waits for
find that there are as to keep track of them, and new types a command. When a command is
are being offered all the time. One received, it returns a transmission
many choices as thing they all have in common is the error code if a transmission error oc-
there are PICs. The requirement for a programmer be- curred, or an invalid command error
cause program and configuration code if it does not recognize the com-
more versatile it is, memory is contained in the chip. mand. If the command is recognized,
Many PIC programmers on the mar- it either returns a response immedi-
the more money you ket are limited with regards to the ately and waits for further input, or
have to lay out, right? types they will program. The less performs the function specified by the
costly the programmer, the less versa- command and returns a response. The
Not if you follow tile it is. master program can abort any func-
The PIC16Cxx programmer de- tion at any time by dropping DTR.
Duanes plan. He scribed here is a smart programmer One command tells the program-
gives you more bang for any serial programmed PIC with a mer to identify itself. It responds with
14-bit instruction word, including the an ASCII A, which is its model
for your buck with his PIC14000 with an adapter for the designation. The master program
target socket (not PIC16C5x or should always check to be sure it is
new serial program- PIC17Cxx devices). It requires a mas- communicating with a model A pro-
mer. ter program running on any computer grammer, because a later model
with an RS-232 serial port configured (which could be developed) will prob-
for 9600 bps, 8-bit word, one stop bit, ably not work correctly.

www.circuitcellar.com/online CIRCUIT CELLAR ONLINE February 2000 1


Figure 1The upper half
of the schematic is the
digital circuit. The lower
half is the voltage control
circuit.

The programmer has two sockets program can set the level high (5.5 V) the programming of user program
for target devices. When told to accept or low (4.5 V) for reading. The level is memory when all remaining words
user program and EEPROM data size automatically set to 5.2 V when pro- are to remain blank, saving the time
parameters, the programmer tests to gramming in conformance with Mi- that would otherwise be wasted. The
see if a device is in either target crochip specifications that require VDD master program should verify the
socket. If no device or two devices are to be in the range of 4.75 to 5.25 V. device after programming to be sure
found, the programmer responds with The VDD levels may deviate slightly that there are no nonblank words
an error code. from those nominal voltages but will where there should be none. When
VPP will be applied to the target be within the limits of Microchips programming an EEPROM device, all
sockets only when a command is minimum and maximum specifica- of the program memory is pro-
received that tells the programmer to tions. grammed to assure that unused words
read or program a target device. VPP Hardware handshaking coordinates are erased. EEPROM data memory (if
cannot be applied unless VDD is ap- the computer and the programmer any) is always fully programmed and
plied. VDD will be applied prior to VPP during transfer of data in either direc- verified.
and when testing for devices in the tion. The programmer utilizes half- A device type code can be pro-
target sockets. duplex, interrupt-driven serial I/O grammed into configuration memory
When commanded to read or pro- with a one-character buffer and will at 2008h. This word can be left blank
gram a target device, no voltages are accept a character from the computer by programming it as 3FFFh. When a
applied to the target sockets until the only when it has asserted CTS. The device is read, the configuration
master program drops RTS. No volt- programmer waits until RTS is as- memory can be read first, including
ages are applied to the target sockets serted (up to 2.3 s) before sending a the device type code. The master
when the programmer is powered up, character. There are no unnecessary program can then establish the device
even if it is not connected. It is safe to delays while the computer or pro- parameters based on the type code
put a device into either or both sock- grammer is marking time to give the before reading user program memory.
ets at any time. Note: VDD is actually other time to perform its task. The programmer can read or pro-
at about 0.5 V when not applied. A When programming a non- gram up to 31.75 KB of words of user
target device will not be harmed by EEPROM device, words expected to program memory. The programmer
this low voltage and it can be safely remain blank in either the user pro- can also read or program up to 510
grounded. gram memory or configuration bytes of EEPROM data memory even
There are three possible levels for memory are not programmed or veri- if the program memory is not
VDD4.5, 5.2, or 5.5 V. The master fied. The master program can abort EEPROM. In the event that Microchip

2 February 2000 CIRCUIT CELLAR ONLINE www.circuitcellar.com/online


develops such a device, the program- plied at J1. A bridge rectifier converts of Q5. There is a drop of about 0.6 V
mer can handle it. The programmer this to 17 VDC, which is filtered by across the base-emitter junction of Q5
can read and program a device ID at C1. VR1 supplies 5 V to U1, U2, and and also across D14, which holds the
2000h to 2003h. The master program other parts as shown. VR2 has three inverting inputs of U3 at approxi-
should limit the ID to four ASCII 1N914 diodes connected in series mately the voltage at the base of Q5,
bytes no greater than 7Fh. All higher- between its ground terminal and thus applying 100% negative feed-
order bits of the word should be 1s. ground, which are supplied with cur- back. C6, C15, and C16 prevent oscil-
rent from R16. The output of this 12- lation.
COMMANDS AND RESPONSE V regulator is at 13.8 V because its When VDD is applied, RA0 is low
CODES ground terminal is held at 1.8 V above and Q3 is cut off. When RB4 is low,
The command codes are all ASCII ground. VR2 supplies U3, Q5, K1, and Q2 is cut off and the VDD level is high.
decimal digits (0-9). They are listed in other parts as shown. If RB7 is low, Q1 is cut off and K1 is
Table 1 along with all possible re- U3 sets the VDD level for the target not energized. If RB7 is high, Q1 con-
sponses. The response codes are also sockets by establishing the voltage at ducts, energizing K1, which in turn
ASCII decimal digits (0-6) with the the base of Q5. The actual VDD level shorts D6. The output of U3B will be
exception of the model designation, may deviate slightly from the nomi- higher than the output of U3A, thus
which is an ASCII A. A transmis- nal voltages that are stated in Figure D13 will not conduct. Due to negative
sion error will always result in a re- 1. U3A has a reference voltage of 5 V feedback, U3B will drive the base of
sponse of error code 4. An invalid at its noninverting pin. U3B has a Q5 to a voltage approximately equal
command (not 0-9) will result in a reference voltage of 6.05 V (the zener to the reference voltage at its
response of error code 3. voltage of D5 at low current) if K1 is noninverting input and the emitter of
energized, or 5.8 V if K1 is not ener- Q5 will be about 0.6 V lower (5.2 or
gized. 5.5 V).
THE ELECTRONICS The outputs of U3 are applied to When RB4 is high, Q2 conducts. R9
Figure 1 shows the schematic dia- the base of Q5 through D13, D15, and pulls the noninverting input of U3B
gram for the programmer. External R12. Whichever output is higher will below 5 V, with the result being that
power of 12.6 VAC or 18 VDC is sup- determine the VDD level at the emitter its output is below the output of U3A

Command Function Description

0 Identify model Response is A.


1 Configure The programmer expects two bytes to follow when it asserts CTS. After these have been received, the
programmer sends 0 if one target device is found, 5 if no target device is found, or 6 if two target
devices are found. The first byte sent after the command is the high-order byte of the program
memory size. The high-order bit = 1 if the device has EEPROM program memory. The second byte
is one-half the EEPROM data memory size (zero if none).

2 Set VDD high Response is 0.


3 Set VDD low Response is 0.
4 Perform blank check The programmer reads all user program memory and configuration memory from 2000h to 2008h until
a nonblank work is found. Possible responses are:
0, all program memory blank
1, user program memory not blank
2, configuration memory not blank
5 Read user program The programmer sends the words read, high-order byte first, and quits when the count is equal to
memory the user program memory size.
6 Read configuration The programmer sends the words read from 2000h to 2008h, high-order byte first.
memory
7 Program the target The programmer responds with 0, then expects each word to be received, high-order bit first,
device when it asserts CTS. If the high-order byte is 1 and the device does not have EEPROM program
memory, programming of user program memory is aborted. After the count reaches the user pro-
gram memory size or programming of user program memory is aborted, the programmer expects to
receive nine more bytes for configuration memory. The programmer sends a response after each
word. In the event of an error, programming is aborted.
The possible responses are:
0, word programmed and verified
1, programming error
8 Read EEPROM The programmer sends the bytes read and quits when the count is Equal to the EEPROM data
data memory memory size.
9 Program EEPROM The programmer responds with 0, then expects each byte to be received when it asserts CTS.
data memory The programmer sends a response after each byte. In the event of an error, programming is aborted.
The possible responses are:
0, byte programmed and verified
1, programming error

Table 1All command and response codes are ASCII.

www.circuitcellar.com/online CIRCUIT CELLAR ONLINE February 2000 3


Table 2Connections For testing purposes, the 18-pin target
Ground 1**2 Polarizing pin to the target PIC are
VDD 3**4 VDD socket should be soldered in. C19 and
shown by the pinout of
RB7 5**6 VPP J3. C20 are mounted on the solder side
RB6 7**8 OSC1 and directly to the pins of the target
OSC2 on 18-pin socket 9 * * 10 OSC2 on 40-pin socket
sockets. Solder over unused holes that
might otherwise result in a break in
the trace.
and D15 does not conduct. Negative target sockets and the data and clock Be sure all solder joints are good
feedback forces the base of Q5 to signals required to read or program a and that there are no solder bridges
about 5.1 V and the emitter of Q5 to PIC16Cxx. Via D8, D9, and D10, it (solder joints are not always as good
4.5 V. When RA0 is high, Q3 con- determines which sockets contain a as they look). Cleaning off the rosin
ducts, pulling the base of Q5 to less target device. after soldering is a nice touch and aids
than 0.5 V, thus cutting off Q5. Cur- VDD is applied, followed by a high visual inspection. Acetone works
rent through R11 and D14 is shunted on OSC1 from RA2 through D10. RB2 well, but dont immerse the board.
through D7, holding VDD to about 0.5 V. and RB3 are inputs with weak pull-
VPP is controlled by Q6. When both ups enabled. If either is pulled low TESTING
RA0 and RA1 are low, Q4 is cut off. through D8 or D9, a device is in the When making the following tests,
13.8 V is applied to the base of Q6 respective socket. If the device is remove power before changing the
through R17, resulting in 13.2 V at configured for a RC oscillator (which test setup. With no ICs in the sockets,
the emitter. When either RA0 or RA1 is the case for a blank device), OSC2 apply 12.6 VAC or 18 VDC to J1. Test
is high, Q4 conducts, cutting off Q6. will be low. If the device is not blank for 17 V across C1, 13.8 V at pin 8 of
R18 limits VPP current to prevent and is not configured for a RC oscilla- U3, 5.8 V at pin 3 of U3, and 5 V at
target device latch-up. tor, an internal inverter outputs the pins 4 and 14 of U1, pin 16 of U2, and
U2 converts the TTL-level signals inverse of OSC1 on OSC2, pulling it pin 5 of U3. You should find about 0.5
from U1 to RS-232 levels for the serial low. After reading or programming a V at pin 14 of the 18-pin target socket
port lines. The positive voltage gener- target device, VPP is dropped, then and pins 11 and 32 of the 40-pin target
ated by the MAX232 is connected after a delay of about 100 ms, to allow socket. Pin 4 of the 18-pin target
directly to the DSR line to signal that C18 to discharge, VDD is dropped. socket and pins 12 and 31 of the 40-
the programmer is powered. DTR is A 4-MHz crystal or ceramic reso- pin target socket should be at ground
connected to DCD and, via R1 and nator can be used. If a ceramic resona- potential (not floating).
D12, to the NOT-MLCR pin of U1. tor with integral capacitors is used, do Place jumper wires between pins 5
When DTR is asserted, D12 does not use C7 and C8. The frequency and 17, and between pins 14 and 18 of
not conduct and 5 V is applied to must be 4 MHz to provide correct the U1 socket. Put a TL082 in the U3
NOT-MCLR by R3, allowing the timing of various pulses and delays socket and test for 5.2 V at pin 14 of
PIC16C71 to operate. When DTR is (assuming the PIC16C71 is pro- the 18-pin target socket and pins 11
dropped, it is negative and sinks cur- grammed with 16CxxPRG.HEX). and 32 of the 40-pin target socket. Pin
rent through R1, D12, and R3, drop- 4 of the 18-pin target socket and pins
ping the voltage on NOT-MCLR to CONSTRUCTION 12 and 31 of the 40-pin target socket
ground level, thus holding the Additional board layout figures can should remain at ground potential.
PIC16C71 in a reset state. D11 as- be downloaded. After etching and Remove the jumper wire from pins 14
sures that the voltage on NOT-MCLR drilling the main board (a #60 drill bit and 18. Pin 4 of the 18-pin target
cannot be negative by holding its is a good choice), solder in all the socket and pins 12 and 31 of the 40-
cathode and that of D12 at 0.6 V be- jumpers shown as solid lines on the pin target socket should now measure
low ground level. parts placement diagram. Use bare 13.2 V. Place a jumper wire between
Because the programmer is wired tinned copper wire, being sure to pins 14 and 13 of U1. VDD, measured
DCE, it sees TX as its data input line, stretch each one tight and straight to anywhere convenient, should be 5.5
RX as its data output line, RTS as a assure that adjacent jumpers cannot V. Change the jumper to pins 14 and
control input, and CTS as a control touch. Solder in all remaining compo- 10. VDD should now measure 4.5 V.
output. The master program can de- nents, starting with the smallest Note: slight variances from the VDD
termine if the programmer is con- (D10-D20) and proceed with resistors levels stated above are acceptable, but
nected, powered or not, by testing to and the remaining diodes. Continue VDD should not exceed 5.25 V when
see if DCD follows DTR. The master with the remaining components by programming.
program can determine if the pro- size, leaving the largest for last. Use Put a MAX232 in the U2 socket.
grammer is active by checking to see sockets for U1, U2, and U3. Pin 6 of J2 (DSR) should measure
if CTS follows RTS. If you plan to use an enclosure, use about +10 V. Pins 3 (RX) and 5 (CTS)
U1 acts as a slave that responds to a 10-pin header (J3) in place of the 40- should measure about 10 V. Pin 8
valid commands from the computer. pin target socket and solder in jump- (DCD) and pin 20 (DTR) should mea-
It controls the voltages applied to the ers where shown by the dashed lines. sure about 4.4 V. Pin 7 should be at

4 February 2000 CIRCUIT CELLAR ONLINE www.circuitcellar.com/online


ground potential (not floating). parts list is available for downloading
Put a programmed PIC16C71 in the so you can check for a source. The IN CONCLUSION
U1 socket. Pin 4 should measure 5 V, small board (shown in the The design of this programmer
and pin 15 should measure about 2.5 V downloadable figures) will fit in the provides the most functionality for
(indicating oscillation). Connect the bezel supplied with the adapter kit. the least cost and conforms to Micro-
programmer to a PC with an RS-232 The cutout for a floppy drive will chip specifications within the limits
cable (the cable must have TX, RX, have to be enlarged to accommodate of its intended use. The VDD levels are
RTS, CTS, DSR, GND, DCD, and the ZIF sockets. Cut a piece of sheet not precisely controlled and are lim-
DTR lines). Run a terminal emulator metal to serve as a base for the pro- ited in range, but satisfy the require-
program on the PC. Set up for 9600 grammer board and a means of attach- ments for a developmental
bps, 8-bit word, one stop bit, and no ing it to the floppy drive adapter base programmer that will not be used for
parity for the port in use. The termi- that fits into the enclosure. The sheet production programming where more
nal emulation program must set the should measure 5.2 5.4. Bend stringent demands must be met. Us-
IRQ in accordance with the actual down the tabs on the adapter base so ers experimenting with PIC16Cxx
hardware configuration. DTR and RTS the sheet will lie flat on them, leaving microcontrollers should find it more
must be asserted. enough space for the heads of sheet than merely adequate.
Press the 0 key. The programmer metal screws below the tabs and Microchip recommends that the
should respond with A. Press 2 then about 1.25 of headroom above the window of an EPROM device be cov-
3. The programmer should respond tabs. ered during reading or programming.
with 0 after each keypress. Press 1 Place the sheet on the tabs leaving If you experience problems, especially
three times in quick succession. The adequate space in front of the enclo- with a 40-pin device such as a
programmer should respond with 5 sure for a connector cable, then mark PIC16C74, use a piece of masking
after the last keypress. Press 4, 5, 6, and drill the sheet for four sheet tape backed with a small piece of
and 7. The programmer should not metal screws to attach it, using four aluminum foil. However, later de-
respond. Press any other keys. The of the tabs. Align the programmer vices with the A suffix (i.e.,
programmer should respond with 3 board squarely over the sheet, then PIC16C74A) do not have this prob-
after each keypress. If all these results mark and drill the sheet for 6-32 ma- lem. I
are obtained, the programmer is basi- chine screws. Use spacers between
cally working. the board and the sheet, being sure to Duane M. Perkins is a self-taught
allow enough distance so the sheet engineer who has made computers
RUNNING 16CXXPRG metal screws will not touch the and electronics his avocation since
Now is the time for the final test- board. retiring in 1980. In recent years he
ing. Type FINDPORT A at the com- Use a 10-pin dual-inline header has specialized in PIC
mand line. If the programmer is connector and ribbon cable to provide microcontrollers. You may reach him
connected and powered, the port it is connections between the programmer at (717) 964-3536 or at
connected to should be found and board and the board with the ZIF dmperkins@compuserve.com.
displayed. 16CxxPRG.PRT will be sockets. Solder the ribbon cable leads
created with one line containing directly to the pads on the solder side
X:YYY COMZ, where X is the IRQ, of the ZIF socket board. You can de- SOURCES
YYY is the port hex address, and Z is vise some means of attaching the
Microchip Technology, Inc.
the COM port number (14). Note cable to the board other than the sol-
(888) 628-6247
that if you are using a port not recog- der connections (even just a dab of
(480) 786-7200
nized by DOS (other than 3F8, 2F8, epoxy cement will do).
Fax: (480) 899-9210
3E8, or 2E8), or an IRQ other than 2, The ZIF socket board can be at-
www.microchip.com
3, 4, or 5, you must create tached to the bezel with 6-32 hard-
16CxxPRG.PRT with the parameters ware or, if you like, a mini toggle
for the port. Now run 16CxxPRG. The switch and LED holder can be used to
display should be as described in the provide for power switching and a
16CxxPRG users manual, and you are power-on indicator. Route the leads to
ready to start programming the switch, well away from the ZIF
PIC16Cxxs. sockets. R19 and J4 provide a handy
current source for an LED. A Radio
HOUSING THE PROGRAMMER Shack 273-1365 transformer fits
For day-in-day-out use, it is nice to nicely in the rear end of the enclosure.
have the programmer in an enclosure. The pinout of the header is shown in
Circuit Cellar, the Magazine for Computer Applications.
A 5.25 floppy drive enclosure is emi- Table 2. Cut off pin 2 and insert it in Reprinted by permission. For subscription information,
nently suitable. You will also need a the header connector so that it cannot call (860) 875-2199, subscribe@circuitcellar.com or
3.5 floppy drive adapter kit. The be connected incorrectly. www.circuitcellar.com/subscribe.htm.

www.circuitcellar.com/online CIRCUIT CELLAR ONLINE February 2000 5

You might also like