This document defines the programming specification
for the PIC24FJXXXGA1/GB1 families of 16-bit
microcontroller devices. This programming specification
is required only for those developing programming
support for the PIC24FJXXXGA1/GB1 families.
Customers using only one of these devices should use
development tools that already provide support for
device programming.
This specification includes programming specifications
for the following devices:
• PIC24FJ256GA106• PIC24FJ256GB106
• PIC24FJ256GA108• PIC24FJ256GB108
• PIC24FJ256GA110• PIC24FJ256GB110
• PIC24FJ192GA106• PIC24FJ192GB106
• PIC24FJ192GA108• PIC24FJ192GB108
• PIC24FJ192GA110• PIC24FJ192GB110
• PIC24FJ128GA106• PIC24FJ128GB106
• PIC24FJ128GA108• PIC24FJ128GB108
• PIC24FJ128GA110• PIC24FJ128GB110
• PIC24FJ64GB106• PIC24FJ64GB108
• PIC24FJ64GB110
2.0PROGRAMMING OVERVIEW
OF THE PIC24FJXXXGA1/GB1
FAMILIES
There are two methods of programming the
PIC24FJXXXGA1/GB1 families of devices discussed
in this programming specification. They are:
• In-Circuit Serial Programming™ (ICSP™)
• Enhanced In-Circuit Serial Programming
(Enhanced ICSP)
The ICSP programming method is the most direct
method to program the device; however, it is also the
slower of the two methods. It provides native, low-level
programming capability to erase, program and verify
the chip.
The Enhanced In-Circuit Serial Programming
(Enhanced ICSP) protocol uses a faster method that
takes advantage of the programming executive, as
illustrated in Figure 2-1. The programming executive
provides all the necessary functionality to erase, program and verify the chip through a small command set.
The command set allows the programmer to program
the PIC24FJXXXGA1/GB1 devices without having to
deal with the low-level programming protocols of the
chip.
FIGURE 2-1:PROGRAMMING SYSTEM
PIC24FJXXXGA1/GB1
Programming
Executive
OVERVIEW FOR
ENHANCED ICSP™
On-Chip Memory
Programmer
This specification is divided into major sections that
describe the programming methods independently.
Section 4.0 “Device Programming – Enhanced
ICSP” describes the Run-Time Self-Programming(RTSP) method. Section 3.0 “Device Programming –
ICSP” describes the In-Circuit Serial Programming
All devices in the PIC24FJXXXGA1/GB1 families are
dual voltage supply designs: one supply for the core
and peripherals and another for the I/O pins. A regulator is provided on-chip to alleviate the need for two
external voltage supplies.
All PIC24FJXXXGA1/GB1 devices power their core
digital logic at a nominal 2.5V. To simplify system
design, all devices in the PIC24FJXXXGA1/GB1 families incorporate an on-chip regulator that allows the
device to run its core logic from V
DD.
The regulator provides power to the core from the other
VDD pins. A low-ESR capacitor (such as tantalum) must
be connected to the V
DDCORE pin (Table 2-1 and
Figure 2-2). This helps to maintain the stability of the
regulator. The specifications for core voltage and capacitance are listed in Section 7.0 “AC/DC Characteristics
and Timing Requirements”.
2.2Program Memory Write/Erase
Requirements
The Flash program memory on PIC24FJXXXGA1/GB1
devices has a specific write/erase requirement that
must be adhered to for proper device operation. The
rule is that any given word in memory must not be written more than twice before erasing the page in which it
is located. Thus, the easiest way to conform to this rule
is to write all the data in a programming block within
one write cycle. The programming methods specified in
this specification comply with this requirement.
Note:Writing to a location multiple times without
erasing is not recommended.
2.3Pin Diagrams
FIGURE 2-2:CONNECTIONS FOR THE
ON-CHIP REGULATOR
Regulator Enabled (ENVREG tied to VDD):
3.3V
CEFC
(10
μF typ)
Regulator Disabled (ENVREG tied to ground):
(1)
2.5V
Regulator Disabled (VDD tied to VDDCORE):
2.5V
3.3V
(1)
PIC24FJXXXGA1/GB1
VDD
ENVREG
V
DDCORE/VCAP
VSS
(1)
PIC24FJXXXGA1/GB1
VDD
ENVREG
V
DDCORE/VCAP
VSS
PIC24FJXXXGA1/GB1
VDD
ENVREG
VDDCORE/VCAP
VSS
The pin diagrams for the PIC24FJXXXGA1/GB1 families are shown in the following figures. The pins that are
required for programming are listed in Table 2-1 and
are shown in bold letters in the figures. Refer to the
Note 1: These are typical operating voltages. Refer
Section 7.0 “AC/DC Characteristics and
to
Timing Requirements”
ranges of V
DD and VDDCORE.
for the full operating
appropriate device data sheet for complete pin
descriptions.
2.3.1PGCx AND PGDx PIN PAIRS
All of the devices in the PIC24FJXXXGA1/GB1 families
have three separate pairs of programming pins,
labelled as PGEC1/PGED1, PGEC2/PGED2, and
PGEC3/PGED3. Any one of these pin pairs may be
used for device programming by either ICSP or
Enhanced ICSP. Unlike voltage supply and ground
pins, it is not necessary to connect all three pin pairs to
program the device. However, the programming
method must use both pins of the same pair.
The program memory map extends from 000000h to
FFFFFEh. Code storage is located at the base of the
memory map and supports up to 87K instruction words
(about 256 Kbytes). Table 2-2 shows the program
memory size and number of erase and program blocks
present in each device variant. Each erase block, or
page, contains 512 instructions, and each program
block, or row, contains 64 instructions.
Locations 800000h through 8007FEh are reserved for
executive code memory. This region stores the
programming executive and the debugging executive.
The programming executive is used for device programming and the debugging executive is used for
in-circuit debugging. This region of memory can not be
used to store user code.
The last three implemented program memory locations
are reserved for the Flash Configuration Words. In
PIC24FJXXXGB1 family devices, the last three locations are used for the Configuration Words; for
PIC24FJXXXGA1 devices, the last two locations are
used. The reserved addresses are shown in Table 2-2.
Locations FF0000h and FF0002h are reserved for the
Device ID registers. These bits can be used by the
programmer to identify what device type is being
programmed. They are described in Section 6.1“Device ID”. The Device ID registers read out
normally, even after code protection is applied.
Figure 2-9 shows the memory map for the
PIC24FJXXXGA1/GB1 family variants.
TABLE 2-2:CODE MEMORY SIZE AND FLASH CONFIGURATION WORD LOCATIONS FOR
ICSP mode is a special programming protocol that
allows you to read and write to the memory of
PIC24FJXXXGA1/GB1 devices. The ICSP mode is the
most direct method used to program the device; note,
however, that Enhanced ICSP is faster. ICSP mode
also has the ability to read the contents of executive
memory to determine if the programming executive is
present. This capability is accomplished by applying
control codes and instructions, serially to the device,
using pins PGCx and PGDx.
In ICSP mode, the system clock is taken from the
PGCx pin, regardless of the device’s oscillator Configuration bits. All instructions are shifted serially into an
internal buffer, then loaded into the Instruction Register
(IR) and executed. No program fetching occurs from
internal memory. Instructions are fed in 24 bits at a
time. PGDx is used to shift data in and PGCx is used
as both the serial shift clock and the CPU execution
clock.
Note:During ICSP operation, the operating
frequency of PGCx must not exceed
10 MHz.
3.1Overview of the Programming
Process
Figure 3-1 shows the high-level overview of the
programming process. After entering ICSP mode, the
first action is to Chip Erase the device. Next, the code
memory is programmed, followed by the device
Configuration registers. Code memory (including the
Configuration registers) is then verified to ensure that
programming was successful. Then, program the
code-protect Configuration bits, if required.
FIGURE 3-1:HIGH-LEVEL ICSP™
PROGRAMMING FLOW
Start
Enter ICSP™
Perform Chip
Erase
Program Memory
Verify Program
Program Configuration Bits
Verify Configuration Bits
Exit ICSP
Done
3.2ICSP Operation
Upon entry into ICSP mode, the CPU is Idle. Execution
of the CPU is governed by an internal state machine. A
4-bit control code is clocked in using PGCx and PGDx,
and this control code is used to command the CPU (see
Table 3-1).
The SIX control code is used to send instructions to the
CPU for execution, and the REGOUT control code is
used to read data out of the device via the VISI register.
The SIX control code allows execution of PIC24F family
assembly instructions. When the SIX code is received,
the CPU is suspended for 24 clock cycles, as the instruction is then clocked into the internal buffer. Once the
instruction is shifted in, the state machine allows it to be
executed over the next four PGC clock cycles. While the
received instruction is executed, the state machine
simultaneously shifts in the next 4-bit command (see
Figure 3-2).
FIGURE 3-2:SIX SERIAL EXECUTION
4 5
231232324 1 2 3 4
16
PGCx
P3
P2
00
PGDx
0000
Execute PC – 1,
Fetch SIX
Control Code
78 9
Only for
Program
Memory Entry
P4
LSB X X X X X X X X X X X X X X MSB
P1A
P1B
Coming out of Reset, the first 4-bit control code is
always forced to SIX and a forced NOP instruction is
executed by the CPU. Five additional PGCx clocks are
needed on start-up, resulting in a 9-bit SIX command
instead of the normal 4-bit SIX command.
After the forced SIX is clocked in, ICSP operation
resumes as normal. That is, the next 24 clock cycles
load the first instruction word to the CPU.
Note:To account for this forced NOP, all example
P1
456 78 181920212217
24-Bit Instruction Fetch
PGDx = Input
code in this specification begins with a
NOP to ensure that no data is lost.
P4A
0000000
Execute 24-Bit
Instruction, Fetch
Next Control Code
3.2.1.1Differences Between Execution of
SIX and Normal Instructions
There are some differences between executing instructions normally and using the SIX ICSP command. As a
result, the code examples in this specification may not
match those for performing the same functions during
normal device operation.
The important differences are:
• Two-word instructions require two SIX operations
to clock in all the necessary data.
Examples of two-word instructions are GOTO and
CALL.
• Two-cycle instructions require two SIX operations.
The first SIX operation shifts in the instruction and
begins to execute it. A second SIX operation – which
should shift in a NOP to avoid losing data – provides
the CPU clocks required to finish executing the
instruction.
Examples of two-cycle instructions are table read
and table write instructions.
• The CPU does not automatically stall to account
for pipeline changes.
A CPU stall occurs when an instruction modifies a
register that is used for Indirect Addressing by the
following instruction.
During normal operation, the CPU automatically
will force a NOP while the new data is read. When
using ICSP, there is no automatic stall, so any
indirect references to a recently modified
register should be preceded by a NOP.
For example, the instructions, MOV #0x0,W0 andMOV [W0],W1, must have a NOP inserted
between them.
If a two-cycle instruction modifies a register that is
used indirectly, it will require two following NOPs: one
to execute the second half of the instruction and a
second to stall the CPU to correct the pipeline.
Instructions such as TBLWTL [W0++],[W1]
should be followed by two NOPs.
• The device Program Counter (PC) continues to
automatically increment during ICSP instruction
execution, even though the Flash memory is not
being used.
As a result, the PC may be incremented to point to
invalid memory locations. Invalid memory spaces
include unimplemented Flash addresses and the
vector space (locations 0x0 to 0x1FF).
If the PC points to these locations, the device will
reset, possibly interrupting the ICSP operation. To
prevent this, instructions should be periodically
executed to reset the PC to a safe space. The optimal method to accomplish this is to perform a
GOTO 0x200.
The REGOUT control code allows for data to be
extracted from the device in ICSP mode. It is used to
clock the contents of the VISI register, out of the device,
over the PGDx pin. After the REGOUT control code is
received, the CPU is held Idle for 8 cycles. After these
8 cycles, an additional 16 cycles are required to clock the
data out (see Figure 3-3).
The REGOUT code is unique because the PGDx pin is
an input when the control code is transmitted to the
device. However, after the control code is processed,
the PGDx pin becomes an output as the VISI register is
shifted out.
FIGURE 3-3:REGOUT SERIAL EXECUTION
PGCx
PGDx
123 41 278
P4
1
0
0
1231234
P5
1234
LSb
Note 1: After the contents of VISI are shifted out,
the PIC24FJXXXGA1/GB1 devices
maintain PGDx as an output until the first
rising edge of the next clock is received.
2: Data changes on the falling edge and
latches on the rising edge of PGCx. For
all data transmissions, the Least
Significant bit (LSb) is transmitted first.
As shown in Figure 3-4, entering ICSP Program/Verify
mode requires three steps:
1.MCLR
2.A 32-bit key sequence is clocked into PGDx.
3.MCLR
The programming voltage applied to MCLR is VIH,
which is essentially V
PIC24FJXXXGA1/GB1 devices. There is no minimum
time requirement for holding at VIH. After VIH is
removed, an interval of at least P18 must elapse before
presenting the key sequence on PGDx.
FIGURE 3-4:ENTERING ICSP™ MODE
MCLR
VDD
PGDx
PGCx
is briefly driven high, then low.
is then driven high within a specified
period of time and held.
DD in the case of
P6
P14
VIH
Program/Verify Entry Code = 4D434851h
010000
b31 b30 b29 b28 b27b2b1b0b3
P18
1
P1A
P1B
...
The key sequence is a specific 32-bit pattern:
‘0100 1101 0100 0011 0100 1000 0101 0001’
(more easily remembered as 4D434851h in hexadecimal). The device will enter Program/Verify mode only
if the sequence is valid. The Most Significant bit (MSb) of
the most significant nibble must be shifted in first.
Once the key sequence is complete, V
applied to MCLR
and held at that level for as long as
IH must be
Program/Verify mode is to be maintained. An interval of
at least time, P19 and P7, must elapse before presenting data on PGDx. Signals appearing on PGCx before
P7 has elapsed will not be interpreted as valid.
On successful entry, the program memory can be
accessed and programmed in serial fashion. While in
ICSP mode, all unused I/Os are placed in the
high-impedance state.
Flash memory write and erase operations are controlled
by the NVMCON register. Programming is performed by
setting NVMCON to select the type of erase operation
(Table 3-2) or write operation (Table 3-3) and initiating
the programming by setting the WR control bit
(NVMCON<15>).
In ICSP mode, all programming operations are
self-timed. There is an internal delay between the user
setting the WR control bit and the automatic clearing of
the WR control bit when the programming operation
is complete. Please refer to Section 7.0 “AC/DCCharacteristics and Timing Requirements” for
information about the delays associated with various
programming operations.
TABLE 3-2:NVMCON ERASE
OPERATIONS
NVMCON
Value
404FhErase all code memory, executive
memory and Configuration registers
(does not erase Unit ID or Device ID
registers).
4042hErase a page of code memory or
executive memory.
TABLE 3-3:NVMCON WRITE
NVMCON
Value
Erase Operation
OPERATIONS
Write Operation
3.5Erasing Program Memory
The procedure for erasing program memory (all of code
memory, data memory, executive memory and
code-protect bits) consists of setting NVMCON to
404Fh and executing the programming cycle.
A Chip Erase can erase all of user memory or all of both
the user and configuration memory. A table write
instruction should be executed prior to performing the
Chip Erase to select which sections are erased.
When this table write instruction is executed:
• If the TBLPAG register points to user space (is
less than 0x80), the Chip Erase will erase only
user memory.
• If TBLPAG points to configuration space (is
greater than or equal to 0x80), the Chip Erase will
erase both user and configuration memory.
If configuration memory is erased, the internal
oscillator Calibration Word, located at 0x807FE,
will be erased. This location should be stored prior
to performing a whole Chip Erase and restored
afterward to prevent internal oscillators from
becoming uncalibrated.
Figure 3-5 shows the ICSP programming process for
performing a Chip Erase. This process includes the
ICSP command code, which must be transmitted (for
each instruction), Least Significant bit first, using the
PGCx and PGDx pins (see Figure 3-2).
Note:Program memory must be erased before
writing any data to program memory.
FIGURE 3-5:CHIP ERASE FLOW
Start
4003hWrite a Configuration Word register.
4001hProgram 1 row (64 instruction words) of
code memory or executive memory.
3.4.2STARTING AND STOPPING A
PROGRAMMING CYCLE
The WR bit (NVMCON<15>) is used to start an erase or
write cycle. Setting the WR bit initiates the programming
cycle.
All erase and write cycles are self-timed. The WR bit
should be polled to determine if the erase or write cycle
has been completed. Starting a programming cycle is
performed as follows:
The procedure for writing code memory is the same as
the procedure for writing the Configuration registers,
except that 64 instruction words are programmed at a
time. To facilitate this operation, working registers,
W0:W5, are used as temporary holding registers for the
data to be programmed.
Table 3-5 shows the ICSP programming details, including the serial pattern with the ICSP command code
which must be transmitted, Least Significant bit first,
using the PGCx and PGDx pins (see Figure 3-2).
In Step 1, the Reset vector is exited. In Step 2, the
NVMCON register is initialized for programming a full
row of code memory. In Step 3, the 24-bit starting destination address for programming is loaded into the
TBLPAG register and W7 register. (The upper byte of
the starting destination address is stored in TBLPAG
and the lower 16 bits of the destination address are
stored in W7.)
To minimize the programming time, a packed instruction
format is used (Figure 3-6).
In Step 4, four packed instruction words are stored in
working registers, W0:W5, using the MOV instruction,
and the Read Pointer, W6, is initialized. The contents of
W0:W5 (holding the packed instruction word data) are
shown in Figure 3-6.
In Step 5, eight TBLWT instructions are used to copy the
data from W0:W5 to the write latches of code memory.
Since code memory is programmed 64 instruction
words at a time, Steps 4 and 5 are repeated 16 times to
load all the write latches (Step 6).
After the write latches are loaded, programming is
initiated by writing to the NVMCON register in Steps 7
and 8. In Step 9, the internal PC is reset to 200h. This
is a precautionary measure to prevent the PC from
incrementing into unimplemented memory when large
devices are being programmed. Lastly, in Step 10,
Steps 3-9 are repeated until all of code memory is
programmed.
FIGURE 3-6:PACKED INSTRUCTION
WORDS IN W0:W5
158 70
W0LSW0
W1MSB1MSB0
W2LSW1
W3LSW2
W4MSB3MSB2
W5LSW3
TABLE 3-5:SERIAL INSTRUCTION EXECUTION FOR WRITING CODE MEMORY
Command
(Binary)
Step 1: Exit the Reset vector.
0000
0000
0000
Step 2: Set the NVMCON to program 64 instruction words.
0000
0000
Step 3: Initialize the Write Pointer (W7) for TBLWT instruction.
0000
0000
0000
Step 4: Load W0:W5 with the next 4 instruction words to program.
Device configuration for PIC24FJXXXGA1/GB1 devices
is stored in Flash Configuration Words at the end of the
user space program memory, and in multiple register
Configuration Words located in the test space. These
registers reflect values read at any Reset from program
memory locations. The values for the Configuration
Words for the default device configurations are listed in
Table 3-6.
The values can be changed only by programming the
content of the corresponding Flash Configuration Word
and resetting the device. The Reset forces an automatic
reload of the Flash stored configuration values by
sequencing through the dedicated Flash Configuration
Words and transferring the data into the Configuration
registers.
For the PIC24FJXXXGA1/GB1 families, certain Configuration bits have default states that must always be
maintained to ensure device functionality, regardless of
the settings of other Configuration bits. These bits and
their values are listed in Table 3-7.
To change the values of the Flash Configuration Word
once it has been programmed, the device must be Chip
Erased, as described in Section 3.5 “Erasing ProgramMemory”, and reprogrammed to the desired value. It is
not possible to program a ‘0’ to ‘1’, but they may be
programmed from a ‘1’ to ‘0’ to enable code protection.
Table 3-8 shows the ICSP programming details for programming the Configuration Word locations, including
the serial pattern with the ICSP command code which
must be transmitted, Least Significant bit first, using the
PGCx and PGDx pins (see Figure 3-2).
In Step 1, the Reset vector is exited. In Step 2, the
NVMCON register is initialized for programming of
code memory. In Step 3, the 24-bit starting destination
address for programming is loaded into the TBLPAG
register and W7 register.
The TBLPAG register must be loaded with the
following:
• 64 Kbyte devices: 00h
• 128, 192 and 256 Kbyte devices: 01h
To verify the data by reading the Configuration Words
after performing the write in order, the code protection
bits initially should be programmed to a ‘1’ to ensure
that the verification can be performed properly. After
verification is finished, the code protection bit can be
programmed to a ‘0’ by using a word write to the
appropriate Configuration Word.
TABLE 3-6:DEFAULT CONFIGURATION
REGISTER VALUES
AddressNameDefault Value
Last WordCW17FFFh
Last Word – 2CW2F7FFh
Last Word – 4CW3FFFFh
TABLE 3-7:RESERVED CONFIGURATION
BIT LOCATIONS
Bit LocationValue
CW1<15>0
CW1<10>1
CW2<11>0
CW2<2>
Note 1:This bit is implemented as I2C2SEL on
(1)
PIC24FJXXXGA110 devices, and should
be programmed as required.
Reading from code memory is performed by executing
a series of TBLRD instructions and clocking out the data
using the REGOUT command.
Table 3-9 shows the ICSP programming details for
reading code memory. In Step 1, the Reset vector is
exited. In Step 2, the 24-bit starting source address for
reading is loaded into the TBLPAG register and W6
register. The upper byte of the starting source address
is stored in TBLPAG and the lower 16 bits of the source
address are stored in W6.
To minimize the reading time, the packed instruction
word format that was utilized for writing is also used for
reading (see Figure 3-6). In Step 3, the Write Pointer,
W7, is initialized. In Step 4, two instruction words are
read from code memory and clocked out of the device,
through the VISI register, using the REGOUT
command. Step 4 is repeated until the desired amount
of code memory is read.
TABLE 3-9:SERIAL INSTRUCTION EXECUTION FOR READING CODE MEMORY
Command
(Binary)
Step 1: Exit Reset vector.
0000
0000
0000
Step 2: Initialize TBLPAG and the Read Pointer (W6) for TBLRD instruction.
0000
0000
0000
Step 3: Initialize the Write Pointer (W7) to point to the VISI register.
0000
0000
Step 4: Read and clock out the contents of the next two locations of code memory, through the VISI register, using
TBLRDL[W6], [W7]
NOP
NOP
Clock out contents of VISI register
NOP
TBLRDH.B[W6++], [W7++]
NOP
NOP
TBLRDH.B[++W6], [W7--]
NOP
NOP
Clock out contents of VISI register
NOP
TBLRDL[W6++], [W7]
NOP
NOP
Clock out contents of VISI register
NOP
The procedure for reading configuration memory is
similar to the procedure for reading code memory,
except that 16-bit data words are read (with the upper
byte read being all ‘0’s) instead of 24-bit words.
Configuration Words are read one register at a time.
Table 3-10 shows the ICSP programming details for
reading the Configuration Words. Note that the
TBLPAG register must be loaded with 00h for 64 Kbyte
and below devices and 01h for 128 Kbyte and larger
devices (the upper byte address of configuration memory), and the Read Pointer, W6, is initialized to the
lower 16 bits of the Configuration Word location.
TABLE 3-10:SERIAL INSTRUCTION EXECUTION FOR READING ALL CONFIGURATION MEMORY
Command
(Binary)
Step 1: Exit Reset vector.
0000
0000
0000
Step 2: Initialize TBLPAG, the Read Pointer (W6) and the Write Pointer (W7) for TBLRD instruction.
0000
0000
0000
0000
0000
Step 3: Read the Configuration register and write it to the VISI register (located at 784h), and clock out the
VISI register using the REGOUT command.
0000
0000
0000
0001
0000
Step 4: Repeat Step 3twice to read Configuration Word 2 and Configuration Word 1.
The verify step involves reading back the code memory
space and comparing it against the copy held in the
programmer’s buffer. The Configuration registers are
verified with the rest of the code.
The verify process is shown in the flowchart in
Figure 3-8. Memory reads occur a single byte at a time,
so two bytes must be read to compare against the word
in the programmer’s buffer. Refer to Section 3.8“Reading Code Memory” for implementation details
of reading code memory.
Note:Because the Configuration registers
include the device code protection bit,
code memory should be verified immediately after writing if code protection is
enabled. This is because the device will
not be readable or verifiable if a device
Reset occurs after the code-protect bit in
CW1 has been cleared.
FIGURE 3-8:VERIFY CODE
MEMORY FLOW
Start
Set TBLPTR = 0
3.11Reading the Application ID Word
The Application ID Word is stored at address 8005BEh
in executive code memory. To read this memory
location, you must use the SIX control code to move
this program memory location to the VISI register.
Then, the REGOUT control code must be used to clock
the contents of the VISI register out of the device. The
corresponding control and instruction codes that must
be serially transmitted to the device to perform this
operation are shown in Table 3-11.
After the programmer has clocked out the Application
ID Word, it must be inspected. If the Application ID has
the value, BBh, the programming executive is resident
in memory and the device can be programmed using
the mechanism described in Section 4.0 “DeviceProgramming – Enhanced ICSP”. However, if the
Application ID has any other value, the programming
executive is not resident in memory; it must be loaded
to memory before the device can be programmed. The
procedure for loading the programming executive to
memory is described in Section 5.4 “Programming
the Programming Executive to Memory”.
3.12Exiting ICSP Mode
Exiting Program/Verify mode is done by removing VIH
from MCLR, as shown in Figure 3-9. The only requirement for exit is that an interval, P16, should elapse
between the last clock and program signals on PGCx
and PGDx before removing V
This section discusses programming the device
through Enhanced ICSP and the programming executive. The programming executive resides in executive
memory (separate from code memory) and is executed
when Enhanced ICSP Programming mode is entered.
The programming executive provides the mechanism
for the programmer (host device) to program and verify
the PIC24FJXXXGA1/GB1 devices using a simple
command set and communication protocol. There are
several basic functions provided by the programming
executive:
• Read Memory
• Erase Memory
• Program Memory
• Blank Check
• Read Executive Firmware Revision
The programming executive performs the low-level
tasks required for erasing, programming and verifying
a device. This allows the programmer to program the
device by issuing the appropriate commands and data.
Table 4-1 summarizes the commands. A detailed
description for each command is provided in
Section 5.2 “Programming Executive Commands”.
TABLE 4-1:COMMAND SET SUMMARY
CommandDescription
SCHECKSanity Check
READCRead Device ID Registers
READPRead Code Memory
PROGP
PROGW
QBLANKQuery if the Code Memory is Blank
QVERQuery the Software Version
The programming executive uses the device’s data
RAM for variable storage and program execution. After
the programming executive has run, no assumptions
should be made about the contents of data RAM.
4.1Overview of the Programming
Figure 4-1 shows the high-level overview of the
programming process. After entering Enhanced ICSP
mode, the programming executive is verified. Next, the
device is erased. Then, the code memory is
programmed, followed by the configuration locations.
Code memory (including the Configuration registers) is
then verified to ensure that programming was successful.
Program One Row of Code Memory
and Verify
Program One Word of Code Memory
and Verify
Process
After the programming executive has been verified
in memory (or loaded if not present), the
PIC24FJXXXGA1/GB1 families can be programmed
using the command set shown in Table 4-1.
FIGURE 4-1:HIGH-LEVEL ENHANCED
ICSP™ PROGRAMMING FLOW
Start
Enter Enhanced ICSP™
Perform Chip
Erase
Program Memory
Verify Program
Program Configuration Bits
Verify Configuration Bits
Exit Enhanced ICSP
Done
4.2Confirming the Presence of the
Programming Executive
Before programming can begin, the programmer must
confirm that the programming executive is stored in
executive memory. The procedure for this task is
shown in Figure 4-2.
First, In-Circuit Serial Programming mode (ICSP) is
entered. Then, the unique Application ID Word stored in
executive memory is read. If the programming executive
is resident, the Application ID Word is BBh, which means
programming can resume as normal. However, if the
Application ID Word is not BBh, the programming
executive must be programmed to executive code
memory using the method described in Section 5.4
“Programming the Programming Executive to
Memory”.
Section 3.0 “Device Programming – ICSP” describesthe ICSP programming method. Section 3.11 “Reading
the Application ID Word” describes the procedure for
As shown in Figure 4-3, entering Enhanced ICSP
Program/Verify mode requires three steps:
1.The MCLR
2.A 32-bit key sequence is clocked into PGDx.
3.MCLR
period of time and held.
The programming voltage applied to MCLR is VIH,
which is essentially V
PIC24FJXXXGA1/GB1 devices. There is no minimum
time requirement for holding at VIH. After VIH is
removed, an interval of at least P18 must elapse before
presenting the key sequence on PGDx.
The key sequence is a specific 32-bit pattern:
‘0100 1101 0100 0011 0100 1000 0101 0000’
(more easily remembered as 4D434850h in hexadecimal format). The device will enter Program/Verify
mode only if the key sequence is valid. The Most
Significant bit (MSb) of the most significant nibble must
be shifted in first.
Once the key sequence is complete, V
applied to MCLR
Program/Verify mode is to be maintained. An interval of
at least time P19 and P7 must elapse before presenting
data on PGDx. Signals appearing on PGDx before P7
has elapsed will not be interpreted as valid.
On successful entry, the program memory can be
accessed and programmed in serial fashion. While in
the Program/Verify mode, all unused I/Os are placed in
the high-impedance state.
The term “Blank Check” implies verifying that the
device has been successfully erased and has no
programmed memory locations. A blank or erased
memory location is always read as ‘1’.
The Device ID registers (FF0002h:FF0000h) can be
ignored by the Blank Check since this region stores
device information that cannot be erased. The device
Configuration registers are also ignored by the Blank
Check. Additionally, all unimplemented memory space
should be ignored by the Blank Check.
The QBLANK command is used for the Blank Check. It
determines if the code memory is erased by testing
these memory regions. A ‘BLANK’ or ‘NOT BLANK’
response is returned. If it is determined that the device
is not blank, it must be erased before attempting to
program the chip.
4.5Code Memory Programming
4.5.1PROGRAMMING METHODOLOGY
Code memory is programmed with the PROGP
command. PROGP programs one row of code memory
starting from the memory address specified in the
command. The number of PROGP commands
required to program a device depends on the number
of write blocks that must be programmed in the device.
A flowchart for programming the code memory of the
PIC24FJXXXGA1/GB1 families is shown in Figure 4-4.
In this example, all 87K instruction words of a
256 Kbyte device are programmed. First, the number
of commands to send (called ‘RemainingCmds’ in the
flowchart) is set to 1368and the destination address
(called ‘BaseAddress’) is set to ‘0’. Next, one write
block in the device is programmed with a PROGP
command. Each PROGP command contains data for
one row of code memory of the device. After the first
command is processed successfully, ‘RemainingCmds’
is decremented by 1 and compared with 0. Since there
are more PROGP commands to send, ‘BaseAddress’
is incremented by 80h to point to the next row of
memory.
On the second PROGP command, the second row is
programmed. This process is repeated until the entire
device is programmed. No special handling must be
performed when a panel boundary is crossed.
FIGURE 4-4:FLOWCHART FOR
PROGRAMMING CODE
MEMORY
Start
BaseAddress = 00h
RemainingCmds = 1368
Send PROGP
Command to Program
BaseAddress
BaseAddress =
BaseAddress + 80h
No
Is
PROGP response
PASS?
Yes
RemainingCmds =
RemainingCmds – 1
Are
RemainingCmds
0?
Yes
Finish
No
Failure
Report Error
4.5.2PROGRAMMING VERIFICATION
After code memory is programmed, the contents of
memory can be verified to ensure that programming
was successful. Verification requires code memory to
be read back and compared against the copy held in
the programmer’s buffer.
The READP command can be used to read back all of
the programmed code memory.
Alternatively, you can have the programmer perform
the verification after the entire device is programmed
using a checksum computation.
The PIC24FJXXXGA1/GB1 families have Configuration bits stored in the last three locations of implemented program memory (see Table 2-2 for locations).
These bits can be set or cleared to select various
device configurations. There are three types of Configuration bits: system operation bits, code-protect bits
and unit ID bits. The system operation bits determine
the power-on settings for system level components,
such as oscillator and Watchdog Timer. The
code-protect bits prevent program memory from being
read and written.
The descriptions for the Configuration bits in the Flash
Configuration Words are shown in Table 4-2.
Note:Although not implemented with a specific
function, some Configuration bit positions
have default states that must always be
maintained to ensure device functionality,
regardless of the settings of other Configuration bits. Refer to Table 3-7 for a list of
these bit positions and their default states.
OSCIOFNCCW2<5>OSC2 Pin Function bit (except in XT and HS modes)
PLLDIV2:PLLDIV0
POSCMD1:
POSCMD0
WDTPOST3:
WDTPOST0
Note 1:Available on PIC24FJXXXGB1XX devices only.
(2)
(1)
2:Available on PIC24FJXXXGA110 devices only. On other devices, always maintain this bit as ‘1’.
CW2<2>
CW2<14:12>USB 96MHz PLL Prescaler Select bits
CW2<1:0>Primary Oscillator Mode Select bits
CW1<3:0>Watchdog Timer Prescaler bit
I2C2 Pin Select bit (PIC24FJXXXGA1XX devices only)
1 = Use SCL2/SDA2 pins for I
0 = Use ASCL2/ASDA2 pins for I
ICD Emulator Pin Placement Select bits
11 = Emulator functions are shared with PGEC1/PGED1
10 = Emulator functions are shared with PGEC2/PGED2
01 = Emulator functions are shared with PGEC3/PGED3
00 = Reserved; do not use
Configuration bits may be programmed a single byte at
a time using the PROGP command. This command
specifies the configuration data and Configuration
register address. When Configuration bits are
programmed, any unimplemented or reserved bits
must be programmed with a ‘1’.
Two PROGP commands are required to program the
Configuration bits. A flowchart for Configuration bit
4.6.3PROGRAMMING VERIFICATION
After the Configuration bits are programmed, the
contents of memory should be verified to ensure that
the programming was successful. Verification requires
the Configuration bits to be read back and compared
against the copy held in the programmer’s buffer. The
READP command reads back the programmed
Configuration bits and verifies that the programming
was successful.
programming is shown in Figure 4-5.
Note:If the General Segment Code-Protect bit
(GCP) is programmed to ‘0’, code memory
is code-protected and can not be read.
Code memory must be verified before
enabling read protection. See Section 4.6.4“Code-Protect Configuration Bits” for
more information about code-protect
Configuration bits.
FIGURE 4-5:CONFIGURATION BIT PROGRAMMING FLOW
Start
ConfigAddress = 0XXXFAh
(1)
Send PROGP
Command
Is
PROGP response
PASS ?
ConfigAddress =
ConfigAddress + 2
Note 1: Refer to Table 2-2 for Flash Configuration Word addresses.
PIC24FJXXXGA1/GB1 family devices provide two
complimentary methods to protect application code
from overwrites and erasures. These also help to protect the device from inadvertent configuration changes
during run time. Additional information is available in
the product data sheet.
4.6.4.1GENERAL SEGMENT
PROTECTION
For all devices in the PIC24FJXXXGA1/GB1 families,
the on-chip program memory space is treated as a
single block, known as the General Segment (GS).
Code protection for this block is controlled by one Configuration bit, GCP. This bit inhibits external reads and
writes to the program memory space. It has no direct
effect in normal execution mode.
Write protection is controlled by the GWRP bit in the
Configuration Word. When GWRP is programmed to
‘0’, internal write and erase operations to program
memory are blocked.
4.6.4.2CODE SEGMENT PROTECTION
In addition to global General Segment protection, a
separate subrange of the program memory space can
be individually protected against writes and erases.
This area can be used for many purposes where a
separate block of write and erase-protected code is
needed, such as bootloader applications. Unlike
common boot block implementations, the specially protected segment in PIC24FJXXXGA1/GB1 devices can
be located by the user anywhere in the program space,
and configured in a wide range of sizes.
Code segment protection provides an added level of
protection to a designated area of program memory by
disabling the NVM safety interlock whenever a write or
erase address falls within a specified range. It does not
override general segment protection controlled by the
GCP or GWRP bits. For example, if GCP and GWRP
are enabled, enabling segmented code protection for
the bottom half of program memory does not undo
general segment protection for the top half.
4.7Exiting Enhanced ICSP Mode
Exiting Program/Verify mode is done by removing VIH
from MCLR, as shown in Figure 4-6. The only requirement for exit is that an interval, P16, should elapse
between the last clock and program signals on PGCx
and PGDx before removing V
FIGURE 4-6:EXITING ENHANCED
MCLR
VDD
PGDx
PGCx
PGDx = Input
IH.
ICSP™ MODE
P16
P17
VIH
VIH
Note:Bulk Erasing in ICSP mode is the only way
to reprogram code-protect bits from an ON
state (‘0’) to an Off state (‘1’).
The programmer and programming executive have a
master-slave relationship, where the programmer is
the master programming device and the programming
executive is the slave.
All communication is initiated by the programmer in the
form of a command. Only one command at a time can
be sent to the programming executive. In turn, the
programming executive only sends one response to
the programmer after receiving and processing a
command. The programming executive command set
is described in Section 5.2 “Programming Executive
Commands”. The response set is described in
Section 5.3 “Programming Executive Responses”.
5.1.1COMMUNICATION INTERFACE
AND PROTOCOL
The Enhanced ICSP interface is a 2-wire SPI,
implemented using the PGCx and PGDx pins. The
PGCx pin is used as a clock input pin and the clock
source must be provided by the programmer. The
PGDx pin is used for sending command data to, and
receiving response data from, the programming
executive.
Data transmits to the device must change on the rising
edge and hold on the falling edge. Data receives from
the device must change on the falling edge and hold on
the rising edge.
All data transmissions are sent to the Most Significant
bit (MSb) first, using 16-bit mode (see Figure 5-1).
FIGURE 5-1:PROGRAMMING
EXECUTIVE SERIAL
TIMING FOR DATA
RECEIVED FROM DEVICE
P1
13
12
123
PGCx
P1A
P1B
PGDx
14 13 12 11
MSb123
45
6
...
11
P2
45
14
15
16
P3
LSb
FIGURE 5-2:PROGRAMMING
EXECUTIVE SERIAL TIMING
FOR DATA TRANSMITTED
TO DEVICE
P1
13
12
123
PGCx
P1A
P1B
PGDx
MSb123
45
14 13 12 11
11
6
P2
...
14
15
16
P3
45
LSb
Since a 2-wire SPI is used, and data transmissions are
half duplex, a simple protocol is used to control the
direction of PGDx. When the programmer completes a
command transmission, it releases the PGDx line and
allows the programming executive to drive this line
high. The programming executive keeps the PGDx line
high to indicate that it is processing the command.
After the programming executive has processed the
command, it brings PGDx low for 15 μs to indicate to the
programmer that the response is available to be clocked
out. The programmer can begin to clock out the response
23 μs after PGDx is brought low, and it must provide the
necessary amount of clock pulses to receive the entire
response from the programming executive.
After the entire response is clocked out, the programmer should terminate the clock on PGCx until it is time
to send another command to the programming
executive. This protocol is shown in Figure 5-3.
5.1.2SPI RATE
In Enhanced ICSP mode, the PIC24FJXXXGA1/GB1
devices operate from the Internal Fast RC oscillator
(FRCDIV), which has a nominal frequency of 8 MHz.
This oscillator frequency yields an effective system
clock frequency of 4 MHz. To ensure that the programmer does not clock too fast, it is recommended that a
4 MHz clock be provided by the programmer.
5.1.3TIME-OUTS
The programming executive uses no Watchdog Timer
or time-out for transmitting responses to the programmer. If the programmer does not follow the flow control
mechanism using PGCx, as described in Section 5.1.1“Communication Interface and Protocol”, it is
possible that the programming executive will behave
unexpectedly while trying to send a response to the
programmer. Since the programming executive has no
time-out, it is imperative that the programmer correctly
follow the described communication protocol.
As a safety measure, the programmer should use the
command time-outs identified in Table 5-1. If the
command time-out expires, the programmer should
reset the programming executive and start
programming the device again.
FIGURE 5-3:PROGRAMMING EXECUTIVE – PROGRAMMER COMMUNICATION PROTOCOL
Programming Executive
Processes Command
10
P9
PGCx = Input (Idle)
PGDx = Output
PGCx
PGDx
Host Transmits
Last Command Word
1 215 16
MSB X X X LSB
PGCx = Input
PGDx = Input
P8
5.2Programming Executive
Commands
The programming executive command set is shown in
Table 5-1. This table contains the opcode, mnemonic,
length, time-out and description for each command.
Functional details on each command are provided in
Section 5.2.4 “Command Descriptions”.
5.2.1COMMAND FORMAT
All programming executive commands have a general
format consisting of a 16-bit header and any required
data for the command (see Figure 5-4). The 16-bit
header consists of a 4-bit opcode field, which is used to
identify the command, followed by a 12-bit command
length field.
FIGURE 5-4:COMMAND FORMAT
1512110
OpcodeLength
Command Data First Word (if required)
•
•
Command Data Last Word (if required)
The command opcode must match one of those in the
command set. Any command that is received which
does not match the list in Table 5-1 will return a “NACK”
response (see Section 5.3.1.1 “Opcode Field”).
The command length is represented in 16-bit words
since the SPI operates in 16-bit mode. The programming executive uses the command length field to
determine the number of words to read from the SPI
port. If the value of this field is incorrect, the command
will not be properly received by the programming
executive.
Host Clocks Out Response
1 215 16
MSB X X X LSB
P20
PGCx = Input
PGDx = Output
12 1516
MSB X X X LSB
P21
5.2.2PACKED DATA FORMAT
When 24-bit instruction words are transferred across
the 16-bit SPI interface, they are packed to conserve
space using the format shown in Figure 5-5. This
format minimizes traffic over the SPI and provides the
programming executive with data that is properly
aligned for performing table write operations.
FIGURE 5-5:PACKED INSTRUCTION
WORD FORMAT
158 70
LSW1
MSB2MSB1
LSW2
LSWx: Least Significant 16 bits of instruction word
MSBx: Most Significant Bytes of instruction word
Note:When the number of instruction words
transferred is odd, MSB2 is zero and
LSW2 can not be transmitted.
5.2.3PROGRAMMING EXECUTIVE
ERROR HANDLING
The programming executive will “NACK” all
unsupported commands. Additionally, due to the
memory constraints of the programming executive, no
checking is performed on the data contained in the
programmer command. It is the responsibility of the
programmer to command the programming executive
with valid command arguments or the programming
operation may fail. Additional information on error
handling is provided in Section 5.3.1.3 “QE_CodeField”.
1hREADC31 msRead an 8-bit word from the specified Device ID register.
2hREADP41 ms/rowRead N 24-bit instruction words of code memory starting from
3hRESERVEDN/AN/AThis command is reserved. It will return a NACK.
4hPROGC45 msWrite an 8-bit word to the specified Device ID registers.
5hPROGP995 msProgram one row of code memory at the specified address,
6hPROGW55 msProgram one instruction word of code memory at the specified
7hRESERVEDN/AN/AThis command is reserved. It will return a NACK.
8hRESERVEDN/AN/AThis command is reserved. It will return a NACK.
9hRESERVEDN/AN/AThis command is reserved. It will return a NACK.
AhQBLANK3TBDQuery if the code memory is blank.
BhQVER11 msQuery the programming executive software version.
Legend: TBD = To Be Determined
Note 1:One row of code memory consists of (64) 24-bit words. Refer to Table 2-2 for device-specific information.
Length
(16-bit words)
Time-outDescription
the specified address.
then verify.
address, then verify.
(1)
5.2.4COMMAND DESCRIPTIONS
All commands supported by the programming executive
are described in Section 5.2.5 “SCHECK Command”
through Section 5.2.12 “QVER Command”.
5.2.5SCHECK COMMAND
1512 110
OpcodeLength
FieldDescription
Opcode0h
Length1h
The SCHECK command instructs the programming
executive to do nothing but generate a response. This
command is used as a “Sanity Check” to verify that the
programming executive is operational.
Expected Response (2 words):
1000h
0002h
Note:This instruction is not required for
programming but is provided for
development purposes only.
The READC command instructs the programming
executive to read N or Device ID registers, starting from
the 24-bit address specified by Addr_MSB and
Addr_LS. This command can only be used to read 8-bit
or 16-bit data.
When this command is used to read Device ID
registers, the upper byte in every data word returned by
the programming executive is 00h and the lower byte
contains the Device ID register value.
Expected Response (4 + 3 * (N – 1)/2 words for N odd):
1100 h
2 + N
Device ID Register 1
...
Device ID Register N
Note:Reading unimplemented memory will
cause the programming executive to
reset. Please ensure that only memory
locations present on a particular device
are accessed.
5.2.7READP COMMAND
1512 118 70
OpcodeLength
N
ReservedAddr_MSB
Addr_LS
FieldDescription
Opcode2h
Length4h
NNumber of 24-bit instructions to read
(max. of 32768)
Reserved0h
Addr_MSBMSB of 24-bit source address
Addr_LSLeast Significant 16 bits of 24-bit
source address
The READP command instructs the programming
executive to read N 24-bit words of code memory,
including Configuration Words, starting from the 24-bit
address specified by Addr_MSB and Addr_LS. This
command can only be used to read 24-bit data. All data
returned in response to this command uses the packed
data format described in Section 5.2.2 “Packed Data
Format”.
Expected Response (2 + 3 * N/2 words for N even):
1200h
2 + 3 * N/2
Least significant program memory word 1
...
Least significant data word N
Expected Response (4 + 3 * (N – 1)/2 words for N odd):
1200h
4 + 3 * (N – 1)/2
Least significant program memory word 1
...
MSB of program memory word N (zero padded)
Note:Reading unimplemented memory will
cause the programming executive to
reset. Please ensure that only memory
locations present on a particular device
are accessed.
The PROGC command instructs the programming
executive to program a single Device ID register
located at the specified memory address.
After the specified data word has been programmed to
code memory, the programming executive verifies the
programmed data against the data in the command.
Expected Response (2 words):
1400h
0002h
5.2.9PROGP COMMAND
1512 118 70
OpcodeLength
ReservedAddr_MSB
Addr_LS
D_1
D_2
...
D_96
FieldDescription
Opcode5h
Length63h
Reserved0h
Addr_MSBMSB of 24-bit destination address
Addr_LSLeast Significant 16 bits of 24-bit
destination address
D_116-bit data word 1
D_216-bit data word 2
...16-bit data word 3 through 95
D_9616-bit data word 96
The PROGP command instructs the programming
executive to program one row of code memory, including Configuration Words (64 instruction words), to the
specified memory address. Programming begins with
the row address specified in the command. The
destination address should be a multiple of 80h.
The data to program to memory, located in command
words, D_1 through D_96, must be arranged using the
packed instruction word format shown in Figure 5-5.
After all data has been programmed to code memory,
the programming executive verifies the programmed
data against the data in the command.
The PROGW command instructs the programming
executive to program one word of code memory
(3 bytes) to the specific memory address.
After the word has been programmed to code memory,
the programming executive verifies the programmed
data against the data in the command.
Expected Response (2 words):
1600h
0002h
5.2.11QBLANK COMMAND
1512 110
OpcodeLength
PSize_MSW
PSize_LSW
FieldDescription
OpcodeAh
Length3h
PSizeLength of program memory to check
in 24-bit words plus one (max. of
49152)
The QBLANK command queries the programming
executive to determine if the contents of code memory
and code-protect Configuration bits (GCP and GWRP)
are blank (contain all ‘1’s). The size of code memory to
check must be specified in the command.
The Blank Check for code memory begins at 0h and
advances toward larger addresses for the specified
number of instruction words.
QBLANK returns a QE_Code of F0h if the specified
code memory and code-protect bits are blank;
otherwise, QBLANK returns a QE_Code of 0Fh.
Expected Response (2 words for blank device):
1AF0h
0002h
Expected Response (2 words for non-blank device):
1A0Fh
0002h
Note:QBLANK does not check the system
operation Configuration bits, since these
bits are not set to ‘1’ when a Chip Erase is
performed.
The QVER command queries the version of the
programming executive software stored in test
memory. The “version.revision” information is returned
in the response’s QE_Code using a single byte with the
following format: main version in upper nibble and
revision in the lower nibble (i.e., 23h means version 2.3
of programming executive software).
Expected Response (2 words):
1BMNh (where “MN” stands for version M.N)
0002h
5.3Programming Executive
Responses
The programming executive sends a response to the
programmer for each command that it receives. The
response indicates if the command was processed
correctly. It includes any required response data or
error data.
The programming executive response set is shown in
Table 5-2. This table contains the opcode, mnemonic
and description for each response. The response format
is described in Section 5.3.1 “Response Format”.
TABLE 5-2:PROGRAMMING EXECUTIVE
RESPONSE OP CODES
OpcodeMnemonicDescription
1hPASSCommand successfully
processed
2hFAILCommand unsuccessfully
processed
3hNACKCommand not known
5.3.1RESPONSE FORMAT
All programming executive responses have a general
format consisting of a two-word header and any
required data for the command.
1512 118 70
Opcode Last_CmdQE_Code
Length
D_1 (if applicable)
...
D_N (if applicable)
FieldDescription
OpcodeResponse opcode
Last_CmdProgrammer command that
generated the response
QE_CodeQuery code or error code.
LengthResponse length in 16-bit words
(includes 2 header words)
D_1First 16-bit data word (if applicable)
D_NLast 16-bit data word (if applicable)
5.3.1.1Opcode Field
The opcode is a 4-bit field in the first word of the
response. The opcode indicates how the command
was processed (see Table 5-2). If the command was
processed successfully, the response opcode is PASS.
If there was an error in processing the command, the
response opcode is FAIL and the QE_Code indicates
the reason for the failure. If the command sent to
the programming executive is not identified, the
programming executive returns a NACK response.
5.3.1.2Last_Cmd Field
The Last_Cmd is a 4-bit field in the first word of
the response and indicates the command that the
programming executive processed. Since the programming executive can only process one command at a
time, this field is technically not required. However, it
can be used to verify that the programming executive
correctly received the command that the programmer
transmitted.
The QE_Code is a byte in the first word of the
response. This byte is used to return data for query
commands and error codes for all other commands.
When the programming executive processes one of the
two query commands (QBLANK or QVER), the
returned opcode is always PASS and the QE_Code
holds the query response data. The format of the
QE_Code for both queries is shown in Table 5-3.
TABLE 5-3:QE_Code FOR QUERIES
QueryQE_Code
QBLANK 0Fh = Code memory is NOT blank
F0h = Code memory is blank
QVER0xMN, where programming executive
software version = M.N (i.e., 32h means
software version 3.2)
When the programming executive processes any
command other than a query, the QE_Code represents
an error code. Supported error codes are shown in
Table 5-4. If a command is successfully processed, the
returned QE_Code is set to 0h, which indicates that
there was no error in the command processing. If the
verify of the programming for the PROGP or PROGC
command fails, the QE_Code is set to 1h. For all other
programming executive errors, the QE_Code is 2h.
TABLE 5-4:QE_Code FOR NON-QUERY
COMMANDS
QE_CodeDescription
0hNo error
1hVerify failed
2hOther error
5.3.1.4Response Length
The response length indicates the length of the
programming executive’s response in 16-bit words.
This field includes the 2 words of the response header.
With the exception of the response for the READP
command, the length of each response is only 2 words.
The response to the READP command uses the
packed instruction word format described in
Section 5.2.2 “Packed Data Format”. When reading
an odd number of program memory words (N odd), the
response to the READP command is (3 * (N + 1)/2 + 2)
words. When reading an even number of program
memory words (N even), the response to the READP
command is (3 * N/2 + 2) words.
5.4Programming the Programming
Executive to Memory
5.4.1OVERVIEW
If it is determined that the programming executive is
not present in executive memory (as described
in Section 4.2 “Confirming the Presence of theProgramming Executive”), it must be programmed
into executive memory using ICSP, as described in
Section 3.0 “Device Programming – ICSP”.
Storing the programming executive to executive
memory is similar to normal programming of code
memory. Namely, the executive memory must be
erased, and then the programming executive must be
programmed 64 words at a time. Erasing the last page
of executive memory will cause the FRC oscillator
calibration settings and device diagnostic data in the
Diagnostic and Calibration Words, at addresses
8007F0h to 8007FEh, to be erased. In order to retain
this calibration, these memory locations should be read
and stored prior to erasing executive memory. They
should then be reprogrammed in the last words of program memory. This control flow is summarized in
Table 5-5.
TABLE 5-5:PROGRAMMING THE PROGRAMMING EXECUTIVE
Command
(Binary)
Step 1: Exit Reset vector and erase executive memory.
0000
0000
0000
Step 2: Initialize pointers to read Diagnostic and Calibration Words for storage in W6-W13.
0000
0000
0000
0000
0000
Step 3: Repeat this step 8 times to read Diagnostic and Calibration Words, storing them in W registers, W6-W13.
0000
0000
0000
Step 4: Initialize the NVMCON to erase executive memory.
0000
0000
Step 5: Initialize Erase Pointers to first page of executive and then initiate the erase cycle.
Step 16: Repeat Steps 14-15, sixteen times, to load the write latches for the 64 instructions.
Step 17: Initiate the programming cycle.
0000
0000
0000
Step 18: Repeat this step to poll the WR bit (bit 15 of NVMCON) until it is cleared by the hardware.
0000
0000
0000
0000
0000
0001
0000
Step 19: Reset the device internal PC.
0000
0000
Step 20: Repeat Steps 14-19 until all 16 rows of executive memory have been programmed. On the final row, make
sure to initialize the write latches at the Diagnostic and Calibration Words locations with 0xFFFFFF to
ensure that the calibration is not overwritten.
After the programming executive has been
programmed to executive memory using ICSP, it must
be verified. Verification is performed by reading out the
contents of executive memory and comparing it with
the image of the programming executive stored in the
programmer.
Reading the contents of executive memory can be
performed using the same technique described in
Section 3.8 “Reading Code Memory”. A procedure
for reading executive memory is shown in Table 5-6.
Note that in Step 2, the TBLPAG register is set to 80h,
such that executive memory may be read. The last
eight words of executive memory should be verified
with stored values of the Diagnostic and Calibration
Words to ensure accuracy.
TABLE 5-6:READING EXECUTIVE MEMORY
Command
(Binary)
Step 1: Exit the Reset vector.
0000
0000
0000
Step 2: Initialize TBLPAG and the Read Pointer (W6) for TBLRD instruction.
0000
0000
0000
Step 3: Initialize the Write Pointer (W7) to point to the VISI register.
0000
0000
Step 4: Read and clock out the contents of the next two locations of executive memory through the VISI register
TBLRDL[W6], [W7]
NOP
NOP
Clock out contents of VISI register
NOP
TBLRDH.B[W6++], [W7++]
NOP
NOP
TBLRDH.B[++W6], [W7--]
NOP
NOP
Clock out contents of VISI register
NOP
TBLRDL[W6++], [W7]
NOP
NOP
Clock out contents of VISI register
NOP
The Device ID region of memory can be used to
determine mask, variant and manufacturing
information about the chip. The Device ID region is
2 x 16 bits and it can be read using the READC
command. This region of memory is read-only and can
also be read when code protection is enabled.
Table 6-1 shows the Device ID for each device, Table 6-2
shows the Device ID registers and Table 6-3 describes
the bit field of each register.
TABLE 6-1:DEVICE IDs
DeviceDEVID
PIC24FJ128GA106
PIC24FJ192GA106
PIC24FJ256GA106
PIC24FJ128GA100
PIC24FJ192GA108
PIC24FJ256GA108
PIC24FJ128GA110
PIC24FJ192GA110
PIC24FJ256GA110
PIC24FJ64GB106
PIC24FJ128GB106
PIC24FJ192GB106
PIC24FJ256GB106
PIC24FJ64GB108
PIC24FJ128GB108
PIC24FJ192GB108
PIC24FJ256GB108
PIC24FJ64GB110
PIC24FJ128GB110
PIC24FJ192GB110
PIC24FJ256GB110
1008h
1010h
1018h
100Ah
1012h
101Ah
100Eh
1016h
101Eh
1001h
1009h
1011h
1019h
1003h
100Bh
1013h
101Bh
1007h
100Fh
1017h
101Fh
TABLE 6-2:PIC24FJXXXGA1/GB1 DEVICE ID REGISTERS
AddressName
FF0000hDEVID
FF0002hDEVREV
1514131211109876543210
—
—MAJRV<2:0>—DOT<2:0>
FAMID<7:0>DEV<5:0>
Bit
TABLE 6-3:DEVICE ID BIT DESCRIPTIONS
Bit FieldRegisterDescription
FAMID<7:0>DEVIDEncodes the family ID of the device
DEV<5:0>DEVIDEncodes the individual ID of the device
MAJRV<2:0>DEVREVEncodes the major revision number of the device
DOT<2:0>DEVREVEncodes the minor revision number of the device
Checksums for the PIC24FJXXXGA1/GB1 families are
16 bits in size. The checksum is calculated by summing
the following:
• Contents of code memory locations
• Contents of Configuration registers
Table 6-4 describes how to calculate the checksum for
each device. All memory locations are summed, one
byte at a time, using only their native data size. More
specifically, Configuration registers are summed by
adding the lower two bytes of these locations (the
upper byte is ignored), while code memory is summed
by adding all three bytes of code memory.
TABLE 6-4:CHECKSUM COMPUTATION
Device
PIC24FJ128GA106DisabledCFGB + SUM(0:1F7F9)TBDTBD
PIC24FJ192GA106DisabledCFGB + SUM(0:20BF9)TBDTBD
PIC24FJ256GA106DisabledCFGB + SUM(0:2ABF9)TBDTBD
PIC24FJ128GA108DisabledCFGB + SUM(0:1F7F9)TBDTBD
PIC24FJ192GA108DisabledCFGB + SUM(0:20BF9)TBDTBD
PIC24FJ256GA108DisabledCFGB + SUM(0:2ABF9)TBDTBD
PIC24FJ128GA110DisabledCFGB + SUM(0:1F7F9)TBDTBD
PIC24FJ192GA110DisabledCFGB + SUM(0:20BF9)TBDTBD
PIC24FJ256GA110DisabledCFGB + SUM(0:2ABF9)TBDTBD
PIC24FJ64GB106DisabledCFGB + SUM(0:ABF9)TBDTBD
PIC24FJ128GB106DisabledCFGB + SUM(0:1F7F9)TBDTBD
PIC24FJ192GB106DisabledCFGB + SUM(0:20BF9)TBDTBD
PIC24FJ256GB106DisabledCFGB + SUM(0:2ABF9)TBDTBD
PIC24FJ64GB108DisabledCFGB + SUM(0:ABF9)TBDTBD
Legend:ItemDescription
SUM[a:b] = Byte sum of locations, a to b inclusive (all 3 bytes of code memory)
CFGB=CFGB = Configuration Block (masked) Byte sum of (CW1 & 0x7BDF + CW2 & 0xF7FF +
TBD= To Be Determined
Note:CW1 address is last location of implemented program memory; CW2 is (last location – 2); CW3 is (last
SUM[a:b] = Byte sum of locations, a to b inclusive (all 3 bytes of code memory)
CFGB=CFGB = Configuration Block (masked) Byte sum of (CW1 & 0x7BDF + CW2 & 0xF7FF +
TBD= To Be Determined
Note:CW1 address is last location of implemented program memory; CW2 is (last location – 2); CW3 is (last
Operating Temperature: 0°C to +70°C. Programming at +25°C is recommended.
Param
D111V
D112IPPProgramming Current on MCLR—5μA
D113I
D031V
D041V
D080V
D090V
D012C
D013C
P1T
P1AT
P1BT
P2T
P3T
P4T
P4AT
P5T
P6TSET2VDD↑ Setup Time to MCLR ↑100—ns
P7T
P8T
P9T
P10T
P11T
P12T
P13T
P14T
P15T
P16T
P17T
P18T
P19T
P20T
P21T
Note 1:V
SymbolCharacteristicMinMaxUnitsConditions
No.
DDSupply Voltage During ProgrammingVDDCORE3.60VNormal programming
DDPSupply Current During Programming—2mA
ILInput Low VoltageVSS0.2 VDDV
IHInput High Voltage0.8 VDDVDDV
OLOutput Low Voltage—0.4VIOL = 8.5 mA @ 3.6V
OHOutput High Voltage3.0—VIOH = -3.0 mA @ 3.6V
IOCapacitive Loading on I/O pin (PGDx)—50pFTo meet AC specifications
FFilter Capacitor Value on VCAP4.710μFRequired for controller core
PGCSerial Clock (PGCx) Period100—ns
PGCLSerial Clock (PGCx) Low Time40—ns
PGCHSerial Clock (PGCx) High Time40—ns
SET1Input Data Setup Time to Serial Clock ↑15—ns
HLD1Input Data Hold Time from PGCx ↑15—ns
DLY1Delay Between 4-Bit Command and
40—ns
Command Operand
DLY1ADelay Between 4-Bit Command Operand
40—ns
and Next 4-Bit Command
DLY2Delay Between Last PGCx ↓ of Command
20—ns
Byte to First PGCx ↑ of Read of Data Word
HLD2Input Data Hold Time from MCLR ↑25—ms
DLY3Delay Between Last PGCx ↓ of Command
12—μs
Byte to PGDx ↑ by Programming Executive
DLY4Programming Executive Command
40—μs
Processing Time
DLY6PGCx Low Time After Programming400—ns
DLY7Chip Erase Time400—ms
DLY8Page Erase Time40—ms
DLY9Row Programming Time2—ms
RMCLR Rise Time to Enter ICSP™ mode—1.0μs
VALIDData Out Valid from PGCx ↑10—ns
DLY10 Delay Between Last PGCx ↓ and MCLR ↓0—s
HLD3MCLR ↓ to VDD↓—100ns
KEY1Delay from First MCLR ↓ to First PGCx ↑ for
40—ns
Key Sequence on PGDx
KEY2Delay from Last PGCx ↓ for Key Sequence
on PGDx to Second MCLR
DLY11 Delay Between PGDx ↓ by Programming
↑
1—ms
23— µs
Executive to PGDx Driven by Host
DLY12 Delay Between Programming Executive
8—ns
Command Response Words
DDCORE must be supplied to the VDDCORE/VCAP pin if the on-chip voltage regulator is disabled. See
Section 2.1 “Power Requirements” for more information. (Minimum V
DDCORE allowing Flash programming is
2.25V.)
DD must also be supplied to the AVDD pins during programming. AVDD and AVSS should always be within ±0.3V
Note the following details of the code protection feature on Microchip devices:
•Microchip products meet the specification contained in their particular Microchip Data Sheet.
•Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
•There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
•Microchip is willing to work with the customer who is concerned about the integrity of their code.
•Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Information contained in this publication regarding device
applications and the like is provided only for your convenience
and may be superseded by updates. It is your responsibility to
ensure that your application meets with your specifications.
MICROCHIP MAKES NO REPRESENTATIONS OR
WARRANTIES OF ANY KIND WHETHER EXPRESS OR
IMPLIED, WRITTEN OR ORAL, STATUTORY OR
OTHERWISE, RELATED TO THE INFORMATION,
INCLUDING BUT NOT LIMITED TO ITS CONDITION,
QUALITY, PERFORMANCE, MERCHANTABILITY OR
FITNESS FOR PURPOSE. Microchip disclaims all liability
arising from this information and its use. Use of Microchip
devices in life support and/or safety applications is entirely at
the buyer’s risk, and the buyer agrees to defend, indemnify and
hold harmless Microchip from any and all damages, claims,
suits, or expenses resulting from such use. No licenses are
conveyed, implicitly or otherwise, under any Microchip
intellectual property rights.
Trademarks
The Microchip name and logo, the Microchip logo, Accuron,
dsPIC, K
EELOQ, KEELOQ logo, microID, MPLAB, PIC,
PICmicro, PICSTART, PRO MATE, rfPIC and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Linear Active Thermistor, Migratable
Memory, MXDEV, MXLAB, SEEVAL, SmartSensor and The
Embedded Control Solutions Company are registered
trademarks of Microchip Technology Incorporated in the
U.S.A.
Analog-for-the-Digital Age, Application Maestro, CodeGuard,
dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN,
ECONOMONITOR, FanSense, FlexROM, fuzzyLAB,
In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi,
MPASM, MPLAB Certified logo, MPLIB, MPLINK, PICkit,
PICDEM, PICDEM.net, PICLAB, PICtail, PowerCal,
PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select
Mode, Smart Serial, SmartTel, Total Endurance, UNI/O,
WiperLock and ZENA are trademarks of Microchip
Technology Incorporated in the U.S.A. and other countries.
SQTP is a service mark of Microchip Technology Incorporated
in the U.S.A.
All other trademarks mentioned herein are property of their
respective companies.
Microchip received ISO/TS-16949:2002 certification for its worldwide
headquarters, design and wafer fabrication facilities in Chandler and
Tempe, Arizona; Gresham, Oregon and design centers in California
and India. The Company’s quality system processes and procedures
are for its PIC
devices, Serial EEPROMs, microperipherals, nonvolatile memory and
analog products. In addition, Microchip’s quality system for the design
and manufacture of development systems is ISO 9001:2000 certified.