AMC Unit I PPT
AMC Unit I PPT
AMC Unit I PPT
INTRODUCTION TO PIC
MICROCONTROLLERS
1
2
1.1
Introduction
3
1.1
Introduction
4
1.1
Introduction
Classification of PIC microcontroller
Low-end architectures Mid-range devices
• 12-bit wide • Upgradation of low-end
instructions with architectures with more
basic I/O functions. number of peripherals,
more number of registers.
• An enhancement of Analog
to Digital converter
capability
5
1.1
Introduction
Classification of PIC microcontroller
Low-end architectures Mid-range devices
• 12C5XX • 16C6X
• 16C5X • 16C7X
• 16F87X
• 16C505
• limited program • More data/program
memory memory
• Applicable only in • Applicable in Medium range
simple interface projects.
functions.
6
1.1
Introduction
Princeton Architecture
7
1.1
Introduction
Harvard Architecture
8
1.2
Series of PIC16C6X
• PIC16C61 • PIC16C64A
• PIC16C62 • PIC16CR64
• PIC16C62A • PIC16C65
• PIC16CR62 • PIC16C65A
• PIC16C63 • PIC16CR65
• PIC16CR63 • PIC16C66
• PIC16C64 • PIC16C67
9
1.2
Core features of PIC16C6X
10
1.2
Core features of PIC16C6X
11
1.2
Peripheral features of PIC16C6X
12
1.2
Peripheral features of PIC16C6X
13
1.2
Pin Diagram of PIC16C6X
14
1.2
Pin out Description of PIC16C61
Pin Name Pin Type Description
OSC1/CLKIN I Oscillator crystal input/
external clock source input.
Oscillator crystal output. Connects to crystal or
O resonator in crystal oscillator mode.
OSC2/CLKOUT In RC mode, the pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the
instruction cycle rate.
MCLR/VPP I/P Master clear reset input or programming voltage
input. This pin is an active low reset to the device.
PORTA is a bi-directional I/O port.
RA0 I/O
RA1 I/O
RA2 I/O
RA3 I/O
RA4/T0CKI I/O RA4 can also be the clock input to the Timer0
timer/counter.
Output is open drain type.
15
1.2
Pinout Description of PIC16C61
Pin Name Pin Type Description
PORTB is a bi-directional I/O port.
PORTB can be software programmed for internal
weak pull-up on all inputs.
RB0/INT I/O RB0 can also be the external interrupt pin.
RB1 I/O
RB2 I/O
RB3 I/O
RB4 I/O Interrupt on change pin.
RB5 I/O Interrupt on change pin.
RB6 I/O Interrupt on change pin. Serial programming clock.
RB7 I/O Interrupt on change pin. Serial programming data.
VSS P Ground reference for logic and I/O pins.
VDD P Positive supply for logic and I/O pins.
16
1.2
Pin Diagram of PIC16C6X
PIC16C62
17
1.2
Pin Diagram of PIC16C6X
18
1.2
Pin Diagram of PIC16C6X
PIC16C63
PIC16CR63
PIC16C66
19
1.2
Pinout Description of
PIC16C62/62A/R62/63/R63/66
Pin Name Pin Type Description
OSC1/CLKIN I Oscillator crystal input/external clock source input.
Oscillator crystal output. Connects to crystal or
O resonator in crystal oscillator mode.
OSC2/CLKOUT In RC mode, the pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the
instruction cycle rate.
MCLR/VPP I/P Master clear reset input or programming voltage
input. This pin is an active low reset to the device.
RA0 I/O PORTA is a bi-directional I/O port.
RA1 I/O
RA2 I/O
RA3 I/O
RA4/T0CKI I/O RA4 can also be the clock input to the Timer0
timer/counter. Output is open drain type.
RA5/SS RA5 can also be the slave select for the synchronous
serial port. 20
1.2
Pinout Description of
PIC16C62/62A/R62/63/R63/66
Pin Name Pin Type Description
PORTB is a bi-directional I/O port.
PORTB can be software programmed for internal
weak pull-up on all inputs.
RB0/INT I/O RB0 can also be the external interrupt pin.
RB1 I/O
RB2 I/O
RB3 I/O
RB4 I/O Interrupt on change pin.
RB5 I/O Interrupt on change pin.
RB6 I/O Interrupt on change pin. Serial programming clock.
RB7 I/O Interrupt on change pin. Serial programming data.
VSS P Ground reference for logic and I/O pins.
VDD P Positive supply for logic and I/O pins.
21
1.2 Pinout Description of
PIC16C62/62A/R62/63/R63/66
Pin Name Pin Description
Type
I/O PORTC is a bi-directional I/O port.
RC0/T1OSO(1)/T1CKI RC0 can also be the Timer1 oscillator output(1) or
Timer1 clock input.
RC1/T1OSI(1)/CCP2(2) I/O RC1 can also be the Timer1 oscillator input(1) or
Capture2 input/Compare2 output/PWM2 output(2).
MZCET/EEE/EE6008/1 23
1.2
Pin Diagram of PIC16C6X
24
1.2
Pin Diagram of PIC16C6X
PIC16C65A
PIC16CR65
PIC16C67
25
1.2
Pinout Description of
PIC16C64/64A/65/65A/67
Pin Name Pin Type Description
OSC1/CLKIN I Oscillator crystal input/external clock source input.
Oscillator crystal output. Connects to crystal or
O resonator in crystal oscillator mode.
OSC2/CLKOUT In RC mode, the pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the
instruction cycle rate.
MCLR/VPP I/P Master clear reset input or programming voltage
input. This pin is an active low reset to the device.
RA0 I/O PORTA is a bi-directional I/O port.
RA1 I/O
RA2 I/O
RA3 I/O
RA4/T0CKI I/O RA4 can also be the clock input to the Timer0
timer/counter. Output is open drain type.
RA5/SS RA5 can also be the slave select for the synchronous
serial port. 26
1.2
Pinout Description of
PIC16C64/64A/65/65A/67
Pin Name Pin Type Description
PORTB is a bi-directional I/O port.
PORTB can be software programmed for internal
weak pull-up on all inputs.
RB0/INT I/O RB0 can also be the external interrupt pin.
RB1 I/O
RB2 I/O
RB3 I/O
RB4 I/O Interrupt on change pin.
RB5 I/O Interrupt on change pin.
RB6 I/O Interrupt on change pin. Serial programming clock.
RB7 I/O Interrupt on change pin. Serial programming data.
VSS P Ground reference for logic and I/O pins.
VDD P Positive supply for logic and I/O pins.
27
1.2
Pinout Description of
PIC16C64/64A/65/65A/67
Pin Name Pin Description
Type
I/O PORTC is a bi-directional I/O port.
RC0/T1OSO(1)/T1CKI RC0 can also be the Timer1 oscillator output(1) or
Timer1 clock input.
RC1/T1OSI(1)/CCP2(2) I/O RC1 can also be the Timer1 oscillator input(1) or
Capture2 input/Compare2 output/PWM2 output(2).
29
1.2
PIC16C6X Device varieties
C, as in PIC16C64- EPROM type memory and
operate over the standard
voltage range
LC, as in PIC16LC64 EPROM type memory and
operate over an extended
voltage range
CR, as in PIC16CR64 ROM program memory and
operate over the standard
voltage range
LCR, as in ROM program memory and
PIC16LCR64 operate over an extended
voltage range
30
1.2
PIC16C6X Device varieties
UV Erasable Devices
• The UV erasable version, offered in CERDIP package is optimal
for prototype development and pilot programs.
• This version can be erased and reprogrammed to any of the
oscillator modes.
One-Time-Programmable (OTP) Devices
• Flexibility for frequent code updates and small volume
applications.
• Packaged in plastic packages, permit the user to program
them once.
• In addition to the program memory, the configuration bits
must also be programmed.
31
1.2
PIC16C6X DEVICE VARIETIES
Quick-Turnaround-Production (QTP) Devices
32
1.2
PIC16C6X DEVICE VARIETIES
Serialized Quick-Turnaround Production
(SQTPSM) Devices
• A unique programming service where a few user-defined
locations in each device are programmed with different serial
numbers.
• The serial numbers may be random, pseudo-random, 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.
33
1.2
Architecture of
PIC16C61
34
1.2
2: PORTD, PORTE and the Parallel Slave Port are not available on
the PIC16C62/62A/R62.
36
1.2
37
PIC16C63/R63/65/65A/R65 BLOCK DIAGRAM
1.2
PIC16C63/R63/65/65A/R65 BLOCK DIAGRAM
2: PORTD, PORTE and the Parallel Slave Port are not available
on the PIC16C63/R63.
38
1.2
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.
41
1.2
Architectural overview
• The PIC16CXX device contains an 8-bit ALU and working
register (W).
42
1.2
Architectural overview
Working register (W register)
43
1.2 Comparison of 16C6X series
PIC16C61 PIC16C62A PIC16CR62 PIC16C63 PIC16CR63
Clock Maximum 20 20 20 20 20
Frequency
of
Operation
(MHz)
Memory EPROM 1K 2K - 4K -
Program
Memory
(x14 words)
ROM - - 2K - 4K
Program
Memory
(x14 words)
Data 36 128 128 192 192
Memory
(bytes)
44
1.2 Comparison of 16C6X series
PIC16C64A PIC16C65A PIC16C66 PIC16C67
Clock Maximum 20 20 20 20
Frequency
of Operation
(MHz)
Memory EPROM 2K 4K 8K 8K
Program
Memory
(x14 words)
ROM - - - -
Program
Memory
(x14 words)
Data Memory 128 192 368 368
(bytes)
45
1.2 Comparison of 16C6X series
PIC16C61 PIC16C62A PIC16CR62 PIC16C63 PIC16CR63
46
1.2 Comparison of 16C6X series
PIC16C64A PIC16C65A PIC16C66 PIC16C67
Peripherals Timer TMR0, TMR0, TMR0, TMR0,
Module(s) TMR1, TMR1, TMR1, TMR1,
TMR2 TMR2 TMR2 TMR2
Capture/ 1 2 2 2
Compare/
PWM
Module(s)
Serial Port(s) SPI/I2C SPI/I2C SPI/I2C SPI/I2C
(SPI/I2C, USART USART USART
USART)
Parallel Slave Yes Yes Yes Yes
Port
47
1.2 Comparison of 16C6X series
PIC16C61 PIC16C62A PIC16CR62 PIC16C63 PIC16CR63
Features Interrupt 3 7 7 10 10
Sources
I/O Pins 13 22 22 22 22
Voltage 3.0-6.0 2.5-6.0 2.5-6.0 2.5-6.0 2.5-6.0
Range
(Volts)
In-Circuit Yes Yes Yes Yes Yes
Serial
Programmin
g
Brown-out - Yes Yes Yes Yes
Reset
Packages 18-pin 28-pin SDIP, 28-pin SDIP, 28-pin 28-pin
DIP, SO SOIC, SSOP SOIC, SSOP SDIP, SDIP,
SOIC SOIC
48
1.2 Comparison of 16C6X series
PIC16C64A PIC16C65A PIC16C66 PIC16C67
Features Interrupt 8 11 10 11
Sources
I/O Pins 33 33 22 33
Voltage Range 2.5-6.0 2.5-6.0 2.5-6.0 2.5-6.0
(Volts)
In-Circuit Yes Yes Yes Yes
Serial
Programming
Brown-out Yes Yes Yes Yes
Reset
Packages 40-pin DIP; 40-pin DIP; 28-pin SDIP, 40-pin DIP;
44-pin 44-pin PLCC, SOIC, SSOP 44-pin
PLCC, MQFP, TQFP PLCC,
MQFP, MQFP,
TQFP TQFP
49
1.2
PIC16C7X
PIC 16C7X
series
50
1.2
PIC16C7X Core Features:
MZCET/EEE/EE6008/1 51
1.2
PIC16C7X Core Features:
52
1.2
PIC16C7X Peripheral Features:
53
1.2
PIC16C7X Peripheral Features:
54
1.2
Pin Diagram of PIC16C7X
PIC16C72
55
1.2
Pin Diagram of PIC16C7X
PIC16C73
PIC16C76
56
1.2
Pin Diagram of PIC16C7X
PIC16C74
PIC16C77
57
1.2 Pin out Description of PIC16C72/73/76
Pin Name Pin Type Description
OSC1/CLKIN I Oscillator crystal input/external clock source input.
Oscillator crystal output. Connects to crystal or
O resonator in crystal oscillator mode.
OSC2/CLKOUT In RC mode, the pin outputs CLKOUT which has
1/4 the frequency of OSC1, and denotes the
instruction cycle rate.
MCLR/VPP I/P Master clear reset input or programming voltage
input. This pin is an active low reset to the device.
PORTA is a bi-directional I/O port.
RA0/AN0 I/O Can also be analog input 0
RA1/AN1 I/O Can also be analog input 1
RA2/AN2 I/O Can also be analog input 2
RA3/AN3/Vref I/O Can also be analog input 3
RA4/T0CKI I/O RA4 can also be the clock input to the Timer0
timer/counter. Output is open drain type.
RA5/SS/AN4 RA5 can also be the slave select for the synchronous
serial port. Or analog input 4
58
1.2 Pin out Description of PIC16C72/73/76
Pin Name Pin Type Description
PORTB is a bi-directional I/O port.
PORTB can be software programmed for internal
weak pull-up on all inputs.
RB0/INT I/O RB0 can also be the external interrupt pin.
RB1 I/O
RB2 I/O
RB3 I/O
RB4 I/O Interrupt on change pin.
RB5 I/O Interrupt on change pin.
RB6 I/O Interrupt on change pin. Serial programming clock.
RB7 I/O Interrupt on change pin. Serial programming data.
VSS P Ground reference for logic and I/O pins.
VDD P Positive supply for logic and I/O pins.
59
1.2
Pin out Description of PIC16C72/73/76
Pin Name Pin Description
Type
I/O PORTC is a bi-directional I/O port.
RC0/T1OSO(1)/T1CKI RC0 can also be the Timer1 oscillator output(1) or
Timer1 clock input.
RC1/T1OSI(1)/CCP2(2) I/O RC1 can also be the Timer1 oscillator input(1) or
Capture2 input/Compare2 output/PWM2 output(2).
62
1.2
PIC16C73/73A/76
BLOCK DIAGRAM
63
1.2 PIC16C73/73A/76 BLOCK DIAGRAM
Device Program Data Memory
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.
64
1.2
PIC16C74/74A/77
BLOCK DIAGRAM
65
1.2 PIC16C74/74A/77 BLOCK DIAGRAM
Device Program Data Memory
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.
66
1.2 Architectural overview
67
1.2 Architectural overview
68
1.2
Architectural overview
CPU Registers
69
1.2
Comparison of 16C7X series
PIC16C72 PIC16C73 PIC16C74 PIC16C76 PIC16C77
Clock Maximum 20 20 20 20 20
Frequency
of
Operation
(MHz)
Memory EPROM 2K 4K 4K 8K 8K
Program
Memory
(x14 words)
Data 128 192 192 368 368
Memory
(bytes)
70
1.2
Comparison of 16C7X series
PIC16C72 PIC16C73 PIC16C74 PIC16C76 PIC16C77
Peripherals Timer TMR0, TMR0, TMR0, TMR0, TMR0,
Module(s) TMR1, TMR1, TMR1, TMR1, TMR1,
TMR2 TMR2 TMR2 TMR2 TMR2
Capture/ 1 2 2 2 2
Compare/
PWM
Module(s)
Serial SPI/I2C SPI/I2C SPI/I2C SPI/I2C SPI/I2C
Port(s) USART USART USART USART
(SPI/I2C,
USART)
Parallel - - Yes - Yes
Slave Port
A/D 5 5 8 5 8
Converter
Channels
71
1.2 Comparison of 16C7X series
PIC16C72 PIC16C73 PIC16C74 PIC16C76 PIC16C77
Features Interrupt 8 11 12 11 12
Sources
I/O Pins 22 22 33 22 33
Voltage 2.5-6.0 2.5-6.0 2.5-6.0 2.5-6.0 2.5-6.0
Range
(Volts)
In-Circuit Yes Yes Yes Yes Yes
Serial
Programmin
g
Brown-out - Yes Yes Yes Yes
Reset
Packages 28-pin 28-pin SDIP, 40-pin SDIP, 28-pin 40-pin
SDIP, SOIC, SSOP PLCC, MQFP, SDIP, SDIP,
SOIC, TQFP SOIC PLCC,
SSOP MQFP,
TQFP
72
1.3 Pipelining
73
1.3 Pipelining
74
1.3 Pipelining
Clocking Scheme/Instruction Cycle
75
1.3 Pipelining
Cycle Cycle Cycle Cycle
Fetch of nth
Execution
instruction
of nth
from
instruction
address n
Fetch of (n+1)th
Change
instruction from
program
address n+1
counter to
(goto New
new address
address
Instruction)
Fetch of (n+2)th Ignore the (n+2)th
instruction from instruction
address n+2
Fetch instruction
from new address
MZCET/EEE/EE6008/1 76
1.3 Pipelining
MZCET/EEE/EE6008/1 77
1.3 Pipelining
Two cycle instruction(Branch)
78
1.3 Pipelining (Example)
CY1 CY2 CY3 CY4 CY5 CY6
Fetch1 Execute1
Fetch 2 Execute2
Fetch3 Execute3
80
1.4
Program memory Considerations
How to access 2K Program memory
Program memory
Program counter (13 bit) Hex address
000
12 11 10 0
X X 0 1 1 1 1 1 0 0 1 1 1
3 E 7
.
2K
Addresses .
Ignored Bits
(11 bit range) .
3E7
.
.
.
.
81
7FF
1.4
Program memory Considerations
How to access 4K Program memory
Program memory
Program counter (13 bit) Hex address
000
12 11 0
X 1 0 1 1 1 0 1 0 0 1 0 1
B A 5
.
4K
Addresses .
Ignored Bit
(12 bit range) .
BA5
.
.
.
.
82
FFF
1.4
Program memory Considerations
• Each PIC 16CXX family either consists of 2K or 4K addresses of
program memory
• For the 4K and 2K parts the upper bits are similarly ingored
during fetches from program memory.
83
1.4
Program memory Considerations
MZCET/EEE/EE6008/1 84
1.4
Program memory Considerations
Program Memory Map Hex address 0 00 Goto main line Program memory
001
002
003
004 Go to Int service
005
Tables
End of Tables
Mainline
Mainline
program and
its subroutines
IntService
Interrupt
service routine
and its
End of subroutines
code . 85
MZCET/EEE/EE6008/1 FFF
1.4
Program memory Considerations
MZCET/EEE/EE6008/1 87
1.4
Program memory Considerations
• CPU begins the execution of the interrupt service
routine by automaticaaly loading the program
counter with H’004’.
• At the completion of interrupt service routine,
CPU returns to where it left off in the Mainline
program.
• Program writing is somewhat simplified if all the
program code for the tables, the mainline
program and its subroutines, interrupt service
routine and its subroutines take up less than 2K
words of instruction.
MZCET/EEE/EE6008/1 88
1.4
Program memory Considerations
Program memory
How 11 bit call instruction is executed
Hex address
X X
000
.
4 3 . 2K
0 PC LATH . Addresses
PC LATH,3 = (11 bit range)
0 .
7FF 4K
12 11 0 Addresses
800
(12 bit range)
0
FFF
MZCET/EEE/EE6008/1 89
1.4
Program memory Considerations
MZCET/EEE/EE6008/1 90
1.4
Program memory Considerations
MZCET/EEE/EE6008/1 91
1.5 Data memory
MZCET/EEE/EE6008/1 92
1.5 Register File Structure
00 80
20
RAM
(32 bytes)
95
1.5 SPECIAL FUNCTION REGISTERS
bit 7 IRP(1): Register Bank Select bit (used for indirect addressing)
1 = Bank 2, 3 (100h - 1FFh) ; 0 = Bank 0, 1 (00h - FFh)
bit 6-5 RP1(1):RP0: Register Bank Select bits (used for direct addressing)
11 = Bank 3 (180h - 1FFh) ;
10 = Bank 2 (100h - 17Fh) ;
01 = Bank 1 (80h - FFh) ;
00 = Bank 0 (00h - 7Fh)
Each bank is 128 bytes
bit 4 TO: Time-out bit
1 = After power-up, CLRWDT instruction, or SLEEP instruction
0 = A WDT time-out occurred
96
1.5 SPECIAL FUNCTION REGISTERS
97
1.5 Special Purpose Registers
98
1.5 SPECIAL FUNCTION REGISTERS
INDF INDF Register
Core SFR accessible at file address 00h in all banks
Virtual pointer — not physical register In register file,
Tracks contents of FSR [05] = 10h
Simplifies pointer arithmetic [06] = 0Ah
Load FSR ← 05
Example
[INDF] = 10h
In register file,
FSR++
[05] = 10h
[INDF] = 0Ah
[06] = 0Ah
99
1.5 SPECIAL FUNCTION REGISTERS
101
1.5 SPECIAL FUNCTION REGISTERS
102
1.5 SPECIAL FUNCTION REGISTERS
105
1.5 SPECIAL FUNCTION REGISTERS
PIE1 Register (ADDRESS 8Ch)
bit 4 TXIE: USART Transmit Interrupt Enable bit
1 = Enables the USART transmit interrupt;
0 = Disables the USART transmit interrupt
bit 3 SSPIE: Synchronous Serial Port Interrupt Enable bit
1 = Enables the SSP interrupt;
0 = Disables the SSP interrupt
bit 2 CCP1IE: CCP1 Interrupt Enable bit
1 = Enables the CCP1 interrupt;
0 = Disables the CCP1 interrupt
bit 1 TMR2IE: TMR2 to PR2 Match Interrupt Enable bit
1 = Enables the TMR2 to PR2 match interrupt;
0 = Disables the TMR2 to PR2 match interrupt
bit 0 TMR1IE: TMR1 Overflow Interrupt Enable bit
1 = Enables the TMR1 overflow interrupt;
0 = Disables the TMR1 overflow interrupt
106
1.5 SPECIAL FUNCTION REGISTERS
R = Readable bit
W = Writable bit
bit 7-2: Unimplemented: Read as '0' U = Unimplemented bit, read as
bit 1: POR: Power-on Reset Status bit ‘0’
1 = No Power-on Reset occurred - n = Value at POR reset
0 = A Power-on Reset occurred q = value depends on conditions
(must be set in software after a Power-on Reset occurs)
bit 0: BOR: Brown-out Reset Status bit
1 = No Brown-out Reset occurred
0 = A Brown-out Reset occurred
(must be set in software after a Brown-out Reset occurs)
107
1.5 CPU Registers
Program Counter
PCH PCL
PC 12 11 10 9 8 7 6 5 4 3 2 1 0
4 3 2 1 0 PCLATH
108
1.5 CPU Registers
109
1.5 Instruction Memory Space
All 8‐bit MCUs
RETURN
4 3 2 1 0 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
May be different from PCH after RETURN
112
1.6 Instruction Format
13 8 7 6 0 Byte oriented
opcode d f d = 0 ⇒ destination = W
d = 1 ⇒ destination = f
f = 7 bit file address
13 10 9 7 6 0 Bit oriented
opcode b f b = bit position in register
f = 7 bit file address
13 8 7 0 General literal
opcode k
k = 8 bit literal (immediate)
13 11 10 0 CALL / GOTO
opcode k k = 11 bit literal (immediate)
113
1.6 Instruction Set
114
1.6 Instruction Set
Clear/move
clrw Clear W 1 Z
clrf f Clear f 1 Z
movlw k Move literal value to W 1
movwf f Move the value of W to f 1
movf f,F(W) Move the value of f to F 1 Z
or W
swapf f,F(W) Swap nibbles of f, putting 1
result into F or W
115
1.6 Instruction Set
Increment/Decrement/complement
Mnemonic Operands Description Cycles Status bits
affected
116
1.6 Instruction Set
Addition/Subtraction
Mnemonic Operands Description Cycles Status bits
affected
117
1.6 Instruction Set
Multiple bit manipulation
Mnemonic Operands Description Cycles Status bits
affected
Rotate
119
1.6 Instruction Set
Conditional Branch
Mnemonic Operands Description Cycles Status bits
affected
121
1.6 Instruction Set
Miscellaneous
122
1.7 Addressing Modes
Direct Addressing
7 6 5 4 3 2 1 0
STATUS Register
X X X X X X
RP1 RP0 6 5 4 3 2 1 0
Instruction
0 0
Address
Bank
00 80
7F FF 123
1.7 Addressing Modes
Notation
REG<b> Bit b in register REG
REG<a:b> Bits a to b in register REG
Concatenation of A and B
A.B
(A bits followed by B bits)
7 6 5 4 3 2 1 0
STATUS Register
X X X X X X X
IRP1 7 6 5 4 3 2 1 0 FSR
0
1
Address
Bank
00 80
7F FF 125
1.7 Addressing Modes
Indirect addressing
Program writes to Special Function Registers (SFRs)
Address formed from SFRs
Instructions can increment/decrement SFR values
Similar to pointer arithmetic
File Select Register (FSR)
Core SFR accessible at file address 08h in all banks
128
1.8
Sample Program
Computed goto
movlw HIGH Prog20 ; W ← Prog20<15:8>
movwf PCLATH ; PCLATH ← W
movlw LOW Prog20 ; W ← Prog20<7:0>
movwf PCL ; PCL ← Prog20<7:0>
; PCH ← PCLATH<4:0>
Prog20:
;
; Prog20 labels some address in program memory
;
129
1.8 Sample Programs
if‐else branch
btfss f,b ; skip one instruction if
; bit b in register f = 1
goto Action2
Action1:
Yes No
; instructions for Action1 F<b> =1?
goto Action3
Action2:
; instructions for Action2
Action3:
; instructions for Action3
130
1.8
Sample Programs
Static loop
131
1..8
Sample Programs
Data table in instruction memory
; Function call returns data at Table.INDEX
movlw HIGH Table ; W ← Table<15:8>
movwf PCLATH ; PCLATH ← W
movf INDEX, W ; W ← INDEX
call Table ; Call to subroutine table
;
Table:
addwf PCL, f ; PCL ← PCL + W = PCL + INDEX
; computed goto
132