TOPIC: A System to Try Out PIC Microcontrollers
Electrical Engineering Labs
School of Engineering
Manchester M13 9PL
Copyright (C) 1996 David Tait
8th September 1996 (preliminary)
The TOPIC system is a very convenient way to learn about the Microchip
PIC16C84 microcontroller. TOPIC is a combination of a small circuit board that connects to
the printer port of an IBM compatible PC and a program to control the board. The hardware
includes both a PIC16C84 microcontroller development circuit and an on-board programmer.
The associated software downloads programs to the PIC16C84 in the form of Microchip hex
files (either INHX8M or INHX16 format) and controls the execution of the PIC.
Alternatively the TOPIC board can be used as a standalone PIC16C84 programmer or, by not
including the programmer
components, a standalone PIC development circuit.
The programmer reserves two of the PIC's I/O pins (RB6 and RB7) and these are unavailable for general purpose use. However, if the TOPIC board is disconnected from the target circuitry during programming, and disconnected from the PC while running, all I/O pins are available.
Despite the loss of two I/O pins, running programs while the board is still attached to the PC offers the most convenient mode of operation. The I/O pins are not wasted because when the board is connected to the printer port it is possible to use RB6 and RB7 to communicate with the
PC as an aid to debugging.
The schematic for the TOPIC hardware is provided in the Windows Paintbrush viewable file TOPIC.PCX. If you don't use Windows and need a DOS-based utility to view the files then you might consider the PICEM package by John Bridges - look for PICEM27.ZIP on any SimTel site. The files COPPER.PCX and LAYOUT.PCX give details of a printed circuit board design for the TOPIC hardware (The schematic shows a crystal oscillator setup but the board can accommodate crystal, ceramic resonator or RC oscillator components). All the PCX files have a resolution of 300 dots per inch (dpi) and should give good quality artwork on most printers. All the components to populate the board are available in the UK from Maplin Electronics.
The software is supplied as a pre-compiled executable file (TOPIC.EXE) and as C source (in SRC.ZIP). The TOPIC program expects a string of switches (introduced by - or /) and single filename. TOPIC is compatible with the __CONFIG, __IDLOCS and DE directives of Microchip's MPASM assembler; this means that using TOPIC to download a program can
be as simple as:
TOPIC PROGRAM.HEX where PROGRAM.HEX includes both the program and the configuration information. It is possible to override (or specify) configuration information on the command line using one or more of the characters from the set (upper-case and lower-case letters are equivalent):
c Enable code protection
p Enable power-up timer
w Enable watchdog
l LP oscillator
x XT oscillator
h HS oscillator
r RC oscillator
TOPIC -PRX PROGRAM.HEX programs the PIC with power-up timer, watchdog and XT (i.e. crystal) oscillator enabled. Other command line switches include:
g Go. Lets the PIC run (no file argument needed).
d Dump. Dumps the PIC contents to the specified file.
e Erase. Erases the PIC (no file argument needed).
v Verify-only. Verifies the PIC against the specified file contents.
Running TOPIC with no arguments pulls the PIC reset line low. The Following batch file can be used to apply a short reset pulse:
TOPIC > NUL
TOPIC -G > NUL
You can erase, program and run with a single command such as:
TOPIC -EG PROGRAM.HEX
The behaviour of the TOPIC system can be changed by some environment variables:
PPLPT=nn The LPT port to use (default nn=1). Can be 1, 2 or 3.
PPDELAY=nn Adds a delay of nn*0.83 microseconds to printer port accesses (default nn=6). Useful for fast PCs. The valid range of nn is 0 to 127.
PPDUMP=nn If nn=16 files are dumped in INHX16 format (default is INHX8M).
It's probably best if the appropriate commands are included in AUTOEXEC.BAT. For example to eliminate the printer port delays and tell TOPIC to use LPT2 use:
The Files WALK.ASM and WALK.HEX are the source code and associated hex file for a simple test program you can use to exercise the TOPIC board. See WALK.ASM for details.
The TOPIC hardware consists of a simple serial mode programmer combined
with the minimum number of components to support PIC operation. The board connects to the
parallel port of an IBM compatible PC via six wires:
TOPIC PL2 PC printer port
pin 1 INIT pin 16
pin 3 D0 pin 2
pin 5 STROBE pin 1
pin 7 AUTOF pin 14
pin 9 SEL/BUSY pins 11 & 17
pins 2,4,6,8,10 GND pins 18-25
I use a short length of ribbon cable with a 10-way IDC plug on one end and a 25-way female D-connector on the other to connect the TOPIC board to a standard printer cable.
PIC pins RB6 and RB7 are used for serial mode programming and are directly connected to the PC via resistors R1 and R2. The resistors are there to protect the PC port drivers and ensure no harm will result if the PIC enables RB6 and RB7 as outputs when it runs. Unlike most directly connected PIC programmers (for example, Mark Cox's BLOWPIC and Derren Crome's programmer described in EPE) TOPIC can also read the PIC contents. Two other printer port pins are used for this purpose: when RB7 is used as an input to the PIC the anode of D4 is
pulled to ground by the SEL open collector driver; when RB7 must be read SEL is turned off and the anode of D4 is thereby raised to +5V via the pullup resistors in the PC; now RB7 can pull the cathode of D4 low and hence also pull the BUSY input low. This may sound cumbersome
but works rather better than the alternatives I tried.
Except during programming the LM317L is set to produce about 1.2V and thus due to the diode D2 the /MCLR pin is held at roughly 5V or 0V depending on the state of the transistor switch Q2. To switch on the programming voltage both Q1 and Q2 are turned off. The programming
voltage should be set to about 13.5V by R7 and R8 and using 2% tolerance resistors for these components is best. If you use 10% tolerance resistors you may need to select R7 to make sure the voltage doesn't exceed 14V. When the the PC is not connected the bias components ensure that Q1 is on and Q2 is off resulting in /MCLR being held at 5V; in this state the
PIC can be reset by power-cycling. Note, an open-collector driver (that guarantees 0V output) rather than one of the data outputs (that doesn't) must be used to control Q1.
The TOPIC board can be used as a standalone programmer as it is but if that's all it must do it's possible to save a few components. For example you can remove R4, R5, Q1, R13, D5, D2 (replace with a wire link), X1, C6, C7, R9, D3 and PL3. R11 and R12 are only there to
reduce dissipation in the 78L05 and in programmer only mode they can be replaced with a wire link. The result is probably the least complicated of all printer port programmer designs (not as simple as the serial port types though). One problem with this setup is that the PIC must be inserted into a "hot" socket (i.e. +5V is connected) but that's how some commercial programmers work too. Don't use the /G switch with the TOPIC software when Q1 is not fitted.
The TOPIC board can be used as a simple (if large) PIC16C84 project board by removing R1-R8, R10, Q1-Q2, U2, C4, R13, D2, D4-D5 and PL2.
Although RB6 and RB7 can't be used as general purpose I/O when the PC is connected that doesn't mean they can't be used at all; you need to design your application so that the circuitry that attaches to these pins will not interfere with the programming process. Here is what the circuit
looks like on a typical PC:
_____ open collector _____
PC internal 4k7 port pin 1K RB6 or RB7
The 4.7k resistor is in the PC. Thus the TOPIC board can pull RB6 (or RB7)
to 5V via roughly 6k or pull it to ground via 1k. External circuitry can be added provided
that RB6 (or RB7) can still be pulled below 1V and above 4V and this means it must present
a load of no more than 25K or so. If you have an existing PIC target board that meets this
specification then the TOPIC board (with it's own PIC unplugged) can be used as an
in-crcuit programmer for that target. It is a fiction
that in-circuit programming can be applied without considering the consequences; that goes for hardware like the AN589 circuit just as much as it does for the TOPIC board.
I have found that I can leave the TOPIC hardware connected to the printer port while the PC is switched on and also during CTRL-ALT-DEL reboot cycles without problems. However it is prudent to disconnect the board or its power connection when the PC is switched off if you
want to avoid trashing the PIC contents.
13th September 1996
LPT Port Assumptions for TOPIC
This short file describes the assumptions made about the printer port (LPT) hardware used to control the TOPIC programmer. It seems that these assumptions may not be correct for some PCs. In particular new PCs equipped with enhanced ports as defined in the recent IEEE 1284
standard. These ports should be capable of working in standard printer port mode - "compatibility mode" - but it appears some are more compatible than others. Unfortunately, where I assume a
particular printer line is controlled by an open-collector (O/C) driver it seems some ports use "totem-pole" drivers instead (the former can only sink current but the latter can both sink and source current). The differences mean that the TOPIC hardware may not work on these systems without modification.
It is assumed that the INIT line is controlled by an open- collector driver. This is not too critical but if INIT is actually controlled by a totem-pole output it may be necessary to reduce R4 from 1k to 470 ohms or even lower. Just check that the output of the LM317L reaches +13.5V when INIT is low.
It is assumed that the STROBE and AUTOF lines are controlled by open-collector drivers. This is handy because they drive RB6 and RB7 which are Schmitt trigger inputs in programming mode; the
O/C drivers are better able to reach the input high threshold of nominally 4V. If the O/C assumption is wrong here it's unlikely to be a problem as new ports will probably have an adequate high output voltage (that's because they are usually implemented using CMOS VLSI). I don't use the LPT data lines (totem-pole outputs) to drive RB6 and RB7 as doing so might mean TOPIC will not work with an old port based on traditional TTL.
It is assumed that SEL (actually SELECTIN) is controlled by an open-collector driver. This line has two functions. It is used to check whether the programmer is plugged into the PC: As SEL is
connected to the BUSY input on the TOPIC board the line can be toggled and the effect on BUSY monitored and thus used to verify the programmer is attached. The second function is more subtle and is explained along with the description of the next assumption. I'll leave a discussion of the consequences of SEL really being a totem-pole output until later.
It is assumed that the BUSY input has an internal pull-up resistor. This assumption is necessary because BUSY is connected to RB7 via a diode and RB7 can only pull BUSY low. You might ask why the diode is required - if it wasn't fitted there would be no need to assume BUSY has a pull-up. OK, let's assume there is no diode between BUSY and RB7. When reading from the PIC everything is fine but consider what happens when writing to the PIC. I have already said that I assume AUTOF has an O/C driver and, to prevent damage when the PIC is running with RB7 enabled as an output, it is connected to RB7 via a 1k resistor. When AUTOF is high RB7 is
connected to +5V via the combination of the 1k resistor and the AUTOF pull-up and it is also connected to +5V via the BUSY pull-up; this pretty well guarantees RB7 is high. Now, when AUTOF is low RB7 is grounded via the 1k resistor but it is still connected to +5V via the BUSY pull-up. This means the voltage at RB7 depends on the value of the BUSY pull-up - if the pull-up is 4.7k the voltage will be around 0.9V and will be even greater if the pull-up has a lower resistance. This value is too close to the low threshold for comfort. By adding the diode the voltage drops slightly but could still be too high. However, remember SEL is alsoconnected to BUSY; by programming SEL low the influence of the BUSY pull-up is removed (this is the real reason for using the diode: without it programming SEL low would simply short RB7 to ground).
When reading from the PIC the SEL line is pulled high. But consider what happens if SEL really has a totem-pole output. In this case SEL will "fight" with RB7 when trying to read from the PIC. It is likely that the PIC will win (it has a fairly beefy output driver) but this is not a good situation. To get around this SEL can be made into a pseudo O/C driver by adding another diode; the diode replaces the SEL/BUSY short with the cathode connected to SEL and the anode to BUSY:
SEL ------------+ +------------ RB7
new diode / \ / \ existing diode
BUSY ------------+ ---------+
Although I assume BUSY has a pull-up it doesn't really matter if it doesn't because, provided it is O/C, SEL will. However if the diode is added as described above then BUSY _must_ have a pull-up. If it doesn't, a resistor (say 4.7k) from BUSY to +5V should be fitted to the TOPIC board.
If the TOPIC board doesn't work with your LPT port try: 1) changing R4 from 1k to 470 ohms; 2) adding a diode between SEL and BUSY. If it still doesn't work add a 4.7k resistor from BUSY to +5V. If it still doesn't work let me know (tell me you've read this document).
Thanks to Kalle Reunanen for his comments about the value of R4. Thanks to Bob Parker for telling me about the "extra diode" fix.
I have successfully assembled the TOPIC hardware which is conceived by David Tait . It is simple and does the job of programming and Project at the same time. The project is ready and also tested.