PIC Microcontroller
PIC Microcontroller
Contents
[hide]
1 Core architecture
o 1.1 Data space (RAM)
o 1.2 Code space
o 1.3 Word size
o 1.4 Stacks
o 1.5 Instruction set
o 1.6 Performance
1.7 Limits
1.8 Compiler development
2 Family core architectural differences
o 2.1 Baseline core devices
o 2.2 Mid-range core devices
o 2.3 PIC17 high end core devices
o 2.4 PIC18 high end core devices
o 2.5 PIC24 and dsPIC 16-bit microcontrollers
o 2.6 PIC32 32-bit microcontrollers
3 Device variants and hardware features
o 3.1 Variants
o 3.2 Trends
4 History
5 Development tools
o 5.1 Commercially supported
o 5.2 Open source
6 Device programmers
o 6.1 Microchip programmers
o 6.2 Third-party programmers
7 Debugging
o 7.1 Software emulation
o 7.2 In-circuit debugging
o 7.3 In-circuit emulators
8 PIC clones
9 PICKit 2 open source structure and clones
10 8/16/32-bit PIC microcontroller product families
11 See also
12 References
13 External links
o
o
Separate code and data spaces (Harvard architecture) for devices other than
PIC32, which has a Von Neumann architecture.
A small number of fixed length instructions
Most instructions are single cycle execution (2 clock cycles), with one delay cycle
on branches and skips
One accumulator (W0), the use of which (as source operand) is implied (i.e. is not
encoded in the opcode)
All RAM locations function as registers as both source and/or destination of math
and other functions.[2]
A hardware stack for storing return addresses
A fairly small amount of addressable data space (typically 256 bytes), extended
through banking
Data space mapped CPU, port, and peripheral registers
The program counter is also mapped into the data space and writable (this is used
to implement indirect jumps).
There is no distinction between memory space and register space because the RAM
serves the job of both memory and registers, and the RAM is usually just referred to as
the register file or simply as the registers.
In order to be clear, the program memory capacity is usually stated in number of (single
word) instructions, rather than in bytes.
[edit] Stacks
PICs have a hardware call stack, which is used to save return addresses. The hardware
stack is not software accessible on earlier devices, but this changed with the 18 series
devices.
Hardware support for a general purpose parameter stack was lacking in early series, but
this greatly improved in the 18 series, making the 18 series architecture more friendly to
high level language compilers.
2. Operation with W and indexed register. The result can be written to either the W
register (e.g. addwf reg,w). or the selected register (e.g. addwf reg,f).
3. Bit operations. These take a register number and a bit number, and perform one of
4 actions: set or clear a bit, and test and skip on set/clear. The latter are used to
perform conditional branches. The usual ALU status flags are available in a
numbered register so operations such as "branch on carry clear" are possible.
4. Control transfers. Other than the skip instructions previously mentioned, there are
only two: goto and call.
5. A few miscellaneous zero-operand instructions, such as return from subroutine,
and sleep to enter low-power mode.
[edit] Performance
The architectural decisions are directed at the maximization of speed-to-cost ratio. The
PIC architecture was among the first scalar CPU designs,[citation needed] and is still among the
simplest and cheapest. The Harvard architecturein which instructions and data come
from separate sourcessimplifies timing and microcircuit design greatly, and this
benefits clock speed, price, and power consumption.
The PIC instruction set is suited to implementation of fast lookup tables in the program
space. Such lookups take one instruction and two instruction cycles. Many functions can
be modelled in this way. Optimization is facilitated by the relatively large program space
of the PIC (e.g. 4096 x 14-bit words on the 16F690) and by the design of the instruction
set, which allows for embedded constants. For example, a branch instruction's target may
be indexed by W, and execute a "RETLW" which does as it is named - return with literal
in W.
Execution time can be accurately estimated by multiplying the number of instructions by
two cycles; this simplifies design of real-time code. Similarly, interrupt latency is
constant at three instruction cycles. External interrupts have to be synchronized with the
four clock instruction cycle, otherwise there can be a one instruction cycle jitter. Internal
interrupts are already synchronized. The constant interrupt latency allows PICs to achieve
interrupt driven low jitter timing sequences. An example of this is a video sync pulse
generator.
[edit] Limits
The PIC architectures have several limits:
The following limitations have been addressed in the PIC18, but still apply to earlier
cores:
With paged program memory, there are two page sizes to worry about: one for CALL and
GOTO and another for computed GOTO (typically used for table lookups). For example,
on PIC16, CALL and GOTO have 11 bits of addressing, so the page size is 2048
instruction words. For computed GOTOs, where you add to PCL, the page size is 256
instruction words. In both cases, the upper address bits are provided by the PCLATH
register. This register must be changed every time control transfers between pages.
PCLATH must also be preserved by any interrupt handler.[6]
MOVWF f Move W to f
CLRW
Clear W to 0 (a.k.a CLR x, W)
CLRF f
Clear f to 0 (a.k.a. CLR f, F)
SUBWF f, d Subtract W from f (d = f W)
DECF f, d Decrement f (d = f 1)
IORWF f, d Inclusive OR W with F (d = f OR W)
ANDWF f, d AND W with F (d = f AND W)
XORWF f, d Exclusive OR W with F (d = f XOR W)
ADDWF f, d Add W with F (d = f + W)
MOVF f, d Move F (d = f)
COMF f, d Complement f (d = NOT f)
INCF f, d
Increment f (d = f + 1)
DECFSZ f, d Decrement f (d = f 1) and skip if zero
RRF f, d
Rotate right F (rotate right through carry)
RLF f, d
Rotate left F (rotate left through carry)
SWAPF f, d Swap 4-bit halves of f (d = f<<4 | f>>4)
0011 11d fffff INCFSZ f, d Increment f (d = f + 1) and skip if zero
0011 01d fffff
0011 10d fffff
BCF f, b
0101 bbb fffff BSF f, b
0110 bbb fffff BTFSC f, b
0111 bbb fffff BTFSS f, b
0100 bbb fffff
1000 kkkkkkkk
1001 kkkkkkkk
1010 kkkkkkkkk
1100 kkkkkkkk
1101 kkkkkkkk
1110 kkkkkkkk
1111 kkkkkkkk
RETLW k
CALL k
GOTO k
MOVLW k
IORLW k
ANDLW k
XORLW k
Opcode (binary)
00 0000 0000 0000
00 0000 0000 1000
00 0000 0000 1001
00 0000 0110 0010
00 0000 0110 0011
00 0000 0110 0100
00 0000 0110 01ff
00 0000 1 fffffff
00 0001 0 xxxxxxx
00 0001 1 fffffff
00 0010 d fffffff
00 0011 d fffffff
00 0100 d fffffff
00 0101 d fffffff
00 0110 d fffffff
00 0111 d fffffff
00 1000 d fffffff
00 1001 d fffffff
00 1010 d fffffff
00 1011 d fffffff
00 1100 d fffffff
00 1101 d fffffff
00 1110 d fffffff
00 1111 d fffffff
MOVWF f Move W to f
CLRW
Clear W to 0 (W = 0)
CLRF f
Clear f to 0 (f = 0)
SUBWF f, d Subtract W from f (d = f W)
DECF f, d Decrement f (d = f 1)
IORWF f, d Inclusive OR W with F (d = f OR W)
ANDWF f, d AND W with F (d = f AND W)
XORWF f, d Exclusive OR W with F (d = f XOR W)
ADDWF f, d Add W with F (d = f + W)
MOVF f, d Move F (d = f)
COMF f, d Complement f (d = NOT f)
INCF f, d
Increment f (d = f + 1)
DECFSZ f, d Decrement f (d = f 1) and skip if zero
RRF f, d
Rotate right F (rotate right through carry)
RLF f, d
Rotate left F (rotate left through carry)
SWAPF f, d Swap 4-bit halves of f (d = f<<4 | f>>4)
INCFSZ f, d Increment f (d = f + 1) and skip if zero
BCF f, b
BSF f, b
01 10 bbb fffffff BTFSC f, b
01 11 bbb fffffff BTFSS f, b
01 00 bbb fffffff
01 01 bbb fffffff
10 0 kkkkkkkkkkk
10 1 kkkkkkkkkkk
11 00xx kkkkkkkk
11 01xx kkkkkkkk
11 1000 kkkkkkkk
11 1001 kkkkkkkk
11 1010 kkkkkkkk
11 110x kkkkkkkk
11 111x kkkkkkkk
CALL k
GOTO k
MOVLW k
RETLW k
IORLW k
ANDLW k
XORLW k
SUBLW k
ADDLW k
Move literal to W (W = k)
Set W to k and return
Inclusive or literal with W (W = k OR W)
AND literal with W (W = k AND W)
Exclusive or literal with W (W = k XOR W)
Subtract W from literal (W = k W)
Add literal to W (W = k + W)
The auto increment/decrement feature was improved by removing the control bits and
adding four new indirect registers per FSR. Depending on which indirect file register is
being accessed it is possible to postdecrement, postincrement, or preincrement FSR; or
form the effective address by adding W to FSR.
In more advanced PIC18 devices, an "extended mode" is available which makes the
addressing even more favorable to compiled code:
a new offset addressing mode; some addresses which were relative to the access
bank are now interpreted relative to the FSR2 register
the addition of several new instructions, notable for manipulating the FSR
registers.
These changes were primarily aimed at improving the efficiency of a data stack
implementation. If FSR2 is used either as the stack pointer or frame pointer, stack items
[edit] Variants
Within a series, there are still many device variants depending on what hardware
resources the chip features.
[edit] Trends
The first generation of PICs with EPROM storage are almost completely replaced by
chips with Flash memory. Likewise, the original 12-bit instruction set of the PIC1650 and
its direct descendants has been superseded by 14-bit and 16-bit instruction sets.
Microchip still sells OTP (one-time-programmable) and windowed (UV-erasable)
versions of some of its EPROM based PICs for legacy support or volume orders. The
Microchip website lists PICs that are not electrically erasable as OTP despite the fact that
UV erasable windowed versions of these chips can be ordered.
[edit] History
The original PIC was built to be used with General Instruments' new 16-bit CPU, the
CP1600. While generally a good CPU, the CP1600 had poor I/O performance, and the 8bit PIC was developed in 1975 to improve performance of the overall system by
offloading I/O tasks from the CPU. The PIC used simple microcode stored in ROM to
perform its tasks, and although the term wasn't used at the time, it shares some common
features with RISC designs.
In 1985 General Instruments spun off their microelectronics division, and the new
ownership canceled almost everything which by this time was mostly out-of-date. The
PIC, however, was upgraded with internal EPROM to produce a programmable channel
controller, and today a huge variety of PICs are available with various on-board
peripherals (serial communication modules, UARTs, motor control kernels, etc.) and
program memory from 256 words to 64k words and more (a "word" is one assembly
language instruction, varying from 12, 14 or 16 bits depending on the specific PIC micro
family).
PIC and PICmicro are registered trademarks of Microchip Technology. It is generally
thought that PIC stands for Peripheral Interface Controller, although General
Instruments' original acronym for the initial PIC1640 and PIC1650 devices was
"Programmable Interface Controller".[2] The acronym was quickly replaced with
"Programmable Intelligent Computer".[3]
FlashForth is a native Forth operating system for the PIC18F and the dsPIC30F
series. It makes the PIC a standalone computer with an interpreter, compiler,
assembler and multitasker.
FreeRTOS is a mini real time kernel ported to the PIC18, PIC24, dsPIC and
PIC32 architectures.
GNU Compiler Collection and the GNU Binutils have been ported to the PIC24,
dsPIC30F and dsPIC33F in the form of Microchip's MPLAB C30 compiler and
MPLAB ASM30 assembler.
GPSIM is an Open Source simulator for the PIC microcontrollers featuring
hardware modules that simulate specific devices that might be connected to them,
such as LCDs.
GPUTILS is a set of PIC utilities comprising an assembler, a disassembler, a
linker and an object file viewer.
Great Cow Basic (GCBasic) The syntax of Great Cow BASIC is based on that of
QBASIC/FreeBASIC. The assembly code produced can be assembled and run on
almost all 10, 12, 16 and 18 series PIC chips.
Ktechlab is a free IDE for programming PIC Microcontroller. It allows one to
write the program in C, Assembly, Microbe (a BASIC-like language) and using
FlowChart Method.
JAL [7] stands for Just Another Language. It is a Pascal-like language that is
easily mastered. The compiler supports a few Microchip (16c84, 16f84, 12c508,
12c509, 16F877) and SX microcontrollers. The resulting assembly language can
then be viewed, modified and further processed as if you were programming
directly in assembler.
JAL is now replaced with JALV2, a much superior open source compiler, that can
run on Windows, Linux and Mac OS. JALV2 supports 10F,12F,16F and 18F
series PICS. There is a set of libraries which are again open source maintained by
jallib
MIOS is a real-time operating system written in PIC assembly, optimized for
MIDI processing and other musical control applications. There is a C wrapper for
higher level development. Currently it runs on the MIDIbox Hardware Platform.
picforth is a Unix hosted Forth compiler written in gforth and generates code for
the Microchip PIC 16F87x and 16F88 microcontrollers family. It includes two
kinds of cooperative schedulers.
PiKdev runs on Linux and is a simple graphic IDE for the development of PICbased applications. It currently supports assembly language. Non Open Source C
language (Currently free 1/22/07) is also supported for PIC 18 devices. PiKdev is
developed in C++ under Linux and is based on the KDE environment.
Piklab is a forked version of PiKdev and is managed as SourceForge Project.
Piklab adds to Pikdev by providing support for programmers and debuggers.
Currently, Piklab supports the JDM, PIC Elmer, K8048, HOODMICRO, ICD1,
ICD2, PICkit1, PICKkit2, and PicStart+ as programming devices and has
debugging support for ICD2 in addition to using the simulator, GPSim.[15]
Pic Micro Pascal (PMP) is a free Pascal language compiler and IDE. It is intended
to work with the Microchip MPLAB, using its device definition files, assembler
and linker. It supports PIC10 to PIC18 devices.
SDCC is a C compiler supporting 8-bit PIC micro controllers (PIC16, PIC18).
Currently, throughout the SDCC website, the words, "Work is in progress", are
frequently used to describe the status of SDCC's support for PICs.
There are many programmers for PIC microcontrollers, ranging from the extremely
simple designs which rely on ICSP to allow direct download of code from a host
computer, to intelligent programmers that can verify the device at several supply
voltages. Many of these complex programmers use a pre-programmed PIC themselves to
send the programming commands to the PIC that is to be programmed. The intelligent
type of programmer is needed to program earlier PIC models (mostly EPROM type)
which do not support in-circuit programming.
Many of the higher end flash based PICs can also self-program (write to their own
program memory). Demo boards are available with a small bootloader factory
programmed that can be used to load user programs over an interface such as RS-232 or
USB, thus obviating the need for a programmer device. Alternatively there is bootloader
firmware available that the user can load onto the PIC using ICSP. The advantages of a
bootloader over ICSP is the far superior programming speeds, immediate program
execution following programming, and the ability to both debug and program using the
same cable.
Usbpicprog
PICPgm - PIC Development Programmer for Windows and Linux. Supports 10F,
12F, 16F, 18F and dsPIC devices and a lot of different programmer hardware like
JDM, Tait, AN589, ...
usbpicprog, an open source USB PIC programmer usbpicprog
Open Programmer, another open source USB programmer for PICmicro and I2C
EEPROM, using HID class OpenProgrammer
home-made ICSP JDM Pic
DIY PIC and EEPROM programmer with ICSP support. PCB files, photos and
detailed information are also provided.
PIC PRESTO that supports ICSP, ISP, JTAG, I2C, SPI, Microwire interfaces,
works on USB and complies with programming specifications
home-made ICSP with external powersupply based on JDM: BobProg
(Romanian)
The major problem of home-made or very simple programmers is that these programmers
do not comply with programming specifications and this can cause premature loss of data
in the flash or EEPROM[citation needed].
[edit] Debugging
[edit] Software emulation
MPLAB (which is a free download) includes a software emulator for PICs. However,
software emulation of a microcontroller will always suffer from limited simulation of the
device's interactions with its target circuit.
Proteus VSM is a commercial software product developed by Labcenter Electronics
which allows simulation of many PICmicro devices along with a wide array of peripheral
devices. This method can help bridge the gap between the limited peripheral support
offered by the MPLAB simulator and traditional in-circuit debugging/emulating. The
product interfaces directly with MPLAB to offer a schematic display of signals and
peripheral devices.
KTechLab is a free and open source circuit simulator for KDE which features simulating
some types of PIC microcontrollers besides many other analog and digital parts.
Piklab is a free and open source IDE for developing PIC software on KDE. Piklab is able
to simulate and debug PIC software using another free and open source tool called gpsim
as a backend.
Real Pic Simulator is a commercial software developed by Digital Electro Soft. It is the
most powerful simulation engine in terms of simulated instructions per second.
These links take you to product selection matrices at the manufacturer's site.
8-bit microcontrollers
PIC10
PIC12
PIC14
PIC16
PIC17
PIC18
16-bit microcontrollers
PIC24F
PIC24H
32-bit microcontrollers
PIC32
dsPIC30
dsPIC33F
The F in a name generally indicates the PICmicro uses flash memory and can be erased
electronically. A C generally means it can only be erased by exposing the die to
ultraviolet light (which is only possible if a windowed package style is used). An
exception to this rule is the PIC16C84 which uses EEPROM and is therefore electrically
erasable.
The PIC's "code protection" features are not at all perfect; To some extent, the
weaknesses repeat themselves across the entire line of devices. But it should also be
acknowledged that Microchip has pushed out targeted revisions to the code protection
system as hacks have become widely known. Flylogic Engineering has documented some
of this ongoing back-and-forth on their website.
PIC16x84
Arduino
BASIC Atom
BASIC Stamp
Dwengo
OOPic
PICAXE
TI MSP430
[edit] References
1. ^ "PICmicro Family Tree", PIC16F Seminar Presentation
http://www.microchip.com.tw/PDF/2004_spring/PIC16F%20seminar
%20presentation.pdf
2. ^ a b "MOS DATA 1976", General Instrument 1976 Databook
3. ^ a b "1977 Data Catalog", Micro Electronics from General Instrument
Corporation http://www.rhoent.com/pic16xx.pdf
4. ^ Microchip Technology (27 February 2008). "Microchip Technology Delivers
Six Billionth PIC Microcontroller". Press release.
http://www.microchip.com/stellent/idcplg?
IdcService=SS_GET_PAGE&nodeId=2018&mcparam=en534302.
5. ^ "AN869: External Memory Interfacing Techniques for the PIC18F8XXX".
http://ww1.microchip.com/downloads/en/AppNotes/00869b.pdf. Retrieved 24
August 2009.
6. ^ "PIC Paging and PCLATH"
7. ^ [1]
8. ^ "PIC24H Family Overview".
http://ww1.microchip.com/downloads/en/DeviceDoc/70166A.pdf. Retrieved 23
September 2007.
9. ^ "32-bit PIC MCUs". http://www.microchip.com/en_US/family/pic32/.
Retrieved 13 October 2010.
10. ^ "MPLAB C Compiler for PIC18 MCUs".
http://www.microchip.com/stellent/idcplg?
IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010014.
11. ^ "Massmind: PIC Micro Controller C/C++ Languages".
http://techref.massmind.org/techref/microchip/language/cs.htm.
12. ^ "Oshon Software Project". http://oshonsoft.com.
13. ^ "mikroElectronika Compilers". http://www.mikroe.com/en/compilers/.
14. ^ "dsPIC blockset for simulink". http://www.kerhuel.eu/RTWdsPIC.
15. ^ "Piklab Homepage". SourceForge.net. 14 November 2007.
http://piklab.sourceforge.net/. Retrieved 16 August 2008.
16. ^ "Microchip Development Tools Showcase".
http://www.microchip.com/stellent/idcplg?
IdcService=SS_GET_PAGE&nodeId=81. Retrieved 4 January 2010.
17. ^ "MPLAB REAL ICE In-Circuit Emulator Product Overview".
http://ww1.microchip.com/downloads/en/DeviceDoc/51630a.pdf. Retrieved 23
September 2007.