ZEPPP: Arduino-based PIC programmer for several old-school microcontrollers. - Page 1
Forum section: electronics / general

author: battlecoder
author_rank: Regular Contributor
timestamp: January 01, 2019, 01:22:11 am
content: This is a project I finished around September and it wasn't until now that it occurred to me that it was perhaps a good idea to share it here.ZEPPP(Zero External Parts PIC programmer) is basically a PIC programmer that requires only two things: A standardArduinoNano/Uno/Pro-miniand your computer(and the PIC of course!)It connects directly to your target microcontroller (or any dev board with a LVP-capable ICSP connector).The command line tool works on Linux, Windows and OSX.It currently supports the following PICs:16F87, 16F8816F627A, 16F628A, 16F648A16F873A, 16F874A, 16F876A, 16F877A.While I guess it makes little sense to most developers or engineers to use such "outdated" devices, I think they are still great for learning, and for simple projects.This is perfect for people who want to try their hand at PIC programming but don't want to (or can't) invest in proper programming hardware. In fact, I started this project for a workshop I was organizing; I had made PIC demo boards for everyone, but it was too unpractical to get PIC programmers for all the attendants, or to expect them to bring their own. Now, most of them already had Arduino boards, and I had several of my own that I could take with me for those who didn't have one.I made a quickpost about this programmer on my blog, but you'd probably be more interested inits GIT repository, where all the latest files are.If any of you give this project a try let me now! Feedback is always a good thing to have (said no audio engineer ever).

author: jaromir
author_rank: Unknown
timestamp: January 01, 2019, 10:35:35 pm
content: Thanks for sharing.I made similar programmer for newer 8-bit devices -https://github.com/jaromir-sukuba/a-p-prog- and really didn't bother to support the older ones (with PGM pin), so your work is great addition to simple PIC programmers.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 02, 2019, 03:41:48 am
content: Awesome project, jaromir! Indeed quite similar to what I did. I'm glad to see something aimed towards more modern microcontrollers, especially with such a wide range of supported devices!For ZEPPP supporting more than one family was a real pain in the rear ...panel. A lot of timing and protocol differences. The programming specs for older devices are all over the place. Hopefully the latest iterations of Microchip's programming specs are more streamlined after their years of experience. I can't imagine the pain of supporting that many devices if the spec are as wildly changing as they used o be.

author: rrinker
author_rank: Super Contributor
timestamp: January 02, 2019, 07:51:30 pm
content: Interesting - if I didn't already have a PICKit 2. I have a box full of 16F873/877 (whichever the complementary ones are, where the one has more memory but is otherwise identical). An old circuit I was going to use used the smaller chip, I figured the extra memory wouldn't for the most part break code written for the one with less memory, and so managed to get several dozen as samples. I've since changed my approach and instead of building someone else's interface design using the PIC chips I am designing my own with Atmel micros. I should do something with all those PICs though. Port my code and make some of my board with the PIC, but I'd rather not have a mix of devices, even though it is all for personal use. I suppose if they would be indistinguishable at the sharp end, it wouldn't matter. At any rate, I hate to see a box full of potentially useful chips just go to waste, at some point I'll come up with some project to use them in.These may be older chips, but there are still plenty of applications that don't need the speed and/or memory of ARm cores and the like. Using faster micros where the project involves mostly waiting for user input just means the thing executes more keyboard scans than a slower one - the old slow ones are more than capable of performing the task.Neat thing about this - I could just set it up as a shield with a ZIF socket and use the same Arduino with my ATTiny shield, or a PIC shield, depending on what I wanted to program. Effectively one platform for multiple purposes. In fact, if it's possible to change around some of the pins being used - it could be BOTH, depending on the code loaded to the Arduino.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 02, 2019, 08:57:59 pm
content: Quote from: rrinker on January 02, 2019, 07:51:30 pmSame, but eventually -even if it's 7 years later- I always find a use for the stuff I have (it has happened), and everything is fine again (except for all the stuff I bought during those 7 years, that will sit there unused, bothering me for probably an equally long time).Quote from: rrinker on January 02, 2019, 07:51:30 pmThat's a really great idea. Pins can be changed to whatever you like. All communication happens using regular digital pins. It would be even better if the same firmware can talk to both PIC and Arduino devices, depending on handshake and/or serial instructions being issued by the host. That could be the beginning of an extremely simple multi-microcontroller programmer.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 02, 2019, 09:39:07 pm
content: I have also designed a PIC programmer once. It was PIC based and supported over 1500 different PIC parts. It also worked very fast. It isn't open source, so I cannot share the code, but it was lot of work to deal with all the individual PICs. Microchip is really idiosyncratic.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 03, 2019, 02:05:56 am
content: Quote from: NorthGuy on January 02, 2019, 09:39:07 pmI'd love to see that. I really like the concept of DIY Programmers (or DIY instruments/gear in general). Building your own tools definitely feels good. And yes, the programming protocol specifications for different families can vary a lot. Especially for older devices.Did your programmer use HVP though? ( I can't imagine supporting 1500 parts with LVP. There are many variations of the "handshake" and many limitations with LVP).I have to say I kinda imagined that many of you had already designed programmers with support for a gazillion devices. Mine basically supports a list equivalent to the one my first PIC programmer supported, lol. But I'm quite happy with that. Will look into adding support for more modern devices though, but with projects like the one byjaromir, I don't know what the usefulness of that would be.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 03, 2019, 04:37:46 am
content: Quote from: battlecoder on January 03, 2019, 02:05:56 amHVP and LVP are practically the same. The only difference is the entry routine. However, you need to supply higher voltage. This higher voltage was used to do flash programming, but this was very long time ago. Now PICs just sense the presense of high voltage - you don't need neither good regulation nor high current. I programmed in all the logic, but you would need to supply the 9V or 13V voltage for it to work.Quote from: battlecoder on January 03, 2019, 02:05:56 amIf it is useful to you, it may be useful to others.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 03, 2019, 08:04:04 pm
content: Quote from: NorthGuy on January 03, 2019, 04:37:46 amYes, but not all devices support LVP, and those that DO support it, have several different entry methods. That was my point: It would be harder to support a broad range of devices if restricted to LVP only. Even if you are wiling to implement all the variations of the LVP "handshake", you are already starting with a subset of the whole PIC catalog.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 03, 2019, 08:39:29 pm
content: Quote from: battlecoder on January 03, 2019, 08:04:04 pmThis is a very big subset. I'd say over 90% of all currently sold PICs support LVP. All PIC24/dsPIC33 are LVP-only (some of smaller PIC24 can do HVP), all PIC32 are LVP-only. All modern PIC16 and PIC18 support LVP (and HVP). It is not that many HVP-only PICs - a limited number of older/smaller PIC16/PIC18 parts and most of the PICs from the totally obsolete dsPIC30 group.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 04, 2019, 02:23:14 am
content: Quote from: NorthGuy on January 03, 2019, 08:39:29 pmOh, that isquiteinteresting. I never got into dsPIC, PIC24 or PIC32. Didn't know they were mostly LVP-only devices. In my experience (with PIC16/18 parts) PICs were either "HVP/LVP compatible", or "LVP-only". Thanks for the correction. Glad to have that piece of outdated knowledge in my head updated.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 04, 2019, 04:43:11 am
content: Quote from: battlecoder on January 04, 2019, 02:23:14 amYou should try them. They're very interesting. They're a little bit similar to PIC16/18, but they are way more powerful.Their programming algorithms are very complex though - it would take a while to figure out. You can program then through so-called serial command execution, but it is so slow that you have to upload a small program called "programmer executive" (bootloader if you will) which accepts data from the programmer and programs flash.But it's not as bad as PIC32. The serial execution in PIC32 is done through JTAG-over-ICSP and is so slow that even uploading the programming executive is costly. You need first upload a loader which will then help you to upload programming executive which, in turn, lets you program the flash.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 04, 2019, 07:03:52 am
content: Quote from: NorthGuy on January 04, 2019, 04:43:11 amI have several PIC programmers, one of them being a PicKit3, so I guess I should be good to go. Will start reading about them. I have to admit it's been a while since the last time I tried a new PIC microcontroller. Any particular device you'd recommend?

