PIC18F4585: 48 KB in Four 12 KB Blocks, Not Six 8 KB

Everyone who works on 32 KB PIC18 parts learns one rule: a protected block reads as zeros, and blocks are 8 KB. Then a 48 KB part arrives and the rule produces the wrong answer, because 48 divides into four 12 KB blocks.

The PIC18F4585 belongs to the PIC18F2585/4585/2680/4680 family, DS39625. It carries 48 KB of flash as 24,576 instruction words, 3,328 bytes of RAM, 1,024 bytes of data EEPROM, eleven 10-bit ADC channels, one CCP and one ECCP, a parallel slave port, an ECAN module and a 40 MHz core. The 40-pin package and the CAN block put it in the same sockets as a great deal of industrial control hardware.

The Blocks Are Quarters, Not Units

Block Byte range Words Bit
0 0x000000–0x002FFF 6,144 CP0
1 0x003000–0x005FFF 6,144 CP1
2 0x006000–0x008FFF 6,144 CP2
3 0x009000–0x00BFFF 6,144 CP3

The array is divided into four equal parts regardless of its size. On a 16 KB device each part is 4 KB; on a 32 KB device each is 8 KB; on this one each is 12 KB. The bits are in CONFIG5L at 0x300008, with CPB and CPD in CONFIG5H at 0x300009.

Twelve kilobytes is 6,144 words, which is not a power of two. That single fact explains most of the bad conclusions drawn about this part.

Why the Wrong Ruler Fails

The standard completeness check on a PIC18 dump is to look for a run of 0x0000 that starts and ends on a boundary. On a 4585, someone applying 4 KB or 8 KB boundaries finds nothing — the locked quarter begins at 0x3000, which is not divisible by 8,192 — and concludes the image is clean.

Worse, the analysis tool may be reporting the image as six 8 KB segments because that is how it was written for the 32 KB parts. The segment boundaries land inside real code, every segment passes, and a missing 12 KB of firmware ships to a customer.

The correct boundaries are 0x2FFF, 0x5FFF, 0x8FFF and the end of the array at 0xBFFF. Nothing else.

Partial Protection Is the Normal Case

A 4585 with a CAN bootloader usually protects the top block only. The bootloader is the part of the product the vendor cares about; the application can be reflashed over the bus and is treated as less sensitive. CP3 set gives you exactly that: 0x9000–0xBFFF returns zeros, the other 36 KB reads normally.

From the outside, such a part looks fully protection levels free — ICSP reads succeed, most addresses return data, and a programmer reports no error. Only a boundary check shows that the last quarter is a refusal. This is the most common protection state on industrial CAN hardware and the most commonly misread one.

The 1,024 Bytes Beside It

Data EEPROM on this part is 1 KB, four times the size on the 32 KB devices, and it is where parameter sets live: PID gains, CAN node identity, calibration tables, occasionally a full copy of the configuration image so the unit can restore itself after a firmware update.

CPD in CONFIG5H protects it independently. Note the read values: an erased EEPROM byte is 0xFF, a protected one is 0x00. A delivered file with 1,024 zero bytes in the EEPROM region is not a wiped parameter set, it is a locked one, and it needs a second operation to recover.

The Relatives

The PIC18F2585 is the 28-pin member of the same family with the same 48 KB array and the same block structure, so a 2585 image and a 4585 image differ in port usage rather than in size. The PIC18F2680 shares the datasheet too, at 64 KB — one block larger in total, still quartered, which means its blocks are 16 KB.

That is the rule to carry away: block size is array size divided by four, and it changes with every part number in the family.

What to Send

A photograph of the marking, the board, and any note about which regions the original programmer refused. If the file already exists, report the highest address and the byte ranges that read as uniform zeros; from those two facts the protection state can be reconstructed without opening anything. The services page sets out what a delivered image contains.

Service scope and next steps

PIC parts from the 16F, 18F and 32F families are handled on the same bench every week. We identify the exact device revision, check the read-protection level, and confirm the flash layout before quoting. 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.

Need a PIC part read?

Send us the part number and a short description of what you need. Free evaluation, fixed quotation, and a reply within one business day.

Request a quotation

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *