Escolar Documentos
Profissional Documentos
Cultura Documentos
INTRODUCTION TO PIC
MICROCONTROLLERS
MZCET/EEE/EE6008/1
1.1
1.2
1.3
PIC16cxx-Pipelining
1.4
1.5
1.6
Instruction Set
1.7
Addressing modes
1.8
Simple Operations.
MZCET/EEE/EE6008/1
1.
1
Introduction
MZCET/EEE/EE6008/1
1.
1
Introduction
MZCET/EEE/EE6008/1
1.
1
Introduction
Classification of PIC
microcontroller
Low-end
Mid-range devices
architectures
12-bit wide
instructions
with basic I/O
functions.
1.
1
Introduction
Classification of PIC
microcontroller
Low-end
Mid-range devices
architectures
12C5XX
16C5X
16C505
16C6X
16C7X
16F87X
limited
More data/program
program
memory
Applicable in
memory
Applicable only
Medium range
in simple
projects.
interface
MZCET/EEE/EE6008/1
6
functions.
1.
1
Introducti
Princeton on
Architecture
MZCET/EEE/EE6008/1
1.
1
Introducti
Harvard on
Architecture
MZCET/EEE/EE6008/1
1.
2
Series of PIC16C6X
PIC16C61
PIC16C62
PIC16C62A
PIC16CR62
PIC16C63
PIC16CR63
PIC16C64
PIC16C64A
PIC16CR64
PIC16C65
PIC16C65A
PIC16CR65
PIC16C66
PIC16C67
MZCET/EEE/EE6008/1
1.
2
Core features of
PIC16C6X
10
1.
2
Core features of
PIC16C6X
Direct, indirect,
and relative addressing
modes
Power-on Reset (POR)
11
1.
2
Peripheral features of
PIC16C6X
12
1.
2
Peripheral features of
PIC16C6X
13
1.
2
MZCET/EEE/EE6008/1
14
1.
2
PinName
e
OSC1/CLKI I
N
O
OSC2/CLKO
UT
MCLR/VPP
I/P
RA0
RA1
RA2
I/O
I/O
I/O
Oscillatorcrystalinput/externalclock
sourceinput.
Oscillatorcrystaloutput.Connectsto
crystalor
resonator incrystal oscillatormode.
InRCmode,thepinoutputsCLKOUT
whichhas
1/4thefrequencyofOSC1,and
denotesthe
instructioncyclerate.
Masterclearresetinputorprogram
mingvoltage
input.Thispinisan
activelowresettothedevice.
PORTAisabi-directionalI/Oport.
MZCET/EEE/EE6008/1
15
1.
2
Pinout Description of
PIC16C61
PinTy Description
PinNa
me
pe
RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6
RB7
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
PORTBisabi-directionalI/Oport.
PORTBcanbesoftwareprogramme
dforinternalweakpulluponallinputs.
RB0canalsobetheexternalinterr
uptpin.
Interruptonchangepin.
Interruptonchangepin.
Interruptonchangepin.Serialprogramm
ingclock.
Interruptonchangepin.
MZCET/EEE/EE6008/1
16
Serialprogrammingdata.
1.
2
PIC16C
62
MZCET/EEE/EE6008/1
17
1.
2
MZCET/EEE/EE6008/1
18
1.
2
PIC16C6
3
PIC16CR
63
PIC16C6
6
MZCET/EEE/EE6008/1
19
1.
2
Pinout Description of
PIC16C62/62A/R62/63/R63
/66
PinName
PinTyp Description
e
OSC1/CLKIN I
O
OSC2/CLKO
UT
MCLR/VPP
I/P
RA0
RA1
I/O
I/O
Oscillatorcrystalinput/externalclocks
ourceinput.
Oscillatorcrystaloutput.Connectstocr
ystalor
resonator incrystal oscillatormode.
InRCmode,thepinoutputsCLKOUTw
hichhas
1/4thefrequencyofOSC1,and
denotesthe
instructioncyclerate.
Masterclearresetinputorprogrammin
gvoltage
input.Thispinisan
activelowresettothedevice.
PORTAisabi-directionalI/Oport.
MZCET/EEE/EE6008/1
20
1.
2
Pinout Description of
PIC16C62/62A/R62/63/R63
/66
PinNa PinTy Description
me
RB0/INT
RB1
RB2
RB3
RB4
RB5
RB6
RB7
pe
I/O
I/O
I/O
I/O
I/O
I/O
I/O
I/O
PORTBisabi-directionalI/Oport.
PORTBcanbesoftwareprogramme
dforinternalweakpulluponallinputs.
RB0canalsobetheexternalinterr
uptpin.
Interruptonchangepin.
Interruptonchangepin.
Interruptonchangepin.Serialprogramm
ingclock.
21
MZCET/EEE/EE6008/1
Interruptonchangepin.
1.2
Pinout Description of
PIC16C62/62A/R62/63/R63/66
PinName
RC0/T1OSO(1)/T1CKI
RC1/T1OSI(1)/CCP2(2)
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK(2)
RC7/RX/DT(2)
Pin Description
Type
I/O PORTC is a bi-directional I/O port.
RC0 can also be the Timer1 oscillator
output(1) or Timer1 clock input.
I/O RC1 can also be the Timer1 oscillator
input(1) or Capture2 input/Compare2
output/PWM2 output(2).
I/O RC2 can also be the Capture1
input/Compare1 output/PWM1 output.
I/O RC3 can also be the synchronous
serial clock input/output for both SPI
and I2C modes
I/O RC4 can also be the SPI Data In (SPI
mode) or data I/O (I2C mode).
I/O RC5 can also be the SPI Data Out (SPI
mode).
I/O RC6 can also be the USART
Asynchronous Transmit(2) or
Synchronous Clock(2).
22
I/O RC7 can alsoMZCET/EEE/EE6008/1
be the USART
1.
2
MZCET/EEE/EE6008/1
23
1.
2
MZCET/EEE/EE6008/1
24
1.
2
PIC16C65A
PIC16CR65
PIC16C67
MZCET/EEE/EE6008/1
25
1.
2
Pinout Description of
PIC16C64/64A/65/65A/67
PinName
PinTyp Description
e
OSC1/CLKIN I
Oscillatorcrystalinput/externalclocks
ourceinput.
Oscillatorcrystaloutput.Connectstocr
O
ystalor
OSC2/CLKO
resonator incrystal oscillatormode.
UT
InRCmode,thepinoutputsCLKOUTw
hichhas
1/4thefrequencyofOSC1,and
denotesthe
instructioncyclerate.
MCLR/VPP
I/P
Masterclearresetinputorprogrammin
gvoltage
input.Thispinisan
activelowresettothedevice.
RA0
I/O
PORTAisabi-directionalI/Oport.
26
RA1
I/O
MZCET/EEE/EE6008/1
1.
2
Pinout Description of
PIC16C64/64A/65/65A/67
1.2
Pinout Description of
PIC16C64/64A/65/65A/67
PinName
RC0/T1OSO(1)/T1CKI
RC1/T1OSI(1)/CCP2(2)
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK(2)
Pin Description
Type
I/O PORTC is a bi-directional I/O port.
RC0 can also be the Timer1 oscillator
output(1) or Timer1 clock input.
I/O RC1 can also be the Timer1 oscillator
input(1) or Capture2 input/Compare2
output/PWM2 output(2).
I/O RC2 can also be the Capture1
input/Compare1 output/
PWM1 output.
I/O RC3 can also be the synchronous
serial clock input/output for both SPI
and I2C modes
I/O RC4 can also be the SPI Data In (SPI
mode) or data I/O (I 2C mode).
I/O RC5 can also be the SPI Data Out (SPI
mode).
I/O RC6 can also be the USART
Asynchronous Transmit(2) or
28
Synchronous Clock(2).
MZCET/EEE/EE6008/1
1.
2
Pinout Description of
PIC16C64/64A/65/65A/67
PinName PinTyp
e
RD0/PSP I/O
0
I/O
RD1/PSP I/O
1
I/O
RD2/PSP I/O
2
I/O
RD3/PSP I/O
3
I/O
RD4/PSP
4
RD5/PSP
5
RD6/PSP
6
RD7/PSP
7
Description
PORTD can be a bi-directional I/O port or
parallel slave port for interfacing to a
microprocessor bus.
MZCET/EEE/EE6008/1
29
1.
2
C, as in
PIC16C64-
LC, as in
PIC16LC64
CR, as in
PIC16CR64
LCR, as in
PIC16LCR64
30
1.
2
UV Erasable Devices
31
1.
2
32
1.
2
Serialized
Quick-Turnaround
Production (SQTPSM) Devices
A unique programming service where a few userdefined locations in each device are programmed
with different serial numbers.
The serial numbers may be random, pseudorandom, or sequential.
Serial programming allows each device to have a
unique number which can serve as an entry-code,
password, or ID number.
ROM devices do not allow serialization information
in the program memory space.
The user may have this information programmed in
the data memory space.
MZCET/EEE/EE6008/1
33
1.
2
Architecture
of PIC16C61
MZCET/EEE/EE6008/1
34
1.
2
MZCET/EEE/EE6008/1
PIC16C62/62A/R62/64/64A/R64
BLOCK
35
1.
2
PIC16C62/62A/R62/64/64A/
R64 BLOCK DIAGRAM
MZCET/EEE/EE6008/1
36
1.
2
MZCET/EEE/EE6008/1
PIC16C63/R63/65/65A/R65
DIAGR
PIC16C63/R63/65/65A/R65 BLOCK 37
1.
2
MZCET/EEE/EE6008/1
38
1.
2
MZCET/EEE/EE6008/1PIC16C66/67
39
BLOCK DIAGRAM
1.
2
MZCET/EEE/EE6008/1
40
1.
2
Architectural overview
RISC microprocessors.
Harvard architecture, in which, program and
data are accessed from separate memories
using separate buses.
This improves bandwidth over traditional von
Neumann architecture.
Separating program and data busses further
allows instructions to be sized differently than
8-bit wide data words.
Instruction opcodes are 14-bits wide making it
possible to have all single word instructions.
A 14-bit wide program memory access bus
fetches a 14-bit instruction in a single cycle.
All instructions execute in a single cycle (200
ns @ 20 MHz) except for program branches.
MZCET/EEE/EE6008/1
41
1.
2
Architectural overview
1.
2
Architectural overview
43
1.
2
Comparison of 16C6X
series
PIC16C PIC16C PIC16C PIC16C PIC16C
61
62A
R62
63
R63
Clock
Maximu
m
Frequen
cy
of
Operatio
n (MHz)
20
20
20
20
20
Memor
y
EPROM
Program
Memory
(x14
words)
1K
2K
4K
ROM
Program
Memory
(x14
words)
2K
4K
Data
Memory
36
128
128
192
192
MZCET/EEE/EE6008/1
44
1.
2
Comparison of 16C6X
series
PIC16C6 PIC16C6 PIC16C6 PIC16C6
4A
5A
Clock
Maximum
Frequenc
y
of
Operation
(MHz)
20
20
20
20
Memory
EPROM
Program
Memory
(x14
words)
2K
4K
8K
8K
ROM
Program
Memory
(x14
words)
Data
Memory
(bytes)
128
192
368
368
MZCET/EEE/EE6008/1
45
1.
2
Comparison of 16C6X
series
PIC16C PIC16C PIC16C PIC16C PIC16C
61
Periphe Timer
rals
Module(
s)
TMR0
62A
R62
63
R63
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
Capture/
Compar
e/
PWM
Module(
s)
Serial
Port(s)
(SPI/I2C,
USART)
SPI/I2C
SPI/I2C
SPI/I2C
USART
SPI/I2C
USART
Parallel
Slave
Port
MZCET/EEE/EE6008/1
46
1.
2
Comparison of 16C6X
series
PIC16C6
4A
Peripher
als
PIC16C6
5A
PIC16C6
6
PIC16C6
7
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
Serial
Port(s)
(SPI/I2C,
USART)
SPI/I2C
SPI/I2C
USART
SPI/I2C
USART
SPI/I2C
USART
Parallel
Slave
Port
Yes
Yes
Yes
Yes
Timer
TMR0,
Module(s) TMR1,
TMR2
Capture/C
ompare/
PWM
Module(s)
MZCET/EEE/EE6008/1
47
1.
2
Comparison of 16C6X
series
PIC16C PIC16C6 PIC16CR6 PIC16C
61
Feature
s
Interrupt
Sources
2A
63
PIC16CR
63
10
10
I/O Pins
13
22
22
22
22
Voltage
Range
(Volts)
3.0-6.0
2.5-6.0
2.5-6.0
2.5-6.0
2.5-6.0
InCircuit
Serial
Program
ming
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Brownout
Reset
Package
s
18-pin 28-pin
DIP, SO SDIP,
28-pin
SDIP,
SOIC,
SOIC,
SSOP
MZCET/EEE/EE6008/1
SSOP
28-pin
SDIP,
SOIC
28-pin
SDIP,
SOIC
48
1.
2
Comparison of 16C6X
series
PIC16C6 PIC16C65 PIC16C66
PIC16C6
4A
Features
Interrupt
Sources
A
8
11
10
11
I/O Pins
33
33
22
33
Voltage
Range
(Volts)
2.5-6.0
2.5-6.0
2.5-6.0
2.5-6.0
In-Circuit
Serial
Programm
ing
Yes
Yes
Yes
Yes
Brown-out
Reset
Yes
Yes
Yes
Yes
Packages
40-pin
40-pin
DIP;
DIP;
44-pin
44-pin
PLCC,
PLCC,
MQFP,
MQFP,
TQFPMZCET/EEE/EE6008/1
TQFP
28-pin
SDIP,
SOIC,
SSOP
40-pin
DIP;
44-pin
PLCC,
MQFP,
TQFP
49
1.
2
PIC16C7
X
PIC16C7
2
PIC16C7
3
PIC 16C7X
series
PIC16C7
3A
PIC16C7
4
PIC16C7
4A
PIC16C7
6
PIC16C7
7
MZCET/EEE/EE6008/1
50
1.
2
51
1.
2
MZCET/EEE/EE6008/1
52
1.
2
53
1.
2
54
1.
2
PIC16C72
MZCET/EEE/EE6008/1
55
1.
2
PIC16C73
PIC16C76
MZCET/EEE/EE6008/1
56
1.
2
PIC16C74
PIC16C77
MZCET/EEE/EE6008/1
57
1.
2
PinName
e
OSC1/CLKIN I
O
OSC2/CLKO
UT
MCLR/VPP
I/P
RA0/AN0
RA1/AN1
RA2/AN2
I/O
I/O
I/O
Oscillatorcrystalinput/externalclocks
ourceinput.
Oscillatorcrystaloutput.Connectstocr
ystalor
resonator incrystal oscillatormode.
InRCmode,thepinoutputsCLKOUTw
hichhas
1/4thefrequencyofOSC1,and
denotesthe
instructioncyclerate.
Masterclearresetinputorprogrammin
gvoltage
input.Thispinisan
activelowresettothedevice.
PORTAisabi-directionalI/Oport.
Can also be analog input 0
Can also be analog input 1
58
Can also be analog
input 2
MZCET/EEE/EE6008/1
1.
2
1.2
PinName
RC0/T1OSO(1)/T1CKI
RC1/T1OSI(1)/CCP2(2)
RC2/CCP1
RC3/SCK/SCL
RC4/SDI/SDA
RC5/SDO
RC6/TX/CK(2)
RC7/RX/DT(2)
1.
2
Pinout Description of
PIC16C74/77
(additional
apart from 72/73/76)
PinName PinTyp
Description
e
RD0/PSP0 I/O
PORTD can be a bi-directional I/O port or
RD1/PSP1 I/O
parallel slave port for interfacing to a
RD2/PSP2 I/O
microprocessor bus.
RD3/PSP3 I/O
RD4/PSP4 I/O
RD5/PSP5 I/O
RD6/PSP6 I/O
RD7/PSP7 I/O
PORTE is a bi-directional I/O port.
RE0/RD/A I/O
RE0 can also be read control for the
N5
parallel slave port OR analog Input 5
I/O
RE1 can also be write control for the
RE1/WR/A
parallel slave port. Or
N6
I/O
Analog input 6
RE2 can also be select control for the
RE2/CS/A
parallel slave port or Analog input7
61
N7
MZCET/EEE/EE6008/1
1.
2
MZCET/EEE/EE6008/1
62
1.
2
PIC16C73/73A/76
BLOCK DIAGRAM
MZCET/EEE/EE6008/1
63
1.
2
PIC16C73/73A/76
DIAGRAM
BLOCK
Device
Program
Memory
Data
Memory
(RAM)
PIC16C73
4K x 14
192 x 8
PIC16C73A
4K x 14
192 x 8
PIC16C76
8K x 14
368 x 8
Note
1: Higher order bits are from the STATUS register.
2: Brown-out Reset is not available on the
PIC16C73.
MZCET/EEE/EE6008/1
64
1.
2
MZCET/EEE/EE6008/1
PIC16C74/74A/77
BLOCK DIAGRAM
65
1.
2
PIC16C74/74A/77
DIAGRAM
BLOCK
Device
Program
Memory
Data
Memory
(RAM)
PIC16C74
4K x 14
192 x 8
PIC16C74A
4K x 14
192 x 8
PIC16C77
8K x 14
368 x 8
Note
1: Higher order bits are from the STATUS register.
2: Brown-out Reset is not available on the
PIC16C74.
MZCET/EEE/EE6008/1
66
1.
2
Architectural overview
RISC microprocessors.
Harvard architecture
Improves bandwidth over traditional von
Neumann architecture
Separating program and data buses allows
instructions to be sized differently than the
8-bit wide data word.
Instruction opcodes are 14-bits wide
A 14-bit wide program memory access bus
fetches a 14-bit instruction in a single cycle.
MZCET/EEE/EE6008/1
67
1.
2
Architectural overview
68
1.
2
Architectural overview
CPU Registers
69
1.
2
Comparison of 16C7X
series
PIC16C PIC16C
72
73
PIC16C
74
PIC16C
76
PIC16C
77
Clock
Maximu
m
Frequen
cy
of
Operatio
n (MHz)
20
20
20
20
20
Memor
y
EPROM
Program
Memory
(x14
words)
2K
4K
4K
8K
8K
Data
Memory
(bytes)
128
192
192
368
368
MZCET/EEE/EE6008/1
70
1.
2
Comparison of 16C7X
series
PIC16C PIC16C PIC16C PIC16C PIC16C
Periphe Timer
rals
Module(
s)
72
73
74
76
77
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
TMR0,
TMR1,
TMR2
Capture/
Compar
e/
PWM
Module(
s)
Serial
Port(s)
(SPI/I2C,
USART)
SPI/I2C
SPI/I2C
USART
SPI/I2C
USART
SPI/I2C
USART
SPI/I2C
USART
Parallel
Slave
Port
Yes
Yes
A/D
MZCET/EEE/EE6008/1
5
71
1.
2
Comparison of 16C7X
series
PIC16C PIC16C7 PIC16C74 PIC16C PIC16C
72
Feature
s
Interrupt
Sources
3
8
11
12
76
77
11
12
I/O Pins
22
22
33
22
33
Voltage
Range
(Volts)
2.5-6.0
2.5-6.0
2.5-6.0
2.5-6.0
2.5-6.0
InCircuit
Serial
Program
ming
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Brownout
Reset
Package
s
28-pin
SDIP,
SOIC,
SSOP
28-pin
40-pin
SDIP,
SDIP,
SOIC,
PLCC,
SSOP
MZCET/EEE/EE6008/1
MQFP,
28-pin
SDIP,
SOIC
40-pin
SDIP,
PLCC,
72
MQFP,
1.
3
Pipelining
MZCET/EEE/EE6008/1
73
1.
3
Pipelining
MZCET/EEE/EE6008/1
74
1.
3
Pipelining
MZCET/EEE/EE6008/1
75
1.
3
Pipelining
Cyc
le
Fetch of
nth
instructi
on from
address
n
Cyc
le
Executio
n
of nth
instructi
on
Fetch of
(n+1)th
instruction
from
address
n+1
(goto New
address
Instruction)
Cyc
le
Cyc
le
Change
program
counter
to new
address
Fetch of
(n+2)th
instruction
from
address n+2
MZCET/EEE/EE6008/1
Ignore the
(n+2)th
instruction
Fetch
instruction
from new
address
76
1.
3
Pipelining
MZCET/EEE/EE6008/1
77
1.
3
Pipelining
Two cycle
instruction(Branch)
A fetch cycle begins with the program counter
(PC) incrementing in Q1.
In the execution cycle, the fetched instruction
is latched into the Instruction Register (IR) in
cycle Q1.
This instruction is then decoded and executed
during the Q2, Q3, and Q4 cycles.
Data memory is read during Q2 (operand read)
and written during Q4 (destination write).
MZCET/EEE/EE6008/1
78
1.
3
Pipelining (Example)
CY
1
CY
2
Fetc
h1
loop
CY
3
Execut
e1
Fetch 2 Execut
e2
Fetch3
Address Instruction
1
MOVLW 55h
MOVWF
PORTB
CALL SUB-1
CY
4
Execut
e3
Fetch4
CY
5
CY
6
Flush
Fetch
SUB-1
Execute
SUB-1
BSF PORTA,
All instructions
BIT3 are single cycle, except for any
branches.
These take two cycles since the
SUB-program
5
ADDW
fetch instruction is flushed from the pipeline while
1
the new instruction MZCET/EEE/EE6008/1
is being fetched and then
executed.
79
1.
4
Memory organisation
MZCET/EEE/EE6008/1
80
1.
4
1
2
11 10
X X 0 1 1 1 1 1 0 0 1 1
Ignored
Bits
Hex
address
000
Program
memory
7
2K
Addresses
(11 bit
range)
.
.
3E7
.
.
.
MZCET/EEE/EE6008/1
.
7FF
81
1.
4
1
2
11
X 1 0 1 1 1 0 1 0 0 1 0
Ignored
Bit
Hex
address
000
Program
memory
5
4K
Addresses
(12 bit
range)
.
.
BA5
.
.
.
MZCET/EEE/EE6008/1
.
FFF
82
1.
4
1.
4
84
1.
4
Program Memory
Map
Hex address
0
00
001
Goto main
line
Program
memory
002
003
004
005
Goto
Intservice
Tables
End of
Tables
Mainline
IntService
MZCET/EEE/EE6008/1
FFF
Mainline
program
and its
subroutine
s
Interrupt
service
routine
and its
subroutine
85
s
1.
4
can
be
86
Cause the CPU toMZCET/EEE/EE6008/1
jump to the beginning of
1.
4
87
1.
4
88
1.
4
1
2
000
.
.
PC LATH
PC
LATH,3 =
0
0
11
.
.
7FF
2K
Addresses
(11 bit
range)
4K
Addresses
(12 bit
range)
800
0
Program counter
(13 bit)
.
PC
LATH,3 =
1
MZCET/EEE/EE6008/1
.
FFF
.
89
1.
4
MZCET/EEE/EE6008/1
90
1.
4
91
1.
5
Data memory
MZCET/EEE/EE6008/1
92
1.
5
0
0
8
0
Special
Purpose
Registers
(32 bytes)
1
F
2
9
F
A
Special
Purpose
Registers
(32 bytes)
RAM
(32 bytes)
RAM
(96 bytes)
7
F
Bank 0
(128 bytes)
F
F
Extra RAM
(64 bytes)
In
PIC16C63
PIC16C65A
PIC16C73A
PIC16C74A
Bank 1
(128 bytes)
93
MZCET/EEE/EE6008/1
1.
5
Typical SFRs
GPR
General Purpose Registers STATUS
OPTION
User program data
PCLATH
PCL
Statusword+flags
Timeroptions
Componentsofpro
gram
counter(PC)
FileSelectforindir
SFR
FSR
ectdata
addressing
Special Function Registers
INTCON,PIR1, Componentsofinte
Reserved for
Control / configuration
Peripheral access
Indirect addressing
Program counter
Core SFRs
Appear in every bank at
MZCET/EEE/EE6008/1
same file address
PIE1,
PIR2,PIE2
rrupt
handling
PORTA,TRISA,
Accesstoparallelp
orts
TMR0,OPTION
,
INTCON,
Timer0
TXREG,TXSTA,
Accesstoserialpor
RCREG,RCSTA t
,
94
ADRESH,ADRE
1.
5
MZCET/EEE/EE6008/1
95
1.
5
1.
5
97
1.
5
98
1.
5
INDFRegister
NDF
Core SFR accessible at file address 00h in all banks
Virtual pointer not physical register In register file,
Tracks contents of FSR
Simplifies pointer arithmetic
[05] =
10h
[06] =
0Ah
xample
In register file,
Load FSR 05
[INDF] = 10h
[05]
= FSR
10h 05
Load
FSR
; points to file address 05
[06]
= 0Ah
[INDF]
= 10h
FSR++
FSR++
INDF
points to file address 05
;
= 06
0Ah
increment FSR [INDF]
FSR =
;
99
1.
5
100
1.
5
101
1.
5
TMR0
Rate
WDT Rate
000
1:2
1:1
001
1:4
1:2
010
1:8
1:4
011
1:16
1:8
100
1:32
1:16
101
1:64
1:32
110
1:128
1:64
111
1:256
1:128
MZCET/EEE/EE6008/1
102
1.
5
103
1.
5
104
1.
5
105
1.
5
1.
5
PCON REGISTER
(ADDRESS 8Eh)
R = Readable bit
W = Writable bit
U ='0'
Unimplemented bit,
bit 7-2: Unimplemented: Read as
read as
bit 1: POR: Power-on Reset Status 0
bit
1 = No Power-on Reset occurred- n = Value at POR reset
0 = A Power-on Reset occurred q = value depends on
conditions
107
1.
5
CPU Registers
Program Counter
PCH
PCH
= PC<12:8> = PCLATH<4:0> 3
PC 12 11 10 9 8 7 6 5 4
PCLATH<7:5> not implemented
4
0 PCLATH
MZCET/EEE/EE6008/1
108
1.
5
CPU Registers
The program counter (PC)
is 13-bits wide.
The low byte comes from
the PCL register, which is
a readable and writable
register.
The
upper
bits
(PC<12:8>)
are
not
readable,
but
are
indirectly
writable
through
the
PCLATH
register.
On any RESET, the upper
bits of the PC will be
cleared
The upper one how the
PC is loaded on a write to
PCL
(PCLATH<4:0>
MZCET/EEE/EE6008/1
109
PCH).
1.
5
InstructionMemoryS
pace
All8bitMCUs
Instruction address
n bit location address
Location = instruction
2n instructions
Instruction width
instruction 11 111
instruction 01 111
12 / 14 / 16 bits
instruction 01 011
Page
instruction 01 010
Partition of instruction
instruction 01 001
instruction 01 000
memory space
instruction 00 111
2k instructions / page
k bit offset
Page 1instruction 00 011
instruction 00 010
n bitaddress
instruction 00 001
instruction 00 000
n k bits
k bits
page offset
offset
page
Memory
MZCET/EEE/EE6008/1
Location Address 110
1.
5
InstructionMemoryS
pace
All8bitMCUs
Mid-Range instruction
memory
14-bit instruction word
13 bitPC
11 bits
2 bits
page
n = 13
12
11
k = 11
2 = 819211instruction words
Page
= 2 = 2048 = 800h words
10
offset
13
Reserved addresses
Address 0h
MZCET/EEE/EE6008/1
Reset vector pointer
to reset routine
111
1.
5
Call/Return
Stack
8 level FILO buffer
Holds 13 bit instruction addresses on CALL/RETURN
literal
CALL
STACK
PC
RETURN
10
12
11
10
PCLATH
Function entry
CALL instruction
STACK PC<12:0>
PCL literal<10:0> from instruction
PCH<12:11> PCLATH<4:3>
Function exit
RETURN instruction
PC<12:0> STACK
PCLATH not updated
MZCET/EEE/EE6008/1
May be different from
PCH after RETURN
112
InstructionFo
rmat
7
6
0
1.
6
13
opcode
13
10
7 6
opcode
Byte
d = oriented
0 destination = W
d = 1 destination = f
f = 7 bit file address
Bit oriented
opcode
13
11
opcode
General
literal
k = 8 bit literal (immediate)
CALL /
GOTO
k = 11 bit literal (immediate)
10
k
MZCET/EEE/EE6008/1
113
1.
6
Mnemoni
c
InstructionS
et
Single bit
Manipulation
Operan
ds
Description
Cycl
es
bcf
f,b
bsf
f,b
MZCET/EEE/EE6008/1
Status
bits
affected
114
1.
6
InstructionS
et
Clear/move
Mnemoni
c
Operan
ds
clrw
Description
Cycl
es
Status
bits
affected
Clear W
Z
Z
clrf
movlw
f
k
Clear f
Move literal value to
W
1
1
movwf
movf
swapf
115
1.
6
InstructionS
et
Increment/Decrement/comple
ment
Mnemoni
c
Operan
ds
incf
Description
Cycl
es
Status
bits
affected
decf
comf
f,F(W) Complement f,
putting result into F
or W
MZCET/EEE/EE6008/1
116
1.
6
InstructionS
et
Addition/Subtractio
n
Mnemoni
c
Operan
ds
addlw
Description
Cycl
es
Status
bits
affected
C, DC,
Z
addwf
C, DC,
Z
sublw
Subtract W from
literal value, putting
result in W
C, DC,
Z
subwf
C, DC,
Z
MZCET/EEE/EE6008/1
117
1.
6
InstructionS
et
Multiple bit
Mnemoni
c
manipulation
Operan
Description
Cycle
s
Status
bits
affected
andlw
andwf
f,F(W)
iorlw
Inclusive OR literal
value into W
iorwf
f,F(W)
Inclusive OR W with f, 1
Putting result into F or
W
xorlw
Exclusive OR literal
value into W
ds
MZCET/EEE/EE6008/1
118
1.
6
InstructionS
et
Rotate
Mnemoni
c
Operan
ds
rlf
rrf
Description
Cycl
es
Status
bits
affected
MZCET/EEE/EE6008/1
119
1.
6
InstructionS
et
Conditional Branch
Mnemoni
c
Operan
ds
Description
Cycl
es
btfsc
f,b
1
(2)
btfss
f,b
1
(2)
decfsz
1
(2)
incfsz
MZCET/EEE/EE6008/1
f,F(W) increment
f, putting
Status
bits
affected
120
1.
6
InstructionS
et
unconditional
Mnemoni
c
Branch Description
Operan
ds
Cycl
es
goto
Label
Go to labeled
instruction
call
label
Call labeled
instruction
Return from
subroutine
Return from
subroutine, putting
literal value in W
return
retlw
retfie
Return
from interrupt 2
MZCET/EEE/EE6008/1
Status
bits
affected
121
1.
6
InstructionS
et
Miscellaneous
Mnemoni
c
Operan
ds
Description
Cycl
es
Status
bits
affected
clrwdt
NOT_T
0,
NOT_P
D
sleep
Go to in standby
mode
NOT_T
0,
NOT_P
D
nop
No operation
MZCET/EEE/EE6008/1
122
1.
7
AddressingModes
Direct
Addressing
7
X
RP
1
RP
0
STATUS Register
Bank
Address
00
Content
MZCET/EEE/EE6008/1
Instruct
ion
80
Bank
0
7F
Bank
1
FF
123
1.
7
AddressingModes
REG<b>
REG<a:b>
Notation
Bitb inregisterREG
Bitsa tob
inregisterREG
ConcatenationofA
andB
A.B
(A bitsfollowedbyB
Direct addressing
RP1
bits)
Program specifies data address
Bank selection
RP0
7bitsfrominstruction
bank
8
6
7 5
fileaddress
4
0
1
File Address
Literal field in instructionMZCET/EEE/EE6008/1
124
1.
7
AddressingModes
Indirect Addressing
7
IRP
1
STATUS Register
FSR
1
Bank
Address
00
IND
F
MZCET/EEE/EE6008/1
80
Bank
0
7F
Bank
1
FF
125
1.
7
AddressingModes
Indirect addressing
Program writes to Special Function Registers (SFRs)
Address formed from SFRs
IRP
FSR<6:0>
8bitsofFSR
bank
Bank
fileaddress
6
IRP.FSR<7>
STATUS bit IRP (Indirect Register Pointer)
1
4
On small devices
1 or 2 banks = 128 or 256 bytes of data memory
8 bit FSR address covers 2 banks
IRP not implemented (read 0 / write = NOP)
MZCET/EEE/EE6008/1
126
1.
8
SampleProgra
m
In register file,
RAMInitialization
[05] =
CLRF STATUS ; STATUS 0
MOVLW 0x20 ; W 1st address in GPR bank10h
0
[06] =
MOVWF FSR ; Indirect address register W
0Ah
Bank0_LP
Load FSR
CLRF INDF0 ; address in GPR 0
05
INCF FSR
; FSR++ (next GPR address)
BTFSS FSR, 7
; skip if (FSR<7> == 1) FSR = 80h
[INDF] = 10h
GOTO Bank0_LP ; continue
; ** IF DEVICE HAS BANK1 **
MOVLW 0x80
1
FSR++
[INDF] = 0Ah
MOVWF FSR
; Indirect address register W
Bank1_LP
CLRF INDF0
; address in GPR 0
INCF FSR
; FSR++ (next GPR address)
BTFSS STATUS, C
; skip if (STATUS<0> == 1)
FSR = 00h
MZCET/EEE/EE6008/1
127
GOTO Bank1_LP
; continue
1.
8
SampleProgram
Prog:
Branchtoaddressinnew
page
; W Prog10<15:8>
g10:
128
1.
8
SampleProgram
movlw HIGH
Prog20
; W
Computedgoto
Prog20<15:8>
movwf PCLATH
; PCLATH W
movlw LOW Prog20
; W
Prog20<7:0>
movwf PCL
; PCL Prog20<7:0>
; PCH PCLATH<4:0>
g20:
129
1.
8
SampleProgra
ms
btfss f,b
ifelsebranch
; skip one instruction if
; bit b in register f = 1
goto Action2
Ye
s
Action1:
; instructions for Action1
goto Action3
F<b>
=1?
Action
1
Action2:
N
o
Action
2
Action3:
; instructions for Action3
MZCET/EEE/EE6008/1
130
1.
8
SamplePrograms
Staticloop
movlw times
; W times
; COUNTER W (times)
movwf COUNTER
Loop:
;
; loop instructions
;
decfsz COUNTER, f
; COUNTER-; COUNTER = 0 skip next
instruction
MZCET/EEE/EE6008/1
; next iteration
131
1..
8
SamplePrograms
Datatableininstructionmemory
;
; return with W 'A'
Table:
retlw
'A'
addwf PCL, f
retlw
'B'
retlw
'C'
132
Class Test-1
1. Explain the architecture of PIC16CXX
Series. (15)
2. Explain the classification of
instruction set. (15)
3. Explain the Pipelining Process.(8)
4. Write any four features of PIC 16CXX
series. (2)
5. Write the function of BOR register.(2)
MZCET/EEE/EE6008/1
133