author: jaromir
author_rank: Unknown
timestamp: January 04, 2019, 03:04:45 pm
content: For sake of completeness - you can program PIC32 using Arduino, using PIC32prog; it supports more than this programming interface, though. I wrote quick how-to here -https://hackaday.io/project/27250-mcu-how-tos-reviews-rants/log/148016-programming-pic32-with-arduinoIt is not the most useful way of loading PIC32 (it takes almost three minutes to load 512k of FLASH), but can be useful as last resort method; or perhaps low cost way to load bootloader once and use the bootloader afterwards.You can get PIC32 in DIP packages, fine for prototyping - I have a few PIC32MX250F128B in my drawer, those are quite universal and proven devices. Similar is also PIC32MX270F256B with even more memory. If you are into higher pin count packages, you may take a look at PIC32MX470F512 or perhaps newer PIC32MZ2048EFH064. Notice the EF in middle of partnumber, avoid EC parts; despite being similar, its errata sheet is more spicy.Oh and always check errata of the part you intend to use. That is also reason I'm not much into the most recent MCUs - the errata list is usually growing in first few years, improving later. The same goes for documentation and online resources; and holds true not only for Microchip.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 04, 2019, 03:42:39 pm
content: Quote from: jaromir on January 04, 2019, 03:04:45 pmThis is rather on a slow side. My programmer could program PIC32MX570F512 in 11 sec. But I'm sure if you optimise it a little bit, it can be done much faster than 3 minutes with Arduino.

