PIC16F628
Instruction Set

 

Destination: 0 = W    1 = F

The files in a '628 are:
00 to 20h Special Purpose Registers  xxx

20h to 7F General Purpose Files  (96 files)       (plus over 80 more)
Blue terms are for assistance.


Page 36
INDEX

ADDLW 00 to FF
ADDWF file,0
ADDWF file,1
ANDLW 00 to FF
ANDWF file,0
ANDWF file,1
BCF file,bit
BSF file,bit
BTFSC file,bit
BTFSS file,bit
CALL label
CLRF file
CLRW
CLRWDT
COMF file,0
COMF file,1
DECF file,0
DECF file,1
DECFSZ file,0
DECFSZ file,1
GOTO label
IN
INCF file,0
INCF file,1
INCFSZ file,0
INCFSZ file,1
IORLW 00 to FF
IORWF file,0
IORWF file,1
LOAD
MOVLW 00 to FF
MOVF file,0
MOVF file,1
MOVWF file
NOP
OPTION
OR
OUT
READ
RETFIE
RETLW 00 to FF
RETURN
RLF file,0
RLF file,1
RRF file,0
RRF file,1
SLEEP
SUBLW 00 to FF
SUBWF file,0
SUBWF file,1
SWAPF file,0
SWAPF file,1
TRIS 06h
XORLW 00 to FF
XORWF file,0
XORWF file,1

Add Literal and W
Add W and f (result stored in W) e.g: ADDWF 0C,0
Add W and f (result stored in f) e.g: ADDWF 0C,1
AND Literal with W e.g: ANDLW 40h
AND W with f (result stored in W) e.g: ANDWF 0C,0
AND W with f (result stored in f) e.g: ANDWF 0C,1
Bit Clear f bit0 to bit7 i.e: 0 to 7 e.g: BCF 1E,7
Bit Set f bit0 to bit7 i.e: 0 to 7 e.g: BSF 1F,3
Bit Test, Skip if Clear " " " " e.g: BTFSC 1A,5
Bit Test, Skip if Set " " " " e.g: BTFSS 1B,6
Call Subroutine (range:00 to FF)  e.g: CALL Tone1
Clear f e.g: CLRF 1A
Clear W = CLRW clear the working register
Clear Watchdog Timer = CLRWDT
Complement f (result stored in W) e.g: COMF 0C,0
Complement f (result stored in f) e.g: COMF 0C,1
Decrement f (result stored in W) e.g: DECF 0D,0
Decrement f (result stored in f) e.g: DECF 0D,1
Decrement f, Skip if 0 (result in W) e.g: DECFSZ 1A,0
Decrement f, Skip if 0 (result in f) e.g: DECFSZ 1A,1 - use this instruction
Unconditional Branch (range: 000 to 1FF) e.g: GOTO Tone2
Read the input port: see BTFSS 06,0 etc for individual lines or MOVF 06,0
Increment f (result stored in W) e.g: INCF 1A,0
Increment f (result stored in f) e.g: INCF 1A,1
Increment f, Skip if 0 (result in W) e.g: INCFSZ 1A,0
Increment f, Skip if 0 (result in f) e.g: INCFSZ 1A,1
Inclusive OR Literal with W e.g: IORLW 20h
Inclusive OR W with f (result in W) e.g: IORWF 0D,0
Inclusive OR W with f (result stored in f) e.g: IORWF 0D,1
Load a file. Use: MOVLW XX then MOVWF 1C (or any other file)
Move Literal to W Load W with a number e.g: MOVLW 80h
Move f (result in W) Copy F into W e.g: MOVF 0E,0
Move f (result in f) Move F in and out of F - does not put F into W MOVF 0E,1
Move W to f Copy W to F e.g: MOVWF 0C
No Operation = NOP
Load OPTION Register = OPTION
see IORWF etc. above
turn on an output. Use: BSF 06,0 etc or MOVF 1C,0 then MOVWF 06
to Read an input line. Use: BTFSS 06,0 or BTFSS 06,1 or BTFSS 06,2 etc
Return from Interrupt
Return with Literal in W e.g: RETLW 80h   Returns with a value in W
Return from Subroutine use RETLW 00h
Rotate Left f through Carry (result in W) Doubles the value *e.g: RLF 1C,0
Rotate Left f through Carry (result in f) " " " * e.g: RLF 1C,1
Rotate Right f through Carry (result in W) Halves the value * e.g: RRF 1D,0
Rotate Right f through Carry (result in f) " " " * e.g: RRF 1D,1
Sleep - go into standby mode
Subtract W from Literal NOT subtract literal from W
Subtract W from f (result stored in W) e.g: SUBWF 0E,0
Subtract W from f (result stored in f) e.g: SUBWF 0E,1
Swap Nibbles in f (result stored in W) e.g: SWAPF 0C,0
Swap Nibbles in f (result stored in f) e.g: SWAPF 0C,1
Load TRIS file from W register. ** Alternative: MOVLW XX then MOVWF 06
Exclusive OR Literal with W e.g: XORLW 40h
Exclusive OR W with f (result in W) e.g: XORWF 0C,0
Exclusive OR W with f (result in f) e.g: XORWF 0C,1

* must clear carry before RLF or RRF if file is read for half or double value.
** must use BSF 03,5 before TRIS (or the two equivalent instructions) and BCF 03,5 after the two instructions to get into "Bank 1" where the in/out control file for the port is located.

 

Flags
carry
zero flag
 
3,0      file 3,  bit 0
3,2      file 3,  bit 2

Some assemblers have built-in macros and recognise abbreviations such as the following:
Do not use these instructions unless you know EXACTLY what you are doing.
fr = file register
For instance:
Branch on No Zero to addr     =     btfss 3, 2  goto addr.   (file 3, bit 2 is the zero flag)
Test the zero flag. Skip if it is set. In other words skip if the zero flag is set, but BRANCH if it is not zero!
Mnemonic
addcf fr, d
subcf fr, d
negf fr, d
b   addr
bz   addr
bnz   addr
bc   addr
bnc   addr
skpc
skpnc
skpz
skpnz

clrz  
setz 
clrc 
setc
tstf   fr
decbnz fr,addr
Description
Add carry to fr
Subtract carry from fr
Negate file register fr
Branch to addr

Branch on Zero to addr
Branch on No Zero to addr
Branch on Carry to addr
Branch on No Carry to addr
Skip on Carry
Skip on No Carry
Skip on Zero
Skip on No Zero
Clear Zero flag
Set Zero flag
Clear Carry flag
Set Carry flag
Test file register fr
Decrement fr, if zero branch to addr
Function
btfsc   3, 0   incf  f,d
btfsc   3, 0   decf  fr,d
comf   fr, 1   incf  fr,d

goto    adddr
btfsc   3, 2    goto addr
btfss   3, 2    goto addr

btfsc   3, 0    goto addr
btfss   3, 0    goto addr
btfss   3, 0
btfsc   3, 0
btfss   3, 2
btfsc   3, 2
bcf    3, 2
bsf    3, 2
bcf    3, 0  
bsf    3, 0  
movf  fr, f
decfsz  fr  goto addr

28-04-2004