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 ac t s
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 M icrochip’s prod ucts as critical components in
life support systems is not authorized except with express
written approval by Microchip. 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, microID, MPLAB, PIC, PICmicro, PICSTART,
PRO MATE, PowerSmart, rfPIC, and SmartShunt are
registered trademarks of Microchip Technology Incorporated
in the U.S.A. and other countries.
AmpLab, FilterLab, Migratable Memory, MXDEV, MXLAB,
PICMASTER, 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, dsPICDEM,
dsPICDEM.net, dsPICworks, ECAN, ECONOMONITOR,
FanSense, FlexROM, fuzzyLAB, In-Circuit Serial
Programming, ICSP, ICEPIC, Linear Active Thermistor,
MPASM, MPLIB, MPLINK, MPSIM, PICkit, PICDEM,
PICDEM.net, PICLAB, PICtail, PowerCal, PowerInfo,
PowerMate, PowerTool, rfLAB, rfPICD EM, Select Mode,
Smart Serial, SmartTel, Total Endurance and WiperLock 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 quality system certification for
its worldwide headquarters, design and wafer fabrication facilities in
Chandler and Tempe, Arizona and Mountain View, California in
October 2003. The Company’s quality system processes and
procedures are for its PICmicro
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.
The PIC24H General-purpose Family (Table 1-1)
is ideal for a wide variety of 16-bit MCU embedded
applications. The variants with codec interfaces are
well-suited for audio applications.
TABLE 1-1:PIC24H GENERAL-PURPOSE FAMILY VARIANTS
PIC24H
(2)
DevicePins
24HJ64GP20664648898801 ADC,
24HJ64GP210100648898801 ADC,
24HJ64GP50664648898801 ADC,
24HJ64GP510100648898801 ADC,
24HJ128GP206641288898801 ADC,
24HJ128GP210 1001288898801 ADC,
24HJ128GP506641288898801 ADC,
24HJ128GP510 1001288898801 ADC,
24HJ128GP3066412816898801 ADC,
24HJ128GP310 10012816898801 ADC,
24HJ256GP2066425616898801 ADC,
24HJ256GP210 10025616898801 ADC,
24HJ256GP610 10025616898802 ADC,
Note 1:RAM size is inclusive of 2 KB DMA RAM.
2:Maximum I/O pin count includes pins shared by the peripheral functions.
The PIC24H device family employs a powerful 16-bit
microcontroller (MCU). The res ulti ng CPU fun cti ona lity
is ideal for applications that rely on high-speed,
repetitive comput at ion s, as well as contro l.
Flexible and deterministic interrupt handling, coupled
with a powerful array of peripherals, renders the
PIC24H devices suitable for control applications.
FIGURE 2-1:PIC24H DEVICE BLOCK DIAGRAM
X-Data Bus <16-bit>
Shifter
Divide Control
Legend:
MCU/DSP X-Data Path
Address Path
17 x 17 Multiplier
W Register
Array
16 x 16
Memory
Mapped
16-bit ALU
Program Flash
Memory Data
Access
Program Counter
<23 bits>
Instruction
Prefetch & Decode
STATUS Register
Further, Direct Memory Access (DMA) enables
overhead-free transfer of data between several
peripherals and a dedicated DMA RAM. Reliable, field
programmable Flash program memory ensures
scalability of applications that use PIC24H devices.
Figure 2-1 shows a sample device block diagram
typical of the PIC24H product family.
The PIC24H C P U mo du l e has a 1 6 -bi t ( data ) mo dif i ed
Harvard architecture with an enhanced instruction set.
The CPU has a 24-bit instruction word with a variable
length opcode field. The Program Counter (PC) is
23 bits wide and addresses up to 4M x 24 bits of user
program memory spac e. The actual amou nt of program
memory implemented, as illustrated in Figure 3-1,
varies from one device to another. A single-cycle
instruction prefetch mechanism is used to help
maintain throughput and provides predictable
execution. All instructions execute in a single cycle,
with the exception of instructions that change the
program flow, the double word move (MOV.D)
instruction and the table instructions. Overhead-free
program loop constructs are supported using the
REPEAT instruction, which is interruptible at any point.
The PIC24H devices have sixteen 16-bit working
registers in the programmer’s model. Each of the
working registers can serve as a data, address or
address offset register. The 16th working register
(W15) operates as a software Stack Pointer (SP) for
interrupts and calls.
The PIC24H instruction set includes many addressing
modes and is designed for optimum C compiler
efficiency.
3.1.1DATA MEMORY OVERVIEW
The data space can be addressed as 32K words or
64 Kbytes . Reads and w rites are per formed usin g an
Address Generation Unit (AGU), which accesses the
entire memory map as one linear data space.
The CPU supports Inherent (no operand), Relative,
Literal, Memory Direct, Register Direct and Register
Indirect Addressing modes. Each instruction is
associated with a predefined addressing mode group
depending upon its functional requirements. As many
as 6 addressing modes are supported for each
instruction.
For most instructions, the PIC24H is capable of
executing a data (or program data) memory read, a
working register (data) read, a data memory write and
a program (instruction) memory read per instruction
cycle. As a result, three parameter instructions can be
supported, allowing A + B = C operations to be
executed in a single cycle.
3.1.3SPECIAL MCU FEATURES
The PIC24H features a 17-bit by 17-bit, single-cycle
multiplier. The multiplier can perform signed, unsigned
and mixed-sign multiplication. Using a 17-bit by 17-bit
multiplier for 16-bit by 16-bit multiplication allows you to
perform mixed-sign multiplication.
The PIC24H supports 16/16 and 32/16 divide
operations, both fractional and integer. All divide
instructions are iterative operations. They must be
executed within a REPEAT loop, resulting in a total
execution time of 19 instruction cycles. The divide
operation can be interrupted during any of those 19
cycles without loss of data.
A 40-bit data shifter is used to perform up to a 16-bit left
or right shift in a single cycle.
3.1.5FEATURES TO ENHANCE
COMPILER EFFICIENCY
The CPU architecture possesses several features that
lead to a more efficient (code size and speed) C
compiler.
1.For most instructions, three-parameter instruc-
tions can be supported, allowing A + B = C
operations to be executed in a single cycle.
2.Instruction addressing modes are extremely
flexible to meet compiler needs.
3.The working re gister array consis ts of 16 x 16-b it
registers, each of which can act as data,
address or offse t registers. One w orking regist er
(W15) operates as the software Stack Pointer
for interrupts and calls.
4.Linear indirect access of all data space is
possible, plus the memory direct address range
is up to 8 Kbytes. This capability, together with
the addition of 16-bit direct address MOV-based
instructions, has provided a contiguous linear
addressing space.
5.Linear indirect access of 32K word (64 Kbyte)
pages within program space is possible, using
any working register via new table read and
write instructions.
6.Part of dat a sp a ce c an be mapped into program
space, allowi ng const ant dat a to be acc essed as
if it were in data space.
3.1.4INTERRUPT OVER VIE W
The PIC24H has a vectored exception scheme with up
to 5 sources of non-maskable traps and 67 interrupt
sources. Each interrup t source can be assign ed to one
of seven priority levels.
The programmer’s model, shown in Figure 3-2,
consists of 16 x 16-bit working registers (W0 through
W15), STATUS reg ister (SR), Dat a Table Page register
(TBLPAG), Program Space Visibility Page register
(PSVPAG), REPEAT count register (RCOUNT) and
Program Counter (PC). The working registers can act
as data, addres s or offset registers. A ll registers are
memory mapped. W0 is the W register for all
instructions that perform file register addressing.
Some of these registers have a shadow register
associated with them (see the legend in Figure 3-2).
The shadow register is used as a temporary holding
register and can tran sfe r it s co ntents to or from its host
register upon some event occurring in a single cycle.
None of the shadow registers are accessible directly.
When a byte operation is performed on a working
register, only the Least Significant Byte (LSB) of the
target register is affected. However, a benefit of
memory mapped working registers is that both the
Least and Most Significant Bytes (MSBs) can be
manipulated through byte-wide data memory space
accesses.
W15 is the dedicated software Stack Pointer (SP). It is
automatically modified by exception processing and
subroutine calls and returns. However, W15 can be
referenced by any instruction in the same manner as all
other W registers. This simplifies the reading, writing
and manipulation of the Stack Pointer (e.g., creating
stack frames).
W14 has been dedica ted as a Stack Frame Pointer, as
defined by the LNK and ULNK instructions. However,
W14 can be referenced by any instruction in the same
manner as all other W registers.
The Stack Pointer always points to the first available
free word and grows from lower addresses towards
higher addresses. It pre-decrements for stack pops
(reads) and post-increments for stack pushes (writes).
The data space is accessed as one unified linear
address range (for MCU instructions). The data space
is accessed using the Address Generat ion Unit (AG U).
All Effective Addre sses (EAs) are 16 b its wide and poi nt
to bytes within the data space. Therefore, the data
space address range is 64 Kbytes or 32K words,
though the implemented memory locations vary from
one device to another.
3.3.1DMA RAM
Every PIC24H device contains 2 Kbytes of DMA RAM
located at the end of Y data space. Memo ry locations in
the DMA RAM space are accessible simultaneously by
the CPU and the DMA Controller module. DMA RAM is
utilized by the DMA Controller to store data to be
transferred to various peripherals using DMA, as well as
data transferred from various peripherals using DMA.
When the CPU and the DMA Controller attempt to
concurrently write to the same DMA RAM location, the
hardware ensures tha t the C PU is giv en prec edenc e in
accessing the DMA RAM location. Therefore, the DMA
RAM provides a reliable means of transferring DMA
data without ever having to stall the CPU.
3.3.2DATA SPACE WIDTH
The core data width is 16 bits. All internal registers are
organized as 16 -bit wide word s. Dat a space memory is
organized in byte addressable, 16-bit wide blocks.
Figure 3-3 depicts a sam ple data space memo ry map
for the PIC24H device with 16 Kbytes of RAM.
3.3.3DATA ALIGNMENT
To help maintain backward compatibility with
PICmicro
memory usage efficiency, the PIC24H instruction set
supports both word and byte operations. Data is
aligned in data memory and registers as words, but all
data space EAs resolv e to byt es. Data b yte rea ds will
read the complete word which contains the byte, using
the Least Significant bit (LSb) of any EA to determine
which byte to select.
As a consequence of t his byte accessib ility , all Effec tive
Address calculations are internally scaled. For
example, the core would recognize that Post-Modified
Register Indi rect Ad dressin g mode, [Ws+ +], wil l result
in a value of Ws + 1 for byt e op erations and Ws + 2 for
word operations.
All word accesses m ust be al igned to an even a ddress.
Misaligned word data fetches are not supported.
Should a misaligned read or write be attempted, a trap
will then be ex ec ut e d, al l ow in g t he sys tem an d/ o r use r
to examine the machine state prior to execution of the
address Fault.
Direct Memory Access (DMA) is a very efficient
mechanism of copying data between peripheral SFRs
(e.g., UART Receive register, Input Capture 1 buffer)
and buffers or variables stored in RAM with minimal
CPU intervention. The DMA Controller can
automatically copy entire blocks of data, without the
user software havin g to read or w rite peripheral Special
Function Registers (SFRs) every time a peripheral
interrupt occurs. To exploit the DMA capability, the
corresponding user buffers or variables must be
located in DMA RAM space.
The DMA Controller features eight identical data
transfer channels, each with its own set of control and
status registers. The UART, SPI, DCI, Input Capture,
Output Compare, ECAN™ technology and ADC
modules can utilize DMA. Each DMA channel can be
configured to copy data either from buffers stored in
DMA RAM to peripheral SFRs o r fro m periph eral SF Rs
to buffers in DMA RAM.
Each channel support s the fol low i ng feat ures :
• Word or byte-sized data transfers
• Transfers from peripheral to DMA RAM or DMA
RAM to peripheral
• Indirect addressing of DMA RA M loc ation s with or
without automatic post-increment
• Peripheral Indirect Addressing – In some
peripherals, the DMA RAM read/write addresses
may be partially derived from the peripheral
• One-Shot Block Transfers – Terminating DMA
transfer after one block transfer
• Continuous Block Transfers – Reloading DMA
RAM buffer start address aft er every block
transfer is complete
• Ping-Pong Mode – Switching between two DMA
RAM start addresses between successive block
transfers, thereby filling two buffers alternately
• Automatic or manual initiation of block transfers
• Each channel can select from 32 possible
sources of data sources or destinations
For each DMA channel, a DMA interrupt request is
generated when a block transfer is complete.
Alternatively , an interrupt can be ge nerated when half of
the block has been filled. Additionally, a DMA error trap
is generated in either of the following Fault conditions:
• DMA RAM data write collision between the CPU
and a peripheral
• Peripheral SFR data wri te collision between the
CPU and the DMA Controller
FIGURE 4-1:TOP LEVEL SYSTEM ARCHITECTURE USING A DEDICATED TRANSACTION BUS
The PIC24H has four pro cessor ex ception s (trap s) and
up to 61 sources o f interrupt s, whi ch must be arbitrate d
based on a pr iority sche me.
The processor core is responsible for reading the
Interrupt Vector Table (IVT) and transferring the
address contained in the interrupt vector to the
Program Counter.
The Interrupt Vector Table (IVT) and Alternate In terrupt
Vector Table (AIVT) are placed near the beginning of
program memory (0x000004) for ease of debugging.
The interrupt controller hardware pre-processes the
interrupts before they are presented to the CPU.
The interrupts and traps are enabled, prioritized and
controlled using centralized Special Function Registers.
Each individual interrupt source has its own vector
address and can be individ ually enabled and prioritized
in user software. Each interrupt source a lso has it s own
status flag. This indepe ndent control and monitoring of
the interrupt eliminates the need to poll various status
flags to determine the interrupt source
Table 5-1 contains information about the interrupt
vector.
Certain interrupts have specialized control bits for
features like edge or level triggered interrupts, interrupton-change, etc. Control of these features remains within
the peripheral m od ul e, which generates the interr upt.
The special DISI instruction ca n be used to disable
the processing of interru pt s of pri orit ies 6 and lowe r for
a certain number of instruction cycles, during which
the DISI bit remains set.
Each interrupt source can be user-assigned to one of
8 priority levels, 0 through 7. Levels 7 and 1 represent
the highest and lowest maskable priorities,
respectively. A priority level of 0 disables the interrupt.
Since more than one interrupt request source may be
assigned to a user-specified priority level, a means is
provided to assign priority within a given level. This
method is called “Natural Order Priority”.
The Natural Order Priori ty of an interrup t is nu merica lly
identical to its vector number. The Natural Order
Priority scheme has 0 as the highe st pri orit y and 74 as
the lowest priority.
The ability for the user to assign every interrupt to one
of eight priority levels implies that the user can assign
a very high overall priority level to an interrupt with a
low Natural Order Priority, thereby providing much
flexibility in designing applications that use a large
number of peripherals.
5.2Interrupt Nesting
Interrupts, by default, are nestable. Any ISR that is in
progress may be interrupted by another source of
interrupt with a higher user-assigned priority level.
Interrupt nesting may be optionally disabled by
setting the NSTDIS control bit (INTCON1<15>).
When the NSTDIS control bit is se t, all interrupts in
progress will force the CPU priority to level 7 by
setting IPL<2:0> = 111. This action will effectively
mask all other sources of interrupt until a RETFIE
instruction is executed. When interrupt nesting is
disabled, the user-assigned in terrupt priority levels
will have no effect, except to resolve conflicts
between simultaneous pending interrupts.
The IPL<2:0> bits become read-only when interrupt
nesting is disabled. This prevents the user software
from settin g IPL<2:0> to a lower va lue, which would
effectively re-enable interrupt nesting.
5.3Traps
Traps can be considered as non-maskable, nestable
interrupts that adhere to a fixed priority structure.
Traps are intended to provide the user a means to
correct erroneous operation during debug and when
operating within the application. If the user does not
intend to ta ke corrective ac tion in the even t of a trap
error condition, these vectors must be loaded with the
address of a software routi ne th at w il l reset the device.
Otherwise, the trap vector is programmed with the
address of a service routine that will correct the trap
condition.
The PIC24H has five implemented sources of
non-maskable traps:
• Oscillator Failure Trap
• Address Error Trap
• Stack Error Trap
• Math Error Trap
• DMA Error Trap
Many of these trap conditions can only be detected
when they happen. Consequently, the instruction that
caused the trap is allowed to complete before
exception processing begins. Therefore, the user may
have to correct the action of the instruction that
caused the trap.
Each trap s ource h as a fixe d priori ty as de fined by its
position in the IVT. An oscillator failure trap has the
highest priority, while an arithmetic error trap has the
lowest priority.
Table 5-2 contains information about the trap vector.
5.4Generating a Software Interrupt
Any available interrupt can be manually generated by
user software (even if the corresponding peripheral is
disabled), simply by enabling the interrupt and then
setting the interrupt flag bit when required.
System managemen t servic es provided by the PI C24H
device family include:
• Control of clock options and oscillators
• Power-on Reset
• Oscillator Start-up Timer/Stabilizer
• Watchdog Timer with RC oscillator
• Fail-Safe Clock Monitor
• Reset by multiple sources
6.1Clock Options and Oscillators
There are 7 clock options provided by the PIC24H:
• FRC Oscillator
• FRC Oscillator with PLL
• Primary (XT, HS or EC) Oscillator
• Primary Oscillator with PLL
• Secondary (LP) Oscillator
• LPRC Oscillator
The FRC (Fast RC) inte rnal osci llator runs at a nom inal
frequency of 7.37 MHz. The user s oftware can tune th e
FRC frequency. User software can specify a factor by
which this clock frequency is scaled.
The primary oscillator can use one of the following as
its clock source:
1.XT (Cryst al): Cryst als and c eramic re sonators i n
the range of 3 MHz to 10 MHz. The crystal is
connected to the OSC1 and OSC2 pins.
2.HS (High-Speed Crystal): Crystals in the range
of 10 MHz to 40 MHz. The crysta l is conn ected
to the OSC1 and OSC2 pins.
3.EC (External Clock): External clock signal in the
range of 0.8 MHz to 64 MHz. The extern al cloc k
signal is directly applied to the OSC1 pin.
The secondary (LP) os cillator is design ed for low power
and uses a 32 kHz cryst al or ceramic resonator . The LP
oscillator uses the SOSCI and SOSCO pins.
The LPRC (Low-Power RC) internal oscIllator runs at a
nominal frequency of 32.768 kHz. Another scaled
reference clock is used by the Watchdog Timer (WDT)
and Fail-Safe Clock Monitor (FSCM).
The clock signals generated by the FRC and primary
oscillators can be optionally applied to an on-chip
Phase Locked Loop (PLL) to provide a wide range of
output frequencies for device operation. The input to
the PLL can be in the range of 1.6 MH z to 16 MHz, and
the PLL Phase Detector Input Divider, PLL Multiplier
Ratio and PLL Voltage Controlled Osc illato r (VCO) ca n
be individually conf igured b y user so ftware to genera te
output frequencies in the range of 25 MHz to 160 MHz.
The output of the oscillator (or the output of the PLL if
a PLL mode has been selected) is divided by 2 to
generate the device instruction clock (F
CY). FCY
defines the operating speed of the device, and speeds
up to 40 MHz are supported by the PIC24H
architecture.
The PIC24H oscillator system provides:
• Various external and internal oscillator options as
clock sources
• An on-chip PLL to scale the internal operating
frequency to the required system clock frequency
• The internal FRC oscillator can also be used with
the PLL, thereby allowing full-speed operation
without any external clock generation hardware
• Clock switching between various clock sources
• Programmable clock postscaler f or s ystem po w er
savings
• A Fail-Safe Clock Monitor (FSCM) that detects
clock failure and takes fail-safe measures
• A Clock Control register (OSCCON)
• Nonvolatile Configuration bits for main oscillator
selection.
A simplified block diagram of the oscillator system is
shown in Figure 6-1.