author: jaromir
author_rank: Unknown
timestamp: January 04, 2019, 04:06:11 pm
content: It's not my work, I just wrote the article (I made the PIC16/18 programmer mentioned earlier, though) Yes, it is glacially slow, but work nonetheless, costs two dollars and can be repurposed for something else. I had intentions to start my own PIC32 programmer a few times, but looking into PIC32 programmings specs put me off every time.On the other hand, your programmers are the fastest ones known to me (faster than the official Microchip tools) and I'm pretty sure it took a lot of work to optimize it. My hat's off to you.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 04, 2019, 04:20:49 pm
content: Quote from: battlecoder on January 04, 2019, 07:03:52 amThere are lots of different PIC24/dsPIC33 devices, so it depends on what you want.There are small devices - PIC24F..K - they are the most similar to PIC18 and very cheap, but they have PIC24 CPU.Big monsters with USB controllers, such as dsPIC33EP...GU..., dsPIC33EP...MU...Small devices with fast PWM/ADC designed for SMPS and similar - dsPIC33EP...GS...Slow general purpose devices with 1MB flash PIC24FJ1024GB6...Recent addition with dual core - where the second core runs from RAM and has to be pre-programmed by master dsPIC33CH...Take you pic(k).

author: JPortici
author_rank: Super Contributor
timestamp: January 04, 2019, 04:43:53 pm
content: Quote from: NorthGuy on January 02, 2019, 09:39:07 pmI also did a programmer, actually a software library to update the code for the slave pic from the master pic.The one bit i never understood is the reverse order SPI (LSB first) do you have any idea why they did it this way?

author: JPortici
author_rank: Super Contributor
timestamp: January 04, 2019, 04:56:31 pm
content: Anyway, My goto dsPIC is the 33EV series which is 5V only (really, 4.5 to 5.5V. If device doesn't work check VDD first) but has a lot of goodies, and less gotchas than the MU series (like IC and OC modules are truly independent)Then of course for 3.3V the 33CH/CK series. Extremely versatile beasts, altough no usb (hence why i had to implement a programmer for a pic that acts as an usb bridge. Why? Because no usb/whatever bridges in extended temp range and at sane prices)The architecture is very nice IMHO, with clear and simple assembly and a lot of grunt thanks to the dsp and many addressing modes

author: NorthGuy
author_rank: Super Contributor
timestamp: January 04, 2019, 05:20:39 pm
content: Quote from: JPortici on January 04, 2019, 04:43:53 pmI don't know why they did it. Since these are instructions, it might have been done either way.When you enter into the programming executive mode, it connects the PGC/PGD pair to SPI1. So, your programming executive simply uses the SPI module to communicate with the programmer. Then it naturally becomes MSB first.

author: NorthGuy
author_rank: Super Contributor
timestamp: January 04, 2019, 05:57:16 pm
content: Quote from: jaromir on January 04, 2019, 04:06:11 pmIn the early days, when I started, I found your web site on debugging PIC18. It was the best information on the subject I could find and it gave me good understanding on how PIC18 debugging works. Thank you for that web site! Although I'm now busy with other things, hopefully I find time to finish the debugger GUI.

author: ThaZ
author_rank: Newbie
timestamp: December 31, 2019, 05:26:54 pm
content: Hi, is there any chance that this programm is gonna be supports the PIC18F47J53 ?

author: battlecoder
author_rank: Regular Contributor
timestamp: January 04, 2020, 04:59:14 am
content: Quote from: ThaZ on December 31, 2019, 05:26:54 pmIn theory support for that kind of device can be added, but it uses a completely different method to enter programming mode, and apparently a newer revision of the ICSP spec so it may take a bit to implement. My programmer is designed for old chips but I may eventually update it to support newer PICs. Just can't promise anything.Anyway, I'd advise you to check the comments of other users in this thread. Some of them have made similar projects but for a wider range of devices, most of them from the newer families that mine does not support.

author: panoss
author_rank: Frequent Contributor
timestamp: January 06, 2020, 06:51:00 pm
content: Hi battlecoder, thanks for sharing your work.I 'm trying to understand your code and how e.g. from the 'PIC16F627A/628A/648A EEPROM Memory Programming Specification' you created the code you created.(because I want to be able to do the same for any MCU or EEPROM and specifically for an EEPROM I have(EN25F80))I read in the above mentioned document, page 11:QuoteFrom this you created this code:Code:ReturnCode execute_serial_cmd() {switch (cmdCode) {// PGM Memory Erase --------.................case ZEPPP_CMD_PGM_MEM_ERASE:load_pgm_mem (0x3fff);bulk_erase_pgm_mem();Am I correct?

author: amyk
author_rank: Super Contributor
timestamp: January 07, 2020, 03:25:00 am
content: A set of wires connected to a PC parallel port will do LVSP just as well.

author: panoss
author_rank: Frequent Contributor
timestamp: January 07, 2020, 07:31:51 am
content: So you 're saying that actually Arduino is not even necessary for this job?

author: NorthGuy
author_rank: Super Contributor
timestamp: January 07, 2020, 01:40:17 pm
content: Quote from: panoss on January 07, 2020, 07:31:51 amAll you need is to produce logic levels on 3 (or 4 for PICs with PGM pin) pins. If you want to detect if the PIC is connected or to verify the results, one of the lines must be bi-directional.

author: panoss
author_rank: Frequent Contributor
timestamp: January 07, 2020, 04:29:37 pm
content: So let 's say I have a 16F628A.Using the 'PIC16F627A/628A/648A EEPROM Memory Programming Specification' I will try to make the algorithm for entering LVP mode (Low Voltage Program).The 4 pins that should be used are PGM(RB4), MCLR(RA5), DATA(PGD (RB7)) and CLOCK(PGC (RB6))?Page 6: ' Low voltage Program/Verify mode is entered by raising VDD, then MCLR and PGM, as shown in Figure 2-3'Code:Enter Low voltage Program/Verify mode:1. supply PIC with power2. PGM must be set to HIGH3. MCLR must be set to HIGHIs my pseudocode correct?How much time should pass between these commands? Where can I find this?

author: NorthGuy
author_rank: Super Contributor
timestamp: January 07, 2020, 06:57:05 pm
content: Quote from: panoss on January 07, 2020, 04:29:37 pmIn Section 4 (table 4-1 "AC/DC CHARACTERISTICS TIMING REQUIREMENTS FOR PROGRAM/VERIFYMODE") of your programming document.

author: panoss
author_rank: Frequent Contributor
timestamp: January 07, 2020, 07:54:13 pm
content: How about this:Code:Enter Low voltage Program/Verify mode:1. supply PIC with power2. Wait for 5us (Hold time after VDD↑ 5us)3. PGM must be set to HIGH4. MCLR must be set to HIGH5. Wait for 5us (Hold time after MCLR↑ 5us)6. Wait for 5us (Hold time after LVP↑ 5us)

author: NorthGuy
author_rank: Super Contributor
timestamp: January 07, 2020, 08:34:12 pm
content: Quote from: panoss on January 07, 2020, 07:54:13 pmI think the LVP wait time comes between PGM up and MCLR up. In practice, the only important thing is to make sure to set PGM before MCLR - otherwise the PIC will start running and may screw everything up.

author: battlecoder
author_rank: Regular Contributor
timestamp: January 07, 2020, 09:44:36 pm
content: Quote from: panoss on January 06, 2020, 06:51:00 pmYep. Tried to follow the programming specifications as much as possible, but when i found differences between devices I normally checked if one of the methods also worked on the other devices first, before having device-specific implementations of a particular process.Quote from: amyk on January 07, 2020, 03:25:00 amIn fact the first programmer I built for myself used the parallel port! It required several components, but they were mostly for the HVP part. LVP can totally be done with nothing but the LPT port. It's unfortunate that it's not a popular port nowadays and computers no longer have it.Quote from: panoss on January 07, 2020, 04:29:37 pmAs NorthGuy already mentioned, all the information is in the programming specs.If you are able to generate the signals with the appropriate timing, yeah, you don't need An arduino. You could use a Raspberry Pi, a PC with a Parallel port, a Wemos board, whatever allows you to create logic-level signals according to the specs.My project uses an Arduino to create the signals because they are simple, cheap, and can be connected to a computer via USB, which is a port you will find in any computer built after the Stone Age.

author: mcovington
author_rank: Regular Contributor
timestamp: January 08, 2020, 12:57:17 am
content: I like the name ZEPPP, which suggests you once encountered NOPPP, which I was the perpetrator of, about a quarter century ago!

author: battlecoder
author_rank: Regular Contributor
timestamp: January 08, 2020, 02:45:31 am
content: Quote from: mcovington on January 08, 2020, 12:57:17 am!!! Indeed! The name of my project is 100% an homage to both the original NOPPP, and the "Enhanced" version based on your design, which ended up being the first PIC programmer I built and used! Your NOPPP programmer is what allowed me to begin my journey with microcontrollers when I was (way) younger!

author: mcovington
author_rank: Regular Contributor
timestamp: January 09, 2020, 02:58:24 am
content: For completeness we must acknowledge David Tait's TOPIC (Try Out PIC), of which NOPPP was a simplification. A long lineage!

author: battlecoder
author_rank: Regular Contributor
timestamp: January 09, 2020, 07:57:21 am
content: Quote from: mcovington on January 09, 2020, 02:58:24 amOh, definitely. David Tait was a name that kept appearing in my searches when I started with PICs. There were a few other names that were really everywhere, and people around the world were building those designs and improving upon them. JDM was also another popular programmer circuit back then, and NOPPP was also 100% part of that landscape.Back then I had pretty basic "maker" skills, almost no knowledge, and highly limited access to electronic components and tools, so the simpler the circuit the better.I ended up building James Padfield's modified version of NOPPP, though, which (if my memory serves me well) was fairly "recent" at the time, and supported a couple more PICs by means of a simple extra resistor and modified software.I owe you a lot, truly. Even when NOPPP was simple in its design I learned a lot from it, and it remained my only and trusted tool for programming PICs for at least several years after I built mine.

author: Slothie
author_rank: Regular Contributor
timestamp: September 18, 2020, 03:22:55 pm
content: Ah PC Paralell Port - thats a name I haven't heard in years!

author: Slothie
author_rank: Regular Contributor
timestamp: September 20, 2020, 06:53:56 pm
content: I've just used this to successfully program a PIC 16F877A with an Arduino Uno using Linux Mint 20 and java 11. I did have problems getting the arduino sketch to compile until I moved the two typedef's into a seperate .h file. Not sure why this was because I'm not an Arduino expert, but I googled and that seemed to be the suggestion people made. Perhaps it was a change to the Arduino pre-processor that reformats the .ino files.

author: battlecoder
author_rank: Regular Contributor
timestamp: September 22, 2020, 06:49:52 pm
content: Quote from: Slothie on September 20, 2020, 06:53:56 pmI will look into the issue you found. I have to admit I haven't updated my Arduino environment in a long, long time, so it could be that the code is not really compiling with later versions of the Arduino environment and I'm just finding out now thanks to you. I have encountered errors like that in the past in other people's projects (that probably used to compile fine 3 years ago but now suddenly you need to rename stuff, or move some declarations somewhere else), so it wouldn't surprise me to see that kind of problem in one of my projects.Anyway, glad to hear you were able to use this programmer successfully. I quite liked the 16F87x family of PIC micros back in the day, and in fact I think the "brain" of my first robot was a 16F874, if my memory serves me right.

author: alexblade
author_rank: Newbie
timestamp: May 16, 2022, 01:59:36 pm
content: Quote from: jaromir on January 01, 2019, 10:35:35 pmHi!I am interested in your project. Please tell me you have implemented the ability to read the firmware?if not. could you do it in the next version 1.0 ?