1.4 PIC Microcontrollers
PIC microcontrollers designed by Microchip Technology are likely the best choice for beginners. Here is why...
The original name of this microcontroller is PICmicro (
Peripheral Interface Controller), but it is better known as PIC. Its ancestor, called the PIC1650, was designed in 1975 by
General Instruments. It was meant for totally different purposes. Around ten years later, this circuit was transformed into a real PIC microcontroller by adding EEPROM memory. Today,
Microchip Technology announces the manufacture of the 5 billionth sample.
If you are interested in learning more about it, just keep on reading.
The main idea with this book is to provide the user with necessary information so that he is able to use microcontrollers in practice after reading it. In order to avoid tedious explanations and endless story about the useful features of different microcontrollers, this book describes the operation of one particular model belonging to the ‘high middle class’. It is the PIC16F887- powerful enough to be worth attention and simple enough to be easily presented to everybody. So, the following chapters describe this microcontroller in detail, but refer to the whole PIC family as well.
Family |
ROM [Kbytes] |
RAM [bytes] |
Pins |
Clock Freq. [MHz] |
A/D Inputs |
Resolution of A/D Converter |
Compar- ators |
8/16 – bit Timers |
Serial Comm. |
PWM Outputs |
Others |
Base-Line 8 - bit architecture, 12-bit Instruction Word Length |
PIC10FXXX |
0.375 - 0.75 |
16 - 24 |
6 - 8 |
4 - 8 |
0 - 2 |
8 |
0 - 1 |
1 x 8 |
- |
- |
- |
PIC12FXXX |
0.75 - 1.5 |
25 - 38 |
8 |
4 - 8 |
0 - 3 |
8 |
0 - 1 |
1 x 8 |
- |
- |
EEPROM |
PIC16FXXX |
0.75 - 3 |
25 - 134 |
14 - 44 |
20 |
0 - 3 |
8 |
0 - 2 |
1 x 8 |
- |
- |
EEPROM |
PIC16HVXXX |
1.5 |
25 |
18 - 20 |
20 |
- |
- |
- |
1 x 8 |
- |
- |
Vdd = 15V |
Mid-Range 8 - bit architecture, 14-bit Instruction World Length |
PIC12FXXX |
1.75 - 3.5 |
64 - 128 |
8 |
20 |
0 - 4 |
10 |
1 |
1 - 2 x 8 1 x 16 |
- |
0 - 1 |
EEPROM |
PIC12HVXXX |
1.75 |
64 |
8 |
20 |
0 - 4 |
10 |
1 |
1 - 2 x 8 1 x 16 |
- |
0 - 1 |
- |
PIC16FXXX |
1.75 - 14 |
64 - 368 |
14 - 64 |
20 |
0 - 13 |
8 or 10 |
0 - 2 |
1 - 2 x 8 1 x 16 |
USART I2C SPI |
0 - 3 |
- |
PIC16HVXXX |
1.75 - 3.5 |
64 - 128 |
14 - 20 |
20 |
0 - 12 |
10 |
2 |
2 x 8 1 x 16 |
USART I2C SPI |
- |
- |
High-End 8 - bit architecture, 16-bit Instruction Word Length |
PIC18FXXX |
4 - 128 |
256 - 3936 |
18 - 80 |
32 - 48 |
4 - 16 |
10 or 12 |
0 - 3 |
0 - 2 x 8 2 - 3 x 16 |
USB2.0 CAN2.0 USART I2C SPI |
0 - 5 |
- |
PIC18FXXJXX |
8 - 128 |
1024 - 3936 |
28 - 100 |
40 - 48 |
10 - 16 |
10 |
2 |
0 - 2 x 8 2 - 3 x 16 |
USB2.0 USART Ethernet I2C SPI |
2 - 5 |
- |
PIC18FXXKXX |
8 - 64 |
768 - 3936 |
28 - 44 |
64 |
10 - 13 |
10 |
2 |
1 x 8 3 x 16 |
USART I2C SPI |
2 |
- |
All PIC microcontrollers use Harvard architecture, which means that their program memory is connected to the CPU over more than 8 lines. Depending on the bus width, there are 12-, 14- and 16-bit microcontrollers. Table above shows the main features of these three categories.
As seen in the table on the previous page, excepting ‘16-bit monsters’- PIC 24FXXX and PIC 24HXXX- all PIC microcontrollers have 8-bit Harvard architecture and belong to one out of three large groups. Thus, depending on the size of the program word there are first, second and third microcontroller category, i.e. 12-, 14- or 16-bit microcontrollers. Having similar 8-bit core, all of them use the same instruction set and the basic hardware ‘skeleton’ connected to more or less peripheral units.
INSTRUCTION SET
The instruction set for the 16F8XX includes 35 instructions in total. The reason for such a small number of instructions lies in the RISC architecture. It means that instructions are well optimized from the aspects of operating speed, simplicity in architecture and code compactness. The bad thing about RISC architecture is that the programmer is expected to cope with these instructions. Of course, this is relevant only if you use assembly language for programming. This book refers to programming in the higher programming language C, which means that most work has been done by somebody else. You just have to use relatively simple instructions.
INSTRUCTION EXECUTION TIME
All instructions are single-cycle instructions. The only exception may be conditional branch instructions (if condition is met) or instructions performed upon the program counter. In both cases, two cycles are required for instruction execution, while the second cycle is executed as an NOP (
No Operation). Single-cycle instructions consist of four clock cycles. If 4MHz oscillator is used, the nominal time for instruction execution is 1μS. As for jump instructions, the instruction execution time is 2μS.
Instruction set of 14-bit PIC microcontrollers:
INSTRUCTION |
DESCRIPTION |
OPERATION |
FLAG |
CLK |
* |
Data Transfer Instructions |
MOVLW k |
Move constant to W |
k -> w |
|
1 |
|
MOVWF f |
Move W to f |
W -> f |
|
1 |
|
MOVF f,d |
Move f to d |
f -> d |
Z |
1 |
1, 2 |
CLRW |
Clear W |
0 -> W |
Z |
1 |
|
CLRF f |
Clear f |
0 -> f |
Z |
1 |
2 |
SWAPF f,d |
Swap nibbles in f |
f(7:4),(3:0) -> f(3:0),(7:4) |
|
1 |
1, 2 |
Arithmetic-logic Instructions |
ADDLW k |
Add W and constant |
W+k -> W |
C, DC, Z |
1 |
|
ADDWF f,d |
Add W and f |
W+f -> d |
C, DC ,Z |
1 |
1, 2 |
SUBLW k |
Subtract W from constant |
k-W -> W |
C, DC, Z |
1 |
|
SUBWF f,d |
Subtract W from f |
f-W -> d |
C, DC, Z |
1 |
1, 2 |
ANDLW k |
Logical AND with W with constant |
W AND k -> W |
Z |
1 |
|
ANDWF f,d |
Logical AND with W with f |
W AND f -> d |
Z |
1 |
1, 2 |
ANDWF f,d |
Logical AND with W with f |
W AND f -> d |
Z |
1 |
1, 2 |
IORLW k |
Logical OR with W with constant |
W OR k -> W |
Z |
1 |
|
IORWF f,d |
Logical OR with W with f |
W OR f -> d |
Z |
1 |
1, 2 |
XORWF f,d |
Logical exclusive OR with W with constant |
W XOR k -> W |
Z |
1 |
1, 2 |
XORLW k |
Logical exclusive OR with W with f |
W XOR f -> d |
Z |
1 |
|
INCF f,d |
Increment f by 1 |
f+1 -> f |
Z |
1 |
1, 2 |
DECF f,d |
Decrement f by 1 |
f-1 -> f |
Z |
1 |
1, 2 |
RLF f,d |
Rotate left f through CARRY bit |
|
C |
1 |
1, 2 |
RRF f,d |
Rotate right f through CARRY bit |
|
C |
1 |
1, 2 |
COMF f,d |
Complement f |
f -> d |
Z |
1 |
1, 2 |
Bit-oriented Instructions |
BCF f,b |
Clear bit b in f |
0 -> f(b) |
|
1 |
1, 2 |
BSF f,b |
Clear bit b in f |
1 -> f(b) |
|
1 |
1, 2 |
Program Control Instructions |
BTFSC f,b |
Test bit b of f. Skip the following instruction if clear. |
Skip if f(b) = 0 |
|
1 (2) |
3 |
BTFSS f,b |
Test bit b of f. Skip the following instruction if set. |
Skip if f(b) = 1 |
|
1 (2) |
3 |
DECFSZ f,d |
Decrement f. Skip the following instruction if clear. |
f-1 -> d skip if Z = 1 |
|
1 (2) |
1, 2, 3 |
INCFSZ f,d |
Increment f. Skip the following instruction if set. |
f+1 -> d skip if Z = 0 |
|
1 (2) |
1, 2, 3 |
GOTO k |
Go to address |
k -> PC |
|
2 |
|
CALL k |
Call subroutine |
PC -> TOS, k -> PC |
|
2 |
|
RETURN |
Return from subroutine |
TOS -> PC |
|
2 |
|
RETLW k |
Return with constant in W |
k -> W, TOS -> PC |
|
2 |
|
RETFIE |
Return from interrupt |
TOS -> PC, 1 -> GIE |
|
2 |
|
Other instructions |
NOP |
No operation |
TOS -> PC, 1 -> GIE |
|
1 |
|
CLRWDT |
Clear watchdog timer |
0 -> WDT, 1 -> TO, 1 -> PD |
TO, PD |
1 |
|
SLEEP |
Go into sleep mode |
0 -> WDT, 1 -> TO, 0 -> PD |
TO, PD |
1 |
|
*1 When an I/O register is modified as a function of itself, the value used will be that value present on the pins themselves.
*2 If the instruction is executed on the TMR register and if d=1, the prescaler will be cleared.
*3 If the PC is modified or test result is logic one (1), the instruction requires two cycles.
The architecture of 8-bit PIC microcontrollers. Which of these modules are to belong to a microcontroller depends on its type.