Silicon ChipPortable PIC Programmer - September 2003 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Internet newsgroups can be a mixed blessing
  4. Weblink
  5. Feature: Robots Wars: The Tech Sport Of The New Millenium by Brett Paulin
  6. Project: Very Bright., Very Cheap Krypton Bike Light by Julian Edgar
  7. Project: Portable PIC Programmer by Peter Smith
  8. Project: Current Clamp Meter Adaptor For DMMs by John Clarke
  9. Project: The PICAXE, Pt.8: A Datalogger & Sending It To Sleep by Stan Swan
  10. Feature: New Technologies In Automotive Lighting by Julian Edgar
  11. Product Showcase
  12. Project: Digital Instrument Display For Cars, Pt.2 by John Clarke
  13. Vintage Radio: Vibrators: the death knell of expensive dry batteries; Pt.1 by Rodney Champness
  14. Back Issues
  15. Notes & Errata
  16. Market Centre
  17. Advertising Index
  18. Book Store
  19. Outer Back Cover

This is only a preview of the September 2003 issue of Silicon Chip.

You can view 24 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 "Portable PIC Programmer":
  • Portable PIC Programmer PCB pattern (PDF download) [07109031] (Free)
Items relevant to "Current Clamp Meter Adaptor For DMMs":
  • Current Clamp Meter Adaptor PCB pattern (PDF download) [04109031] (Free)
  • Panel artwork for the Current Clamp Meter Adaptor (PDF download) (Free)
