Documente Academic
Documente Profesional
Documente Cultură
Index
Development systems
Contact us
on-line FREE !
Previous page
Table of contents
Next Page
Appendix A
Instruction Set
Introduction
Instruction set in PIC16Cxx microcontroller family
Data Transfer
Arithmetic and logic
Bit operations
Directing the program flow
Instruction execution period
Word list
Instruction list
Introduction
We have already mentioned that microcontroller is not like any other integrated circuit. When they come out of
production most integrated circuits are ready to be built into devices which is not the case with
microcontrollers. In order to "make" microcontroller perform a task, we have to tell it exactly what to do, or in
other words we must write the program microcontroller will execute. We will describe in this chapter
instructions which make up the assembler, or lower-level program language for PIC microcontrollers.
Data transfer
Transfer of data in a microcontroller is done between work (W) register and an 'f' register that represents any
location in internal RAM (regardless whether those are special or general purpose registers).
First three instructions (look at the following table) provide for a constant being written in W register (MOVLW
is short for MOVe Literal to W), and for data to be copied from W register onto RAM and data from RAM to be
copied onto W register (or on the same RAM location, at which point only the status of Z flag changes).
Instruction CLRF writes constant 0 in 'f ' register, and CLRW writes constant 0 in register W. SWAPF instruction
Bit operations
Instructions BCF and BSF do setting or cleaning of one bit anywhere in the memory. Even though this seems
like a simple operation, it is executed so that CPU first reads the whole byte, changes one bit in it and then
writes in the entire byte at the same place.
We write the position of a member of our table in W register, and using CALL instruction we call a subprogram
which creates the table. First subprogram line ADDWF PCL, f adds the position of a W register member to the
starting address of our table, found in PCL register, and so we get the real data address in program memory.
When returning from a subprogram we will have in W register the contents of an addressed table member. In a
previous example, constant 'k2' will be in W register following a return from a subprogram.
RETFIE (RETurn From Interrupt - Interrupt Enable) is a return from interrupt routine and differs from a RETURN
only in that it automatically sets GIE (Global Interrupt Enable) bit. Upon an interrupt, this bit is automatically
cleared. As interrupt begins, only the value of program counter is put at the top of a stack. No automatic
Word list
f
W
b
d
label
TOS
[]
<>
*1
*2
be
*3
Instruction List
Appendix contains all instructions presented separately with examples for their use. Syntax, description and its
effects on status bits are given for each instruction.
A.1 MOVLW
A.2 MOVWF
A.3 MOVF
A.4 CLRW
A.5 CLRF
A.6 SWAPF
A.7 ADDLW
A.8 ADDWF
A.9 SUBLW
A.10 SUBWF
A.11 ANDLW
A.12 ANDWF
A.13 IORLW
A.14 IORWF
A.15 XORLW
A.16 XORWF
A.17 INCF
A.18 DECF
A.19 RLF
A.20 RRF
A.21 COMF
A.22 BCF
A.23 BSF
A.24 BTFSC
A.25 BTFSS
A.26 INCFSZ
A.27 DECFSZ
A.28 GOTO
A.29 CALL
A.30 RETURN
A.31 RETLW
A.32 RETFIE
A.33 NOP
A.34 CLRWDT
A.35 SLEEP
A.1 MOVLW
A.2 MOVWF
A.3 MOVF
Copy W to f
Copy f to d
A.4 CLRW
Write 0 in W
A.5 Write 0 in f
A.6 SWAPF
A.7 ADDLW
Add W to a constant
A.8 ADDWF
Add W to f
A.9 SUBLW
A.10 SUBWF
Subtract W from f
A.11 ANDLW
A.12 ANDWF
A.13 IORLW
A.14 IORWF
Logic OR W with f
A.15 XORLW
A.16 XORWF
A.17 INCF
Increment f
A.18 DECF
Decrement f
A.19 RLF
A.20 RRF
A.21 COMF
Complement f
A.22 BCF
Reset bit b in f
A.23 BSF
Set bit b in f
A.24 BTFSC
A.25 BTFSS
A.26 INCFSZ
A.27 DECFSZ
A.28 GOTO
Decrement f, skip if = 0
Jump to address
A.29 CALL
A.30 RETURN
Call a program
A.32 RETFIE
A.33 NOP
No operation
A.34 CLRWDT
A.35 SLEEP
Stand by mode
Previous page
Table of contents
Copyright 2003. mikroElektronika. All Rights Reserved. For any comments contact webmaster.
Next page