The lesson for my future PCBs is to not trust the bootloader exclusively. If the code gets scrambled the bootloader fails and you are up that famous creek.

A trawl of the Melabs site ended up at http://www.melabs.com/support/meprogfixes.htm where I found....

Programming Errors:

"Target device does not match selected device." - This indicates that the programmer has read an unexpected device id from the target PIC®. Make sure you've selected the correct device in the dropdown list on the toolbar. You will also get this error if the programmer can't put the PIC into programming mode. This can be caused by low power supply voltage, a defective PIC, incorrect placement of the PIC in the programming socket, or a bad in-circuit programming connection.

Problems specific to PIC18F1220, 18F1320, 18F2220, 18F2320, 18F2620 and 18F4620 can sometimes be fixed with a small modification to your Serial Programmer board.

I added the capacitor and squeaked the voltage up a bit ( I have parts on the board rated MAX 3.7 volts) and hey presto it works now.

Having got the ICSP attached I could read the PIC EEROM and program memory. This showed some unextected results. The first 60 bytes or thereabouts of program space look like code but from there to top of memory, the PIC reads FF in every cell. Somehow the code initiated an 'erase mem' comand. The EEROM was correct except for three cells which are frequently read but very rarely if ever written to.

My next PCB will have accessible pads for PGC, PGD, Vss, Vdd and Reset to allow attaching the ICSP when/if the bootloader fails. That will be very tight on an already crowded board.

I think the mixing of 5 volt programmers with 3.3 volt boards will lead to more of these subtle problems.

Brian