The instruction set of PIC16F84A has 35 instructions [The controller “understands” 35 words].These instructions are otherwise called Mnemonics. While introducing about the PIC16F84A till the hello world program, Â 7 instructions are introduced to you which were,
BSF – bit set f
BCF- bit clear f
MOVLW – move literal value to W-register
MOVWF – move contents of W-register to file [specified]
GOTO – go to the address [the label indicated]
BTFSS – Â Bit test f, skip if set
DECFSZ – Â Decrement f, skip if zero.
Now, only 28 instruction to go!
Before dealing with the instructions, let us classify these instructions in to major categories as:
- Byte-oriented file register operations
- Bit-oriented file register operations
- Control operations.
Byte-oriented file register operations:
|Mnemonics & Operands||Description|
|ADDWF f,d||Add contents of W-register and f and store the contents in the specified address(d)|
|ANDWF f,d||AND the contents of W-register and f and store the contents in the specified address(d)|
|CLRF f||Clear the contents of f|
|CLRW||Clear the contents of W-register|
|COMF f,d||Compliments the contents of f and stores the result in d(destination)|
|DECF f,d||Decrement f and store the result in the destination(d)|
|DECFSZ f,d||Decrement f, skip if zero|
|INCF f,d||Increment f and store the result in destination (d)|
|INCFSZ f,d||Increment f, skip if zero|
|IORWF f,d||Incluse OR contents of W-register with contents of f and store the result in destination(d)|
|MOVF f,d||move the contents of f to destination(d)|
|MOVWF f||Move the contents of W-register to fM|
|NOP||No operation (remains quiet for one cycle)|
|RLF f,d||Rotate left f through carry|
|RRF f,d||Rotate right f through carry|
|SUBWF f,d||Subtract contents of W-register from f|
|SWAPF f,d||Swaps nibbles in f|
|XORWF f,d||Exclusive OR contents of W-register with f|
Some examples of how to implement the instructions and the result of how they work.This will give you insight in working with these instructions.
In the above table, ‘f’ signifies the file (or register) which will be specified and ‘d’ signifies the destination address.
ADDWF f,d – This instruction adds the contents of W register and f (which will be specified) and stores the result in the destination specified by ‘d’ (operation: (W)+(F) —>(destination)). ‘d’ takes the value 0 or 1. If ‘d’ is 0, the result is stored in the W-register itself and if ‘d’ is 1, the result is stored in f.
Let initial contents of the W register = 00100110
Let initial contents of register 0CH = 10100010
If we apply the instruction ADDWF 0CH, 0
The above instruction adds contents of W and f and stores it in W.
Now, the contents of W register = 11001000 (the result of W+F)
the contents of register 0CH= 10100010 (unchanged)
On the contrary, if we apply the instruction ADDWF 0CH,1
The instruction adds the contents of W and F and stores it in F.
Now, the contents of W register = 00100110(unchanged)
the new contents of register 0CH = 11001000(the result of W+F)
All the byteÂ orientedÂ instructions work similar to the one explained above.
The remaining instructions will be explained in the following posts.
Note: Always remember, before each instruction, the space is reserved for a label. So, when not using a label, remember to leave a blank space before the instruction and failing to do so, will generate error since the assembler interprets the keywords as labels.