Chapter 2.2 4pic16f877 Instruction Set Programming
Chapter 2.2 4pic16f877 Instruction Set Programming
PIC16F877A INSTRUCTION
SET AND ASSEMBLY
PROGRAMMING
OBJECTIVES
For better understanding of the
PIC16f877a architecture
To study the instruction set of this
PIC microcontrollers
HARVARD VSS VON NEUMANN
ARCHITECTURE
HARVARD ARCHITECTURE IN
THE PIC MICROCONTROLLERS
MICROCONTROLLERS VSS
MICROCONTROLLERS
PIC16F877A BLOCK DIAGRAM
PIC16F877 CORE FEATURES
High-performance RISC CPU
Only 35 single word instructions to learn
All single cycle instructions except for
program branches which are two cycle
Operating speed: DC - 20 MHz clock input DC
- 200 ns instruction cycle
Up to 8K x 14 bit of FLASH Program Memory
Up to 368 x 8 bit of Data Memory (RAM)
Up to 256 x 8 bytes of EEPROM data memory
PIC16F877 CORE FEATURE
(CONTI…)
Interrupt capability (up to 14 sources)
Eight level deep hardware stack
Direct, indirect and relative addressing modes
Power-on Reset (POR)
Power-up Timer (PWRT) and Oscillator Start-up
Timer (OST)
Watchdog Timer (WDT) with its own on-chip RC
oscillator for reliable operation
Power saving SLEEP mode
Selectable oscillator options
Low-power, high-speed CMOS FLASH/EEPROM
technology
WHAT IS INSTRUCTION SET
The language that human and
microcontrollers speak to
communicate to each other
It is the language through which
human tell microcontroller what to
do
There are only 35 instruction set to
learn in PIC microcontroller family
INSTRUCTION DESCRIPTION
CONVENTION
f -------involvement of file register in the
instruction
W ------ >> working register
b ------ bit operation indecator
k(l) ------- >> literal (constant operand)
d ------ result destination indicator
------ direction of assignment indicator
<> ---- position of bit indecator
IMPORTANT SPECIAL FUNCTION
REGISTER
W register
Almost all instruction go through the working
registers
Status register
Port registers
Port content register (e.g.. PORTA register)
Port direction indication register (TRISA register)
TYPES OF INSTRUCTION SET
We can classify instruction set
The type of operand on which they work
on
i.e. bit or byte, literal number or control oriented
type
Based on type of operation
Arithmetic and logic operation
Data movement operation
Program control operation
Processor hardware control operation
FORMAT FOR THE INSTRUCTION
SET
DATA TRANSFER INSTRUCTIONS
ARITHMETIC/LOGIC OPERATION
Addition
Subtraction
Incrementing
Decrementing
Clearing
Bit setting and resetting
Bitwise AND
Bitwise OR
Bitwise XOR
Bitwise complement
Rotating
DATA MOVEMENT OPERATION
MOVLW k
Move literal to W
MOVFf, d
Move f
MOVWF f
move w to f
PROGRAM EXECUTION
CONTROL INSTRUCTION
goto
return
call
RETFIE
Return from interrupt
RETLW k
Return with literal in W
BTFSC f, b
Bit Test f, Skip if Clear
BTFSS f, b
Bit Test f, Skip if Set
PROCESSOR HARDWARE
CONTROL
SLEEP
Go into standby mode
CLRWDT
Clear Watchdog Timer
BIT ORIENTED INSTRUCTION SET
BCF
Example
BIT ORIENTED INSTRUCTION SET
(CONTI…)
BTFSC
Example
ARITHMETIC OPERATION
ADDLW
ARITHMETIC OPERATION
(CONT…)
ADDWF
ARITHMETIC OPERATION
(CONT…)
SUBLW
Example
LOGICAL OPERATION
ANDLW
LOGICAL OPERATION (CONTI…)
BCF
Example
LOGICAL OPERATION (CONTI…)
IORWF
Example
PROGRAM CONTROL
INSTRUCTION
BTFSC
Example
PROGRAM CONTROL INSTRUCTION
GOTO
Example
PROCESSOR CONTROL INSTRUCTION
CLRWDT
PROCESSOR CONTROL INSTRUCTION
(CONTI…)
SLEEP
SUMMARY
Instruction set is the language that the PIC
understand
There are only 35 instruction set in the PIC
microcontrollers
The instruction set can be categorized based
either on the operation type of the opcode or
the size or the types of the operand