Articles in this series:
  • PICAXE: The New Millennium 555? (February 2003)
  • PICAXE: The New Millennium 555? (February 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE: Pt.2: A Shop Door Minder (March 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.3: Heartbeat Simulator (April 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.4: Motor Controller (May 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.5: A Chookhouse Door Controller (June 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.6: Data Communications (July 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.7: Get That Clever Code Purring (August 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: A Datalogger & Sending It To Sleep (September 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.8: The 18X Series (November 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)
  • The PICAXE, Pt.9: Keyboards 101 (December 2003)
Items relevant to "Digital Instrument Display For Cars, Pt.2":
  • PIC16F84A-20(I)/P programmed for the Digital Instrument Display for Cars [INSTRUM.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC16F84 firmware for the Digital Instrument Display for Cars [INSTRUM.HEX] (Software, Free)
  • Digital Instrument Display for Cars PCB patterns (PDF download) [05108031/2] (Free)
  • Panel artwork for the Digital Instrument Display for Cars (PDF download) (Free)
Articles in this series:
  • Digital Instrument Display For Cars, Pt.1 (August 2003)
  • Digital Instrument Display For Cars, Pt.1 (August 2003)
  • Digital Instrument Display For Cars, Pt.2 (September 2003)
  • Digital Instrument Display For Cars, Pt.2 (September 2003)
Articles in this series:
  • Vibrators: the death knell of expensive dry batteries; Pt.1 (September 2003)
  • Vibrators: the death knell of expensive dry batteries; Pt.1 (September 2003)
  • Vibrators, the death knell of expensive dry batteries; Pt.2 (October 2003)
  • Vibrators, the death knell of expensive dry batteries; Pt.2 (October 2003)

Purchase a printed copy of this issue for $10.00.

PIC Programmer Pass your PIC programmer around the classroom or take it out on the road using this portable, robust design! It can program popular PICs as well as serial EEPROMs. By PETER SMITH U NLIKE PREVIOUSLY published designs, this new PIC programmer can be battery powered for portable use. It can also program all the latest 8-pin and 18-pin devices, including the PIC16F628A and PIC12F629. Another important addition is power supply current limiting. This feature makes it virtually impossible to 26  Silicon Chip destroy a PIC, even if it is accidentally reversed in the programming socket (great for instructional use)! We’ve also included rudimentary in-circuit programming support. A five-way header on the programmer can be connected to your prototyping board for in-circuit reprogramming capability. This means that there’s no need to unplug the PIC (which may be difficult to get to) each time you want to test a change to your code. Finally, a second header has been included for connection to a user-wired programming adapter. This provides a means of programming the 24CXX family of serial EEPROMs, as well as 28-pin and 40-pin (16F87X series) PICs. How it works For ease of explanation, let’s divide the circuit into three sections; power supply, programming interface and Vpp generation and switching. Power for the circuit can be either Fig.1: the circuit diagram for the PIC programmer. PIC programming is performed via the RS232 interface, with IC1 & IC2 providing the connect­ ion to the programming socket. www.siliconchip.com.au www.siliconchip.com.au September 2003  27 Parts List 1 PC board coded 07109031, 100.5mm x 117mm 1 DPDT PC-mount slide switch (S1) (Altronics S-2060) 1 18-pin ZIF socket or IC socket (SKT1) (see text) 1 9V PC-mount battery holder (Altronics S-5048) 1 M205 500mA quick-blow fuse 2 M205 fuse clips 4 small stick-on rubber feet 3 No. 4 x 6mm self-tapping screws 1 9V DC 150mA (min.) plugpack (optional) 1 1kΩ 20-turn or 25-turn trimpot (VR1) Semiconductors 1 MAX232 RS232 receiver/driver IC (IC1) 1 74HC14 hex inverter IC (IC2) 1 LP2951CN or LP2951ACN voltage regulator (REG1) (Farnell 334-3674) 5 PN200 PNP transistors (Q1Q4, Q6) 2 PN100 NPN transistors (Q5, Q7) 1 13V 0.4W (or 0.5W) zener diode (ZD1) 1 1N4004 diode (D1) 1 1N5819 Schottky diode (D2) 5 1N4148 diodes (D3 – D7) 1 3mm red LED (LED1) provided by an on-board 9V battery or an external 6.5-12V DC source (eg, a 9V unregulated plugpack). The switch contacts in the DC socket (CON1) disconnect the battery when a jack is inserted to prevent unwanted (and potentially dangerous) charging of the battery. Conversely, when used for in-circuit programming, the circuit is powered by the prototyping (target) board but more on that shortly. Diode D1 affords reverse-polarity protection before the input is filtered and pumped into a low-power series-pass regulator (REG1). The LP2951 regulator used here has a very low dropout voltage and low quiescent current (75μA typical), making it an ideal choice for battery-powered operation. In conjunction with transistors Q1 & Q2, it also performs the current limiting function. 28  Silicon Chip Capacitors 1 100μF 25V PC electrolytic 1 4.7μF 16V tag tantalum 8 1μF 50V monolithic ceramic 1 220nF (0.22μF) 50V monolithic ceramic 2 100nF (0.1μF) 50V monolithic ceramic 1 33nF (.033μF) MKT polyester Resistors (0.25W, 1%) 1 470kΩ 1 1.2kΩ 1 300kΩ 1 1kΩ 1 100kΩ 1 470Ω 1 22kΩ 3 220Ω 1 15kΩ 2 100Ω 2 4.7kΩ 1 51Ω (for calibration) 1 2.2kΩ 1 1Ω 1 10kΩ (in case VR1 cannot be adjusted to 5V, replace the 22kΩ resistor in Q1 with this) Connectors & cable 1 2.5mm PC-mount DC socket (CON1) 1 9-way 90° PC-mount female ‘D’ connector (CON2) 2 5-way 2.54mm SIL connectors (optional) (Altronics P-5495) 1 3-way 2.54mm SIL header & jumper shunt (JP1) 9-way RS232 cable, D9M to D9F “pin-to-pin” type 100mm (approx.) length of 0.71mm tinned copper wire A 1Ω resistor in series with the regulator’s input is used as the current sense element. We’ve redrawn a small section of the circuit to make its operation easier to understand – see Fig.2. As you can see, Q1 & Q2 are wired in a simple current-mirror configuration. Consequently, the voltage developed across the sense resistor in Q2’s emitter leg will also be developed across the 470Ω resistor & 1kΩ potentiometer (VR1) in Q1’s emitter leg. The current flowing in Q1’s emitter also flows in the collector (minus base current), so with the 22kΩ resistor shown, a voltage gain of about 22 is produced. Effectively, the circuit acts like a common base amplifier. When the voltage drop across the sense resistor reaches 100mV (for 100mA total circuit current), the voltage on Q1’s collector exceeds the threshold voltage on the regulator’s SD (Shutdown) input, signalling the LP2951 to shut down. A 220Ω resistor and 33nF capacitor between the SD input and ground provide loop compensation, ensuring high frequency stability. Potentiometer VR1 is included in the emitter circuit of Q1 to allow adjustment of the current trip point. The LP2951 is an adjustable regulator with an output range of 1.24V – 29V. However, by connecting the SENSE, FB and VTAP pins as shown, the output is a well-regulated 5.0V. When used for in-circuit programming, +5V is provided by the target system (CON3/4 pin 2). In this case, the power switch (S1) should be set to the “OFF” position to prevent the LP2951 from attempting to power both the programmer and the target board. With power provided from the target board, the voltage on the regulator’s output will be higher than it’s input voltage, which would forward-bias the internal series-pass element. Schottky diode D2 prevents this from happening by clamping the input-output differential to less than the pass element’s forward voltage. Programming interface Fig.2: a small section of the diagram from Fig.1, highlighting the current mirror configuration of the Q1 & Q2 transistor pair. The code and data memory in most of Microchip’s microcontrollers can be programmed using a serial method. Microchip refers to this as “ICSP” (In-Circuit Serial Programming), and detailed information on how it works is available from their web site at www.microchip.com (look for the “Memory Programming Specifications” link in the “Engineer’s Toolbox” section). www.siliconchip.com.au To understand how the programmer works, we only need a very basic knowledge of ICSP. Essentially, two port pins (RB6 & RB7 on the 16F84) take on a secondary role when in programming mode. One pin (DATA) is used for bidirectional data exchange, whereas another (CLK) is used to synchronise the exchange. The serial input/output (DATA) pin carries both commands (“erase”, “program”, etc) and data to and from the micro’s code and data memories. On the programming board, the DATA & CLK pins are connected to the PC’s serial port DTR, CTS & RTS lines and controlled by Windows programming software. A MAX232 receiver/driver (IC1) converts the ±10V (nominal) RS232 voltage levels to logic-compatible (0-5V) levels. IC2, a 74HC14 hex inverter, buffers and inverts the DATA and CLK signals to and from the programming socket. A 2.2kΩ resistor in series with the output of IC2a provides a simple isolation mechanism when the DATA pin is in output mode. To enter programming mode, the micro’s MCLR/VPP pin must first be driven low and then raised to the programming voltage level. Again, this is controlled by the Windows programming software via one of the PC’s serial port lines (TXD). The TXD line is first converted to TTL levels by a resistive divider and clamping diodes D6 & D7, after which it is buffered and inverted by IC2e. The output from IC2e then drives an MCLR/VPP switching circuit, comprised of Q3-Q7, ZD1, D5 and a sprinkling of resistors. Vpp generation & switching The PIC16F84/A requires a high voltage level (13V ±1V) on its MCLR/ VPP pin during programming. This is generated by adding several components to IC1s existing voltage boosting circuitry. As described earlier, IC1’s primary function is to convert RS232 voltage levels to logic levels and vice-versa. With only a +5V supply rail, the MAX232 generates the higher positive and negative voltages required for RS232 communications using two internal charge-pump voltage converters. One converter doubles the supply voltage to +10V (nominal) and the other inverts the result to obtain –10V. www.siliconchip.com.au Fig.3: follow this diagram closely when assembling the PC board. Take care with the orientation of all the ICs, diodes, and the 100μF and 4.7μF capacitors. The 51Ω resistor should only be installed during the current calibration procedure. Four external 1μF capacitors provide the necessary filtering. By adding diodes D3 & D4 and a 1μF capacitor to pin 4, we’ve tapped into the MAX232’s charge pump circuitry to create a voltage quadrupling circuit. However, due to switch and diode losses, the voltage appearing on D4’s is less than four times the supply rail, at about 17.8V. To minimise loading on the boosting circuitry and therefore reduce battery drain, we’ve used a low-current voltage reference together with a series pass element to generate the nominal 13V programming voltage. Transistors Q3 & Q4 form a simple constant current source, providing bias current for ZD1 & D5 and the base of Q5. The series combination of ZD1 & D5 clamp the base of Q5 at 13.6V, which fixes the output (emitter) of Q5 at 13V, assuming Q7 is off. When Q7 switches on, it pulls the base or Q5 towards ground, switching it off. At the same time, Q6 switches on. This holds the MCLR/VPP signal at a logic low level and therefore any PIC in the programming socket is held in the reset state. The totem-pole arrangement of Q5 (NPN) and Q6 (PNP) gives a two diode Main Features • • • • • • • Battery (on-board) or plugpack powered Programs PIC16F84/A, 16F627/A, 16F628/A, 12F629 & 12F675 micros Programs PIC16F87X & 24CXX EEPROMS with user-wired adapters Serial port connected (eliminates parallel port cabling issues) Reverse PIC protection Supports in-circuit programming (limited, see text) Recommended software runs on Win9x, Me, NT4, 2000 & XP September 2003  29 Fig.4: the main IC-Prog window. Select the PIC type from the drop-down list on the menu bar (here we’ve chosen the PIC16F84A) before loading the HEX file. drop “dead-band”, ensuring that both transistors don’t conduct simultaneously during switching transitions. Note: the (newer) PIC16F62X and 16F87X series micros do not require high voltage for programming. How­ ever, Microchip has retained sup­ port for this programming method to ensure backward compatibility. Therefore, all of these devices can be programmed using the Portable PIC Programmer. Construction All parts mount on a single PC board coded 07109031. Using Fig.3 as a guide, begin by installing the four wire links, followed by all the resistors and diodes. Make sure that the cathode (banded) ends of the diodes are oriented as shown. The three sockets for IC1, IC2 and REG1 can go in next, followed by the capacitors, transistors (Q1-Q7) and potentiometer (VR1). Note that there are two transistor types (PN100 & PN200), so be careful not to mix them up! Install the connectors, 3-pin header (JP1), fuse clips and power switch (S1) next. If you’ll only be using the on-board programming socket, then there’s no need to install to two ICSP headers (CON3 & CON4). The battery holder, power LED and programming socket should be fitted last of all. Before soldering the holder in place, secure it firmly to the PC board using three No.4 x 6mm self-tapping screws. For the programming socket, you can use either a standard IC socket or one of the (much) more expensive ZIF (Zero Insertion Force) sockets. It all depends on how often you’ll be using it and how much money you want to spend. 18-pin ZIF sockets are available locally from a number of sources, including Jaycar Electronics (Cat. PI-6480). To complete the assembly, attach four small stick-on feet to the underside of the PC board, or fit a nylon/ brass tapped spacer to each corner hole. Alternatively, check out the section towards the end of this article if you prefer to build the programmer into a case. Before we move on to the programming software, let’s do some basic power checks and calibrate the current limiting circuit. Setup and testing For the following tests, you’ll need a fresh battery or a 9V DC plugpack, a 51Ω 0.25W resistor and a digital multimeter. Important: do not insert a PIC in the programming socket or plug in the serial cable until these checks are complete! All measurements are made with respect to the ground rail. Connect the negative probe of your meter to any convenient ground point, such as the cathode (banded) end of D5 or the metal body of the power switch (S1). Adjust VR1 fully clockwise and switch on. Set your meter to read volts and check each of the following points for the voltages indicated: REG1 pin 1 (5.0V); IC1 pin 2 (+9.6V); IC1 pin 6 (-9.4V); and D4’s cathode (+17.8V). Table 1: Resistor Colour Codes                30  Silicon Chip No. 1 1 1 1 1 2 1 1 1 1 3 2 1 1 Value 470kΩ 300kΩ 100kΩ 22kΩ 15kΩ 4.7kΩ 2.2kΩ 1.2kΩ 1kΩ 470Ω 220Ω 100Ω 51Ω 1Ω 4-Band Code (1%) yellow violet yellow brown orange black yellow brown brown black yellow brown red red orange brown brown green orange brown yellow violet red brown red red red brown brown red red brown brown black red brown yellow violet brown brown red red brown brown brown black brown brown green brown black brown brown black gold gold 5-Band Code (1%) yellow violet black orange brown orange black black orange brown brown black black orange brown red red black red brown brown green black red brown yellow violet black brown brown red red black brown brown brown red black brown brown brown black black brown brown yellow violet black black brown red red black black brown brown black black black brown green brown black gold brown brown black black silver brown www.siliconchip.com.au Fig.5: Windows NT/2000/XP users can enable the built-in I/O port driver on this tab. Do not change any other settings here! Fig.6: if you get this message when IC-Prog starts, it means that the I/O port driver is not properly installed. Our prototype used a ZIF socket for the programming socket but you can substitute a standard IC socket if the unit is only for occasional use and you want to save money. If all measurements check out, then power off and install the 51Ω resistor across the +5V and ground rails. If you have a ZIF socket, this can be achieved by slipping the resistor into pins 5 (VSS) and 14 (VDD) of the socket and closing the gate. Be sure to fit a jumper shunt on JP1 (pins 2-3) to route VDD to pin 14 of the socket. Alternatively, if you’re using a standard IC socket, then temporarily solder the resistor into the “calibration” position marked on the overlay diagram (Fig.3). That done, power up and slowly wind VR1 in an anticlockwise direction while monitoring the +5V rail. At some point, you should note that the voltage starts to decrease. Now reverse direction, winding the pot in a clockwise direction until the voltage reading is just restored to its maximum value. This sets the maximum power supply current to approximately 100mA. About 15mA is consumed by the onboard circuits, leaving 85mA for the programming socket. Now if a PIC is accidentally reversed in the socket (or a faulty PIC is inserted), nothing bad should happen! www.siliconchip.com.au Now switch off and remove the 51Ω resistor. The calibration is now complete, so let’s move on to the PC side of things and install the Windows programming software. Installing the software The PC-interface side of our programmer is compatible with the well-known Ludipipo/JDM serial PIC programmers. This means that it can be used with much of the free programming software available on the Internet. In keeping with several recent articles on PIC programming, we’ve selected IC-Prog for the job, as it can program all the devices of interest and it runs on all recent vintages of Windows. You can obtain the latest version of IC-Prog from www.ic-prog.com 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 Fig.7: select the “JDM” type programmer on the “Hardware Settings” tab. The I/O Delay slider is generally OK at the default setting but can be increased if you get the occasional verify error. Do not enable (check) any of the “Invert” signal options! Fig.8: the Hardware Check window provides a handy means of controlling the interface lines for fault-finding. September 2003  31 on your desktop (or start menu) to “icprog.exe”. The help file (icprog.chm) should also be saved in this new folder. A few users have reported issues programming newer devices (e.g, PIC16F88), this can be resolved by using an alternative called "Win­ PIC" at: http://www.qsl.net/dl4yhf/ winpicpr.html (complete with doc­ umentation). Choose an interface type "COM84 programmer for serial port" for compatibility with with the Portable PIC Programmer in the "In­ terface" tab. Keep in mind, IC-Prog and WinPIC will not easily co-exist on the same PC. Installing the port driver Fig.9: after you hit the "Program All' button, IC-Prog automatically erases, programs and verifies code, data and configuration (fuse) memory. If the CP (code protect) fuse bit is set, the verify will fail. 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 For Windows NT/2000/XP users, the serial/parallel port driver should be installed as the next step. Before continuing, refer to the “I/O Port Access on Windows NT/2000/XP” panel elsewhere in this article. Launch IC-Prog (ignore any error messages) and from the main menu select Settings -> Options. Click on the Misc tab and from the list of displayed options (Fig.5), click on the “Enable NT/2000/XP Driver” check box (do not change any other settings on this tab!). Follow the prompts to restart IC-Prog and complete the installation. Note: you need to be logged in as “Administrator” (or equivalent) when installing the driver. If the installation is unsuccessful, you will get a “Privi­ leged 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 Set­ tings -> Hardware to bring up the “Hardware Settings” dialog (see Fig.7). Choose “JDM” 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!). To prepare for the next step, connect your programmer to the chosen serial port using a 9-way “pin-to-pin” RS232 cable and power up. Vpp check Before programming your first PIC, it’s a good idea to check that the programming voltage (Vpp) level is correct. We weren’t previously able to do this during the setup and test procedure because the MCLR/Vpp switch (Q7) is on by default, disabling the 13V regulator. IC-Prog includes a handy debugging dialog that enables us to switch on the programming voltage. Select Settings -> Hardware Check from the main menu to bring up the “Hardware Check” window (Fig.8). Click in the “Enable MCLR” box to switch off Q7 and enable the 13V regulator. Now measure the voltage at pin 4 of the programming socket. If all is well, your measurement should be close to 13.0V. By the way, clicking in the “Enable Data Out” box should cause a corresponding tick to appear in the “Data In” box. This is because “Data Out” (DTR) is looped back to “Data In” (CTS) on the programmer. It’s a handy way of checking that the software is communicating with your programmer. Assuming your programmer has checked out OK, close the “Hardware Check” window and reach for that bag of blank PICs! Acid test Fig.10: this is the full-size etching pattern for the PC board. 32  Silicon Chip To program a PIC, first select the www.siliconchip.com.au appropriate device type from the dropdown list on the main menu bar – see Fig.4. That done, load the program/ data file that you wish to write via the File -> Open File menu. The contents of the file will appear in the “Program Code” and “EEPROM Data” frames. Next, switch off and insert your PIC in the programming socket. Both 8-pin and 18-pin devices go in with pin 1 aligned as shown on the overlay diagram (Fig.3). For 8-pin devices, install a jumper shunt on JP1 pins 1-2, whereas for 18-pin devices, jumper pins 2-3. Now power up the board and click on the “Program All” button. If programming fails, erase the device (click on “Erase All” button) and try again. By default, the device is automatically verified both during and after programming. If desired, you can change this action via the Programming tab, accessible from the Settings -> Options menu. Fig.11: to program PICs in-circuit, include a 5-way header on your prototyping board for connection to the programmer. Switches S1 & S2 and diode D1 isolate the ICSP signals during programming. Caution! If you’re about to program either a PIC12F629 or PIC12F675, then beware! The internal oscillator and bandgap reference are factory calibrated and the results saved on-board. When you erase/program the device, these values are overwritten! Before erasing or programming the device for the first time, perform a memory read and record the bandgap fuse settings and OSCCAL value for future reference. The OSCCAL value is stored in the last location of code memory (03FF). Refer to the Microchip datasheet for more information. In-circuit programming For faster development, it’s possible to connect the programmer to your prototyping board. Then each time you want to test a modification to your code, there’s no need to unplug the PIC chip to reprogram it. An ICSP header (CON3/4) is provided on the programmer for the connection. Fig.11 shows the additional circuitry that you’ll need to include on your prototyping board to support ICSP. To prevent the ICSP signals from being loaded down by the circuits that would normally be connected to the PICs RB6 & RB7 port pins, these two lines must be isolated during programming. The easiest way of achieving this is with switches or jumpers. www.siliconchip.com.au Fig.12: you can easily expand the programmer to handle 28-pin & 40pin flash-based PICs. Here we show how to wire up a 28-pin socket for the PIC16F873/876 devices. Fig.13: you can also program the 24CXX family of EEPROMs by building a simple adapter, wired as shown here. Also, note that the high voltage present on the MCLR/VPP line during programming must be isolated from the prototype board’s +5V rail with a Schottky diode. Use a 10kΩ (or larger) pull-up resistor for your power-on reset (MCLR) circuit. The cable between the programmer September 2003  33 I/O Port Access In Windows NT/2000/XP The I/O (Input/Output) ports present on most PCs provide a simple means of connecting and controlling just about any type of external device. To simplify design (and save money), many of these external devices rely on the PC’s horsepower to do all the work. Often, this means that external hardware can be reduced to just a few transistors or logic gates. You might be surprised to learn that controlling “dumb” devices like these can be quite a challenge even for today’s super micros. Windows operating systems are “event driven”, meaning that they do not work well with devices that need to be controlled in “real time”. Simple PIC and EEPROM programmers fall into this category. To get around this problem, software engineers often bypass the Windows operating system altogether and access the I/O port hardware directly. This method works well under Windows 95/98 and earlier Microsoft operating systems. However, Microsoft “shut the door” in Windows NT, 2000 & XP, making it impossible to (legitimately) access the ports directly. This was done to improve the integrity and security of Windows. Nevertheless, on a stand­ alone machine in a development (home, workshop, etc) environment, this level of security can be a pain in the proverbial. Note: for direct I/O access, the hardware must be connected to the PCs ISA bus. The standard serial and parallel ports on most motherboards are ISA bus-connected. Conversely, add-on serial or paral- lel port cards that plug into a PCI slot are not. PCI-connected ports require special Windows drivers and therefore won’t work with the direct I/O methods (or port drivers) described here. and your prototype board must be no longer than 150mm to ensure reliable operation. In ICSP mode, +5V power for the programmer is derived from the prototyping board. This means that you need to power off your prototyping board before connecting and disconnecting the ICSP cable. It also means that the programmer’s power switch (S1) should remain in the “OFF” position if a battery or plugpack is connected. 34  Silicon Chip Faking it Not surprisingly, a number of programmers have written port drivers that circumvent the Windows protection schemes, restoring direct port access capability to user mode programs. This allows much of the legacy hardware and software to continue to work on the latest operating systems. It also allows enthusiasts like us to continue experimenting with our simple port-controlled gizmos! IC-Prog port driver IC-Prog includes a built-in port driver than enables direct serial (and parallel) port access. However, if you don’t want to install this driver, then you can still use the software by selecting the “Windows API” option in the “Hardware Settings” dialog. As you’ve probably guessed, The “Windows API” option forces IC-Prog to access the serial port indirectly (via Windows). The downside to this is slower and less reliable device programming. Port driver compatibility Generally, once a direct I/O port driver is installed, it operates transparently, granting “carte blanche” access to any application that requests it. It’s up to you to make sure that you don’t try to access the same port from two different applications! While testing our prototype, we noticed that one MS-DOS program Faster programming To speed development work even further, check out IC-Prog’s command line options. If you’re continually rebuilding the same project, then there’s no need to open IC-Prog and manually perform the reprogramming steps each time. Instead, create a batch file (or (Autotrax) stopped responding to mouse & keyboard input when ICProg’s port driver was installed. In the unlikely event that you experience this problem, then you’ll need to uninstall the driver. This can be achieved by simply removing the tick from the “Enable NT/2000/XP Driver” check box and restarting Windows. You can then either use the “Windows API” option mentioned above or opt for a different port driver. We found two that appear to work fine with IC-Prog and MS-DOS programs, as well as other programs requiring direct port access. These are: (1.) UserPort, written by Tomas Franzon and available from: w w w. e m b e dd e d t ro n i c s . c o m / design&ideas.html (2.) PortTalk, written by Craig Peacock and available from: www.beyondlogic.org/porttalk/ porttalk.htm Follow the instructions in the “UserPort.pdf” document (included in the ZIP file) to install it. Note that the default port settings must be changed to suit your setup. Fig.14 shows the correct I/O address ranges for COM1 (top) through to COM4 (bottom). For example, if your programmer is connected to COM2, you’d enter only the second address range (2F8 – 2FF) and remove all the others. Of the two drivers, we prefer PortTalk because it allows you to restrict access to specific programs. To install it, unzip “porttalk22.zip” into a temporary directory and copy “allowio.exe”, “porttalk.sys” and “uninstall.exe” into your IC-Prog folder. You’d then use “allowio.exe” to shortcut on your desktop) with the necessary command. For example, the following command line could be used to program a PIC16F84A with “test.hex”: icprog.exe -ltest.hex -t104 -p -i -q A full description of all the command line options can be found in the on-line help, accessible from IC-Prog’s main menu bar. www.siliconchip.com.au PIC16F627A/8A Fuse Bits Fig.14: this screen capture shows the correct I/O address ranges for COM1 (top) through to COM4 (bottom) grant IC-Prog access to the appropriate COM port. For example, if your programmer were connected to COM2, you’d launch IC-Prog with the following command line: allowio.exe icprog.exe 0x2F8 To make life easier, place a shortcut to “allowio.exe” on your desktop. Right-click on the shortcut and choose “Properties” from the context menu. On the “Shortcut” tab, edit the “Target” box to include the above arguments. Refer to the PortTalk.pdf document (included in the ZIP file) for more information. Note: we emphasise that you do not need to download and install either of these drivers unless you experience problems with MS-DOS programs after enabling IC-Prog’s built-in driver. Be sure that you have completely uninstalled one port driver before installing another! Uninstalling ICProg’s built-in driver is as simple as removing the tick from the “Enable NT/2000/XP Port Driver” check box and restarting Windows. We do not recommend the use of any of these direct I/O port drivers in an industrial or military setting or any other application that demands high integrity and/or security. Programming other devices Your new programmer can also program the larger PIC16F8XX devices, as well as most of the 24CXX serial EEPROM family. However, you’ll need to wire up separate adapters for the job. Fig.12 shows the connections required for the 28-pin PIC16F873/876 devices. A similar scheme can be employed for the 40-pin PIC16F874/877 devices. Fig.13 shows the connections for www.siliconchip.com.au The current version of IC-Prog (1.05a) does not list the 16F627A or 16F628A as supported devices. Undoubtedly, they will be included in a future release. In the meantime, the “A” part can be successfully programmed by selecting the 16F627 and 16F628 entries. The main difference between the “A” and “non-A” parts (from a programming perspective) can be seen in the fuse bit assignments. Fuse bits defined in your code should read in OK and not need any modification. If you’re modifying them manually in IC-Prog, then note the following: (1). The 16F627/8 has more code protection bits than the 16F627A/8A. To code protect an “A” part, select the entire memory range. For the 16F627A, choose “CP 0000h-03FFh” and for a 16F628A, choose “CP 0000h-07FFh” (2). Fuse bit 6 is named “BODEN” on the 16F627/8 and “BOREN” on the 16F627A/8A but it is functionally identical. (3). “ER” oscillator mode on the 16F627/8 has been redefined as “RC” oscillator mode on the 16F­627A/8A. In other words, choose “ER” mode if you want the “RC” mode. 24CXX serial EEPROMS. This supports the 24C01, 02, 04, 08, 16, 32, 64, 128, 256 & 512 devices. Both “C” and “LC” varieties are supported. The adapters can be wired up on a small piece of Veroboard, which is then connected to one of the programmer’s ICSP headers (CON3/4). As before, the cable length must be restricted to 150mm for reliable operation. This far exceeds the capabilities of the Portable PIC Programmer, which we’ve designed for low-power operation. Although this current requirement theoretically exceeds the programmer’s limit, we were able to successfully program all the blank 12C508s we had on hand. Replacing the 1µF capacitor at the cathode of D4 with a 10µF 35V Tantalum type helped. About PIC12C508/9 micros Housing Undoubtedly, some would-be constructions will want to know if this project can program the 12C508 & 12C509 devices. These have been popular amongst the gaming community over recent years for PlayStation “modchips” and the like. The short answer is yes but results are not guaranteed. To understand why, a little background information is required. PIC micros with a “C” in the type number can not be electrically erased. In fact, unless they have a quartz window, they’re OTP (One Time Programmable) only. In addition, unlike the “F” series chips, they don’t generate their own, on-chip programming voltage. This might sound like an odd statement, considering that the programmer applies 13V to the MCLR/VPP pin on the “F” series chips during programming. However, on the “F” series, this voltage is used only as a bias source, with just 200μA (max.) leakage current flowing into the pin. By contrast, the “C” series chips require 13V at 50mA (max.) on the MCLR/VPP pin during programming. To save money and simplify construction, the programmer does not need to be built into a case. You may prefer it in the “naked” form anyway, so that you can show off your handiwork! Nevertheless, we’ve sized the board so that it will fit into a regular 140 x 110 x 35mm (W x D x H) slimline instrument case or similar. Of course, the programming socket and power switch will need to be moved off the board for accessibility. One way of achieving this might be to wire up a small “carrier” board for the programming socket, which could then be mounted directly on the top or front of the case. You can use one of the ICSP headers (CON3/4) for the connection back to the main board. Just remember to keep the cable length to 150mm or less for reliable operation. Note that as shown on the circuit diagram (Fig.1), a 4.7kΩ pull-down resistor must be connected between pin 10 of the socket and ground. In addition, connect a 100nF decoupling capacitor directly across the supply SC (Vdd & Vss) pins. September 2003  35