PIC
Instructions
Page 1a
The PIC
microcontrollers we are using in our projects have almost identical
instruction sets (some have more instructions than others). The three
instruction-sets are: PIC12C508A, PIC16F84,
and PIC16F628.
There are only about 35 instructions for our PIC microprocessors and these made
up of the first letter(s) of the words of the instruction. They
are very easy to read and remember.
The first instruction you will need to know is how to put a value into a file.
You cannot do this!
You must load a value (from 00 to FF) (00 to 255 in numerical terms) into the
working register W.
Then move the value from W into the file. This takes two instructions.
They are MOVLW and MOVWF.
The
first instruction is MOVLW.
This means MOVe
Literal
(a number) into W.
We have chosen the hexadecimal number 6F. It is written as 6Fh to show
it is a Hexadecimal number. 6F is moved into W. This is how numbers get
"plucked out of the air" and placed into a program. 6F has the
decimal value of 111. We could select ANY value - it's just an example of
how to put a value into a program.
The second instruction MOVWF means MOVe
W
to file F.
We have chosen file 1A (the files start at 0C and go to 4F).
In the second instruction, the value in W (6F) is moved to file 1A.
File 1A
now contains the value 6F.
The next instruction you may need to know is something like "incrementing a
file." This is: INCF 1A,1 This means: INCrement
File 1A and put the result in the file. (this is the instruction
normally used in a program - there is one other variation INCF 1A,0
but it is
rarely used).
The animation below shows the file incrementing:
The next thing you may want to do is move the value 70h to Port B. Port B is
an input/output port. The file for
Port B is 06.
We must move 70h to W then move the value in W to File 06. It will then appear
on the output. If LEDs are connected to Port B, three will
illuminate: 0111 000. The word "move" should actually
be "copy" as the original contents of a file are not
altered. In other words, they are available to "copy" to
another file, if needed.
The instruction MOVF 1A,0 moves the contents of file 1A to
W.
The next instruction is MOVWF 06. This moves the value in W (70h) to File
06
File 06 is the output port (also the input port) and the lines corresponding
to 70h will be active (HIGH).
The animation shows this:
The instructions we have covered will create a very simple program.
But before they can be "read by a micro," a SetUp routine must be
added to set up PortB as an output. The SetUp routine consists of a
few instructions:
|
BSF 03,5
MOVLW 00
MOVWF 06
BCF 03,5
|
;Go to Bank 1
;Load W with 0000 0000
;Make PortB output
;Go to Bank 0 - the program memory area.
|
|
Adding these
two sets of instructions together will turn on the LEDs shown above (a few
other minor instructions are also needed).
That's all there is to beginning programming.
|
MOVLW 6Fh
MOVWF 1A
INCF 1A,1
MOVF 1A,0
MOVWF 06
|
;Load W with 6F
;Copy W to file 1A
;Increment file 1A
;Copy file 1A to W
;Move the value in W (6F) to Port B.
|
|
This is the beginning
to understanding PIC instructions.
There are about 35 instructions and each one can be read and remembered
quite easily.
The PIC
PROGRAMMING COURSE covers the INSTRUCTION SET and the operation of each
instruction as well as chapters on programming.
To Top
|