The 4220 and the 4221 look interchangeable on paper: both 40-pin, both 36 I/O, both 4 KB of flash with 512 bytes of RAM and 256 bytes of EEPROM. They are not interchangeable as binaries. They are two different silicon families with different register maps and different config-word layouts, and a hex file taken from one will not run correctly on the other.
This matters because the substitution is such an obvious move. An obsolete PIC18F4220 board needs a new controller, the 4221 is in stock in the same package, and the assumption is that the program moves across. It does not, and finding that out after a production run has been built is an expensive way to learn it.
Where They Actually Differ
The two belong to separate datasheets, which is the cleanest signal that the internals diverged. The 4221 family adds the enhanced CCP module, moves to an enhanced USART with LIN support, and brings the nanoWatt power-management set — all of which live in registers that the 4220 either lacks or defines differently.
The consequence is not a missing pin. It is code that branches into an interrupt vector expecting one register layout and finds another. Symptoms at bring-up are consistent and misleading: the part boots, drives some I/O, then hangs in a loop that looks like a watchdog reset. Engineers usually blame the crystal first.
Config words are the second trap. The oscillator mode, brown-out threshold and protection bits are all encoded in CONFIG1H onward, and the bit assignments are not identical across the two families. Program a 4220’s config block into a 4221 and the clock source may come up as something the board was never designed around.
What Does Transfer
The 256-byte data EEPROM usually does move — it is a flat parameter block, not code — and that is often the most valuable single item on the device, because it carries the serial number, the run-hour counter and the user thresholds.
That block is also what makes a partial approach workable: read the 4221’s own flash for the program, and transplant the parameter values from the 4220 if the customer wants the replacement to carry the same identity. It is a two-part job, not a copy-and-paste.
Confirming which part is on the board takes one command, not a datasheet crawl. The device ID sits at 0x3FFFFE and reads back over the programming interface even when the array is protected, so a programmer reports the family and revision before anyone commits to a plan. Two boards that look identical on the silkscreen routinely return different IDs.
The Right Question to Ask First
Before quoting anything, establish which device the working board actually carries. Suffixes and second sources make this less obvious than it sounds, and the marking on a 15-year-old part is often the only reliable record.
If the target is a 4221, the program has to come from a 4221 — either read the firmware out of one, or rebuild it from source if the customer still has it. If the goal is only to keep an existing 4220 board alive, the newer 8 KB PIC18F4321 is the same family as the 4221 and shares its toolchain, which changes the migration arithmetic again.
On Protection
Devices of this generation are normally protected through CP0–CP3 in CONFIG5L, with CPB covering the boot block and CPD covering the EEPROM. At 4 KB there is effectively one block, so the state is binary — open, or closed — and the copy protection scheme tells you which config bytes to look at before anything is opened.
If the CPD bit is clear, the parameter block can be lifted through the normal programming interface with no package work at all. That is worth checking first: it is the cheapest possible outcome and it sometimes covers the whole job.
Send the marking photograph and the ordering suffix, and say which part the replacement board will use. The services page sets out what comes back and in which format.
Service scope and next steps
Before we quote a PIC job we confirm the silicon revision and the protection configuration, because both decide whether the on-chip programming area can be read directly or needs a different approach. The full scope of what we handle, how a project runs from electrical integrity test to delivered file, and the payment terms are described on our service capabilities page.
Ready to extract this PIC firmware?
Send us the part number and a short description of what you need. Free evaluation, fixed quotation, and a reply within one business day.

Leave a Reply