Professional Documents
Culture Documents
Introduction
Peripheral Interface Controllers (PIC)
is one of the advanced
microcontrollers developed by
microchip technologies.
They are advanced than 8051.
PIC microcontroller family uses
modified Harvard architecture.
program memory bus and a data
memory bus to access two separate
memories.
Block Diagram
CPU
The CPU in PIC normally supports Reduced
Instruction Set Computer (RISC) architecture.
CPU consists of several sub-units such as
instruction decoder, ALU, accumulator, control
unit, etc.
RISC structure gives the following advantages.
The RISC structure only has 35 simple instructions
as compared to others
The execution time is same for most of the
instructions (except very few numbers).
The execution time required is very less (5 million
instructions/second (approximately)
Memory
Memory partitioned into data memory and
program memory
Each of them have separate bus.
Based on type, PIC chip also has certain amount
of RAM, ROM, EEPROM, other flash memory.
RAM memory is a complex memory module in a
PIC chip.
RAM memory associated with special function
registers, general purpose registers and
memory BANK modules
Registers
Information is stored in CPU at memory
locations called a register.
Register file is used to denote locations that
an instruction can access via address
Registers can be thought of as the CPUs
tiny scratchpad (8 bit locations)
General Purpose Register (GPR)
Used to store data and addresses
PIC16F877A
Pin Diagram
Pin Configuration
Block
Diagram
Memory Organization
Program memory
Data Memory
Each memory has separate buses so
that concurrent access can occur.
Program Memory
Organization
PIC16F87XA devices have a 13-bit
program counter
The PIC16F877A has 8K words x 14
bits of Flash program memory
The Reset vector is at 0000h and the
interrupt vector is at 0004h.
PIC16F877A
PROGRAM
MEMORY MAP
AND STACK
Register
File Map
SPECIAL FUNCTION
REGISTERS
These registers are used to configure
the operation of the CPU and its
peripherals
These registers are implemented as
static RAM
RAM addressing
Two types of addressing modes
direct addressing
address forms part of the instruction
indirect addressing
Address is taken from the File Select
Register (FSR)
Status Register
It contains arithmetic status of ALU,
reset status and bank select bits for
data memory
Status register can be the destination
for any instruction
Write
OPTION_REG Register
It is a readable and writable register
It contains various control bits to
configure
TMR0 prescaler/WDT scaler
the external INT interrupt,
TMR0 operation
weak pull-ups on PORTB.
Loading of PC
COMPUTED GOTO
It involves adding an offset to the
program counter (ADDWF PCL).
Care to be exercised to check if
result crosses a PCL memory
boundary
CALL AND GOTO INSTRUCTIONS
They provide 11 bits of addressing
Two Most significant bits taken from
PCLATH register 4th & 3rd bit to form
13 bit PC value.
CALL OF A SUBROUTINE
IN PAGE 1 FROM PAGE 0
SUB1_P1
ORG 0x500
: ;called subroutine
BCF PCLATH,4
;page 1 (800h-FFFh)
BSF PCLATH,3 ;Select page 1
:
;(800h-FFFh)
RETURN ;return to
CALL SUB1_P1 ;Call subroutine
;Call subroutine
in
;in page 0
:
;page 1
;(000h-7FFh)
(800h-FFFh)
:
ORG 0x900
;page 1 (800hFFFh)
STACK TRANSFER
PIC16F877A has an 8-level deep x 13-bit wide
hardware stack
13-bit value is transferred between Stack and
Program Counter
stack space is not part of either program or data
space
Stack pointer is not readable or writable
PC is PUSHed onto the stack when a CALL
instruction is executed, or an interrupt causes a
branch.
Stack is POPed in the event of a RETURN, RETLW
or a RETFIE instruction
Stack operates as a circular buffer
PCLATH register contents are unchanged after a
RETURN or RETFIE instruction is executed
Addressing Modes
Two types of addressing modes for
accessing data memory
Direct addressing mode
Indirect addressing mode
Direct addressing
Direct Addressing is done through a
9-bit address for the RAM.
Address obtained concatenating 7
bits of direct address of an
instruction with two bits (RP1, RP0)
from STATUS register
bsf STATUS, RP0 ;Bank 1
movlw 0xFF ;w=0xFF
movwf TRISA ;address of TRISA register is
taken from
;instruction movwf
Indirect Addressing
Indirect addressing does not take an address
from an instruction
Address derived from IRP bit of STATUS and
FSR registers
Addressed location is accessed via INDF
register
INDF register holds the address indicated by a
FSR. Eg.
movlw 0x0C
movwf FSR
movwf INDF
Indirect Addressing
Instruction Set
PCL as Source or
Destination
Read PC: PCL -> dest; PCLATH does
not change;
Write PCL: PCLATH -> PCH;
8-bit destination value -> PCL
Read-Modify-Write: PCL -> ALU
operand
PCLATH -> PCH;
8-bit result -> PCL
Bit Manipulation
All bit manipulation instructions
follow read-modify-write (R-M-W)
operation on the specified register
It will first read the entire register,
operate on the selected bit and then
write the result back
Q Cycle Activity
Each instruction cycle (Tcy) is comprised of four Q
cycles (Q1-Q4)
The Q cycle is the same as the device oscillator
cycle (TOSC).
The Q cycles provide the timing/designation for the
Decode, Read, Process Data, Write etc., of each
instruction cycle.
The four Q cycles can be generalized as
Q1:
Q2:
Q3:
Q4:
Q Cycle Activity
+++++++++++++