PIC18 handheld debugger


...for a long time, I dreamt of a small device, which could be programmed in some kind of programming language, a device which could be taken everywhere, that would fit my hand, portable and independent from electrical network, etc... While there are lots of PDA class computers, smart (whatever it means) phones and small netbooks, which could serve for this, all that doesn’t exhibit one important feature - to be DIY hand made. That time (I was maybe 14 or 15 years old) I had no clue about microcontrollers nor microprocessors so all those thoughts remained just dreams. Now things slightly changed. While studying university I made a small device, consisting of 8052 basic module (compressed into one 89C51RD2 device, really single-chip solution) with 18F2620, 2x16 alphanumeric LCD and keypad display serving as terminal, plus some other components (PSU, RS232 interface etc.) forming a small computer-like device, and I was able to program it in BASIC. A lot of people asked me, what is it good for... well, for nothing. There is no real reason for doing something like that, except of good feeling after completing a device, which really works, stretching a brain, hobby or whatever you call it. But after all, I felt unsatisfied with that and want something more.
I took a 18F2620 (yes, my favorite that time), added a keypad and display and wrote a small program, which enabled me to change a portion of RAM – all done in means of hexadecimal numbers, then I could burn this image into FLASH and jump at this address – sort of monitor program, like WOZMON for Apple1 computer. Writing in machine code could be interesting as well as annoying and slow, so I felt something like small assembler would be great. First I looked for assembler, which could fit into a few kilobytes of RAM, but how wrong I was! I decided to write my own. I won’t bother you with this task, it took me a few weeks to write a small assembler for 18F devices, which could fit into RAM of PIC18F2620, after leaving a 2kB of RAM for program buffer! It was a pretty poor-featured assembler, but worked after all.
Well, nice tool-chain on chip... editor, assembler and burner. Debugger would be nice, but who knows, how to? Except of Microchip guys, probably nobody. There is NO specification for on-chip debug module contained in every single PIC18. There is only official debug specification for PIC16F87x from Microchip, so this would be a first attempt to give a more-less complete description of debug mode for PIC18 family.
Fortunately, in that time I found book, which was miraculous for me... Coin-Cell-Powered Embedded design by John Peatman. To be honest, most exciting for me wasn’t that design, covered in book, but the mention of debug mode in monitor (QwikBug), which serves as basis for those project, really got me. I downloaded sources and started to study. I was unsure about a few things, so I nicely asked Microchip, whether they could send me a description of debug mode for 18F PICs. First of all they treated me like a complete idiot (just got response that resources needed by ICD2 debugger can be found somewhere in help –  not what I asked) and when I asked again, they responded that they don’t have any debugging specification and my support ticked was closed. Great support, I must admit! Well, help yourself, little man.
So I returned back into studying sources for QwikBug, disassembling hex-binaries from PicKit2 directory (debug executives for various PICs) and ICD2 as well, studying sources for PicKit2, and .xml files. I also wrote to John Peatman, who gave me a few valuable comments. This was still incomplete source. After a long, long and again long days and nights spent with this and after a unbelievable amount of experiments I finally got that damned PIC to enter debug mode by itself.
Then I found out that debugging PIC by itself wouldn’t be easy, and if it would be easy, then it wouldn’t be useful and if it even would be useful, it will not be useful very much. So I decided to decline my way of single-chip tool-chain and soldered another PIC into my breadboard, as a slave device to be debugged.

Then started another long story, consisting of writing debug executive for slave PIC and complete debug engine for master PIC. It took me a lot of time to get functional couple debugger-target and I must admit that this, along with reverse engineering of debug specifications for PIC18 was the most challenging task I ever did in my short life (27 years now) – I started with a few incomplete information all around and finished with working system.
Then came some small “cosmetic” changes, like porting whole editor-assembler-burner-debugger into dsPIC33FJ128GP802 – just because of more RAM, more horse power (for assembler and debugger), adding a bigger display, writing a GUI for debugger and so on. After all this my new PIC18 debugger is done. If you wish to know, how it looks and how it works, look here - few images and comments.

Currently it supports just PIC18F4620 family, PIC18F46K20 family and PIC18F45K10 family. PIC16F probably will not be supported, as I’m lazy to redesign assembler and what is more, it seems that debugging various of those MCUs is much more diverse than for 18F. 16-bit PIC definitely will not be supported, as I don’t have a clue about debugging of them, as well as changes to assembler would be really dramatic (lots of opcodes and addressing modes).
Only single-supply ICSP is supported (using PGM), but it would be easy to change it into high-voltage ICSP, but I was lazy to include Vpp supply on board.


Updated 20.2.2011
Back to P18debug