Having experimented with different ideas, I arrived at a way of working that is quick and convenient. This page provides a step by step guide to configuring your PC to work with my chosen range of software. Please note - I'm not necessarily saying that this is the best way to do this, but if you're in a hurry to get started, this will ensure your system is the same as mine and all of the following sections will work. Once you've gained confidence and experience, I hope you'll feel free to try different ways of working. If you discover a better way, please let me know...
PIC Programming in 2023
This content was originally posted 20 years ago in 2003. So much has changed since then. However, the workflow outlined below served me really, really well. But in the last decade, I didn't really do anything with PICs, either at work or home, until a recent project required me to dive in again. This prompted a bit of research about how things are done today - details of what I found are below, but I'd recommend you at least skim the following sections first.
How I initially programmed PICs (in 2003)
Here's what we need to do:
- Check the (modest) system requirements.
- Install MPASM, the free assembler from Microchip
- Install IC-Prog, a free PIC programmer
- Install ConTEXT, my favourite text editor!
1. System requirements
For PIC programming, I use a PC that has a minimal installation of Windows 98. Because I rely on this machine, I deliberately keep it "lean". Despite being an old OS, it's absolutely fine - in fact, it's one of the quickest, most stable Windows machines I've ever used. Note that it doesn't connect to the Internet, so it doesn't need to run a virus checker or a firewall - this makes a big difference to the performance. It's a 333MHz Celeron with 256MB of RAM, and a fast 30GB hard drive. It reboots in less than a minute, so on the rare occasions that you see a GPF, it's no hardship to restart it.
I've run all the applications very successfully on much slower machines (e.g. 200MHz Pentium 1 with 64kB RAM). The software is not demanding, and the machine spec really just affects the way Windows runs more than anything else. You hardly need any disc space either.
Having said that, it does work fine under XP - the only additional step is downloading an additional driver file. I haven't tried Windows 7 or 8, or anything involving Linux!
You do need a serial port, which is another reason to re-purpose an old machine. Please note that USB to serial converters won't work!
2. Install MPASM
You need the latest version of MPASM, the Microchip PIC Assembler. This can be found on the Microchip website - just type "MPASM" into the search box on the front page.
Alternatively, you could download the whole development environment, which is called MPLAB. Personally, I don't use MPLAB, but don't let that stop you. MPLAB includes a simulator which is occasionally useful.
Installing it is just a case of following the instructions. Decide now which drive and folder you are planning to install it to, as you'll need to know this later. For all sorts of complicated historic reasons (habit!), I installed it on my F: drive, in F:\CAD\PIC\MPLAB
The installation will create a program group, and you should have a shortcut to MPASMWIN (there is a DOS version of MPASM). Run this, and check the options:
From memory, you shouldn't need to change too many of these, but do make sure the List File box is ticked. The other default settings are appropriate, because all of these can be specified in the source code that you'll write later.
3. Install IC-Prog
Download IC-Prog from http://www.ic-prog.com/. Decide now which drive and folder you are planning to install it to, as you'll need to know this later. For all sorts of complicated historic reasons (habit!), I installed it on my F: drive, in F:\CAD\PIC\PICProg
You'll need to configure it to work with your programmer. The screenshot shows the options I set for my JDM programmer, but feel free to experiment. You'll note that I've selected the PIC16F877 - you have to set this before loading the .HEX file, because when you change device, it empties the buffer. If you are running this from ConTEXT (see below), you'll need to run up IC-Prog before and select the processor.
Another option I changed is to enable Verify during programming, which is in the Options dialogue. Otherwise, it won't flag up a problem until after it has completed the programming phase, which can be quite annoying, especially for the larger PICs.
If using Windows XP, you'll need to download the driver I mentioned earlier, which is available on the download page. This is a single file called icprog.sys, which is simply copied to the same directory as ICProg.exe - and then you need to go to the "Misc" tab in the Options dialogue to enable it. Without it, you'll get error popups saying "Privileged instruction", presumably as it tries to communicate directly with the serial port.
Before proceeding, you should ensure that you can write a .HEX file to a PIC, and read one back from the PIC. Use the .HEX file and test circuit discussed previously.
4. Install ConTEXT
Back in 2001, I downloaded just about every free text editor, and decided that ConTEXT was the clear winner for this application. As of 2013, I haven't seen a better option yet. Sadly, ConTEXT isn't actively developed these days, but it's perfectly fine as it stands. As well as PIC programming, I use it for other coding; this website has been produced using it. Yes, it has some quirks, but I like it a lot. Of course, some people have strong views about text editors and will probably want to use their own, but I'd encourage you to try ConTEXT for this - principally because of the ability to define function keys that invoke the assembler and programming software, which makes the "programming cycle" very quick.
Download the latest version from http://www.contexteditor.org/ - note that this text refers to 0.x versions (0.98.6 at time of writing). For some time now, we've been anticipating the release of Version 1 which promises to be radically different, which I hope is a good thing. Should version 1 ever become available - which doesn't seem awfully likely at the moment - then the following instructions might not work.
The download is 1.6MB, and installation is simply a case of running the .EXE, and choosing which directory to install to. For all sorts of complicated historic reasons (also habit!), I installed it on my D: drive, in D:\Program Files\WinUtils\ConTEXT
(After installing Windows, I create Program Files on my D: drive and install all applications there, thus keeping the C: drive as clean as possible. This makes reformatting and rebuilding much easier)
I like to have shortcuts to ConTEXT and IC-Prog on the quick-launch area of the taskbar:
Now, the fun begins. First, we need to install the correct Microchip PIC highlighter. My version is here, but feel free to make your own, as mine is a "work in progress". Every few months I discover a new keyword that should be in the list! Alternatively you can download one from the ConTEXT site - I haven't tried this, so I can't comment on it. Either way, copy the appropriate .CHL file to the Highlighters directory within the ConTEXT program directory and restart ConTEXT. You should find that it defaults to Microchip Assembler (look at the drop-down at the top-right of the screen), but if it picks x86 Assembler instead, you can set it up: Tools, Set Highligher, Customise Types...
You might be wondering why I feel that syntax highlighting is so important. Apart from making the source code look nice, it performs an essential role for beginners - there are so many new instructions and keywords to learn that any help you get from the computer has got to be welcome. As you're typing in your source code, seeing that the instruction changes colour and is shown in bold is good positive feedback - you know you've just typed something that the assembler can understand!
Next, make sure you have a .ASM file to play with. It can be anything - even a totally blank file - we just need to have something with a .ASM file extension open in the editor, because we're going to customise the function keys. You're about to see why ConTEXT is so good!
Drop down the Options menu and select Environment Options... In the dialogue box, click the Execute Keys tab - you should see a tree in a white box showing "asm" as a branch, with F9 to F12 hanging from it. If not, click the Add button.
F9 - Assemble this program
First, click on F9, then click the button on the right of the Execute box (). Browse to the folder you installed MPASM in, and select MPASMWIN.EXE - note that if you installed MPLAB, you'll find MPASM in a sub-folder called "MCHIP_Tools" or similar.
This means that if you press F9 while editing a .ASM file, the Microchip Assembler will run. Pretty neat! But, to make this do something useful, we need to configure the remaining options:
As you can see, we are saving the file, and passing on the filename using %p%f - looking now, I'm not sure why I'm not using %n; perhaps it wasn't an option when I first set this up (there have been many versions of ConTEXT released since I first installed it).
F10 - Programme PIC
Next, click on F10 and browse to the folder that contains ICProg.EXE
You'll note that I've used F12 here, but that was because originally I'd tried doing other things with F10 and F11. In the end I changed it to use F10.
To load a file into IC-Prog from the command line, you must preface the filename with "-l" (lower-case "L"). So, to load PREAMP.HEX, for example, you would type "icprog -lpreamp.hex" at the DOS prompt. Knowing this, we can get ConTEXT to work by typing "-l%p%F.hex" into the Parameters box - %F means the current file minus the extension - a rather neat option.
General ConTEXT options
Have a hunt around the options dialogue - ConTEXT is very configurable. Of course, most options are a matter of personal choice, but I've found the following settings useful:
The print options are equally configurable - you can define some nice headers and footers, and you can choose whether to use syntax highlighting and colours - very useful.
Summary (2003)
So that's all you need - a handful of small applications running on a modest machine. You should have configured ConTEXT so that pressing F9 assembles the program, and F10 programmes the PIC. This makes the programming cycle (explained later) very quick and simple. I find this approach much easier than using MPLAB, but feel free to try it both ways.
PIC programming 20 years later
As mentioned earlier, the setup described above has worked brilliantly for me. Not only at home, but also at work, where I taught basic PIC programming for many years. However, with all the cutbacks at work, demand for the courses gradually fell away, while at the same time family life got in the way of hobbies, meaning that I haven't inhabited the PIC world personally or professionally for about a decade. But deciding to incorporate a PIC into a recent project prompted me to re-visit this. Plus, the demand to re-start the courses at work is slowly building momentum. So time to investigate the current state of play.
Believe it or not, I still have the old W98 machines mentioned above - both the 200MHz PI and the 333MHz Celeron, and they both work perfectly. Plus I have an old Compaq Evo sporting a Pentium IV with a basic W98 installation, and a HP DC7800 running XP - both were originally built for the workshop. So, personally, no problem - I am replete with crappy old PCs!
But for work, there's no way I'd be allowed to keep a bunch of old W98 or XP machines for this. If I am to resurrect the course, I need to move to W10. And I suspect that most people reading this would feel the same!
I started by hooking up my W98 EVO and getting it to the point where I could assemble code and programme a PIC - this proved that my home-made JDM programmer still worked. Then I repeated that on the XP machine, which at least gave me better plug-and-play, so it works with most of my USB memory sticks (my version of W98 is the original, so USB support is somewhat patchy).
Next, Windows 10. What about Vista, 7 and 8, you might cry? No point - we don't have W7 at work any more. The less said about Vista and 8, the better!
Here is where things get tricky. I started experimenting with a 32 bit machine first to give myself the best chance, but obviously everyone will be using 64 bit now, so that's the eventual end game.
OS | ConTEXT | MPASM | IC-Prog (with JDM programmer) |
---|---|---|---|
W98 | Yes | Yes | Yes |
XP 32 bit | Yes | Yes | Yes, with ic-prog.sys |
W10 32 bit | Yes | Yes | No! |
W10 64 bit | Yes | Yes | No! |
So, if we could just persuade the person behind IC-Prog to make it work with W10, all would be well with the world!
When you run it up, you get the expected "Privileged instruction" messages that happen on NT-based systems, which tells you that you need to enable the NT driver in the options dialogue. But having done that, you get this error message:
For the web crawlers, that's "Error occured (The system cannot find the file specified.) while loading driver!"
And after that, you continue to get the "Privileged instruction" messages which serve to confirm that the driver definitely did not load. That's a shame - I really like IC-Prog. But I completely understand that life causes priorities to change - I'm sure we can all empathise with that! At the very least I'm grateful the website hosting it still exists, which must be costing the author time and money to maintain.
Alternative programmers
Being philosophical, you could argue that IC-Prog's incompatibility with W10 is a blessing in disguise, as serial ports in 2023 are a rare sight. Compared to the myriad serial (and parallel) port options I found 20 years ago, DIY USB programmers are much thinner on the ground, but this option looks really interesting: Open Programmer. I hope to find the time to investigate further...
I did have an old Microchip PICkit 1 that was bought in a clearout sale for next to nothing, but I never got around to investigating it before. It's basically a very simple programmer with a couple of PICs included (an 8-pin PIC12F675 and a 14 pin PIC16F684), plus a few LEDs and a prototype area that can be snapped away and used separately. But the programming software only supports a number of 8 and 14 pin chips. I did try plugging up a couple of different devices via jumpers on a breadboard, but didn't have much luck. Also, as far as I've been able to establish so far, the software - apparently written in Visual Basic - does not support command-line arguments, so I can't invoke it from within ConTEXT and have it automatically load the .HEX file. So that's an extra set of steps that I'd have to take after assembling the ASM file. Sounds trivial, but would quickly get really boring.
OK, so what about newer PICkits? At the time of writing - September 2023 - the PICkit 4 is ending production but is still widely available. Whereas the PICkit 5 has recently been released, but is not so easy to buy at the moment - that will change soon, I'm sure. So let's try V4. If it works, it's likely V5 will be much the same.
MPLAB X and XC8
Picking up the PICkit 4 prompted me to download the latest version of MPLAB. This is where I started getting grumpy! Re-reading my earlier comments, I see that I was very diplomatic about the earlier versions - truth is, I didn't like it then, and I like it even less now! It's a massive download (about a GB), takes an age to install, and is extremely complicated for a simple idiot like me! A quick search shows that I'm not alone here...
Allow me to explain something. I am an engineer. I am not a programmer. Therefore, I like things to be simple and accessible. I don't like things to be abstracted from me - I wouldn't be programming microcontrollers in assembly language if I did!
But if you are a programmer, you might feel right at home with MPLAB. It's a project-based workflow, which is the norm for most programming languages. For higher level languages, I kind-of understand that you need something to help take care of all the various header and include files, but for what I do, it's far too complicated. I write one .ASM file. It "includes" the include file for the relavent PIC, which is supplied with the assembler. I am fully aware of (and comfortable with) the idea that I could write my own include files containing snippets of code that I re-use, but I generally prefer to just copy-paste into the main file and have it all in front of me. Yes, this might not be a realistic approach for larger projects, but these are small 8 bit microcontrollers!
OK, perhaps that's a "me problem", as my kids would enjoy telling me. But it gets worse. Upon installing MPLAB X, there's no assembler! So you have to install a C compiler. Because that makes total sense to someone who wants to write assembly! But that's how it works now - the C compiler includes the assember too.
This C compiler is called XC8. And as you'll see, there are free options and paid options, depending on how good a job you want the C compiler to do for you. The modern way, I guess. Luckily, I have little interest in C as I'm a masochist!
But the assembler has changed! Code written for MPASM will not compile under XC8. You can read about these changes here: MPASM to MPLAB XC8 PIC Assembler Migration Guide 50002973A.pdf.
MPASM
Luckily, Microchip maintain an archive of previous versions of MPLAB, so you are able to download something that isn't using XC8. The latest non-X version is 8.92.
When you install it, the setup program allows you to choose what components to install, and if you're careful, you can just install MPASM, meaning you have the assembler but not the IDE.
Remembering my advice above to search the Microchip site for MPASM as a single download, I was impressed to find that this still works. The search results is a direct link to asm21500.zip, and I copied the contents of that directly to C:\Program Files\Microchip\MPASM on my 32 bit W10 machine. Upon first run it said it needed NTVDM, which it automatically installed. After which, I saw my old friend again! Version 2.15, as the file name implies. But that is really quite an old version now - note the screenshot from my W98 machine taken some 20 years ago shows version 3.20.07, and the version that comes with MPLAB 8.92 is 5.51. So while this download is probably OK if you're using older PICs, it is of limited utility today - perhaps if you really need to avoid the full MPLAB download (version 8.92 is 111MB).
PICkit 4 programmer
Enough moaning about MPLAB! At least we can get the legacy MPASM assembler on its own. But what about the programmer?
Sadly, I'm not aware of any 3rd-party software that works with the Microchip hardware - neither the PICkit 1 mentioned above, nor the PICkit 4. But after the MPLAB X install, I did spot something called IPE, which stands for Integrated Programming Environment, and is a stand-alone programmer that get installed as part of the MPLAB install (sadly, I don't think it's available as a separate download, but I believe that you don't have to install MPLAB X to get IPE). This allows you to import .HEX files and programme them. And I've seen that it accepts command-line options, which hopefully allows integration with ConTEXT. I'm still working on this, but I'm optimistic about it being a viable solution. It's based on ipecmd.exe.
Another option
The earlier PICkit 3 was very popular. Today, it is long out of production, but £30 gets you a Chinese clone. This can be used with the Microchip software, but there are 3rd-party options, such as PICkitPlus and PICkit-. I'm quite tempted to pick up a clone to see how they go - while I wouldn't risk them for work, they might be a cheap solution for home that avoides the "heavyweight" Microchip software.
Provisional conclusion
So to wrap this up, here's what I've found so far:
OS | ConTEXT | MPASM | IC-Prog | PICkit 1* | PICkit 4 |
---|---|---|---|---|---|
W98 | Yes | Yes | Yes | No | No |
W98 SE | Yes | Yes | Yes | Yes | No |
XP 32 bit | Yes | Yes | Yes, with ic-prog.sys | Yes | No |
W10 32 bit | Yes | Yes | No | Yes | Not tested |
W10 64 bit | Yes | Yes | No | Yes | Yes |
*: Limited device support
So it looks like my best options are:
- Use my XP machine, with ConTEXT, MPASM, IC-Prog and my JDM programmer
- Use my W10 64 bit machine, with ConTEXT, MPASM, IPE, and the PICkit 4 (or 5) programmer
For work, the latter option is the only one, but at home I have the choice. In the interests of progressing the project that dragged me back into the PIC world, I will probably stick with Option 1 in the short term, but as there isn't really space on the bench for the extra XP machine, I plan to migrate to W10 eventually.