Файл: Microcontroller Programming. Thi Micro Chip PIC (Julio Sanchez, 2007).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 14.06.2025
Просмотров: 8657
Скачиваний: 0
634 |
Appendix C |
COMF |
Complement f |
|
Syntax: |
[ label ] COMF |
f,d |
Operands: |
f in range 0 to 127 |
|
d is 0 or 1 |
||
Operation: |
(f) -> destination |
|
Status Affected: |
Z |
|
Description: |
The contents of register 'f' are 1’s |
|
complemented. If 'd' is 0 the result is stored in |
||
w. If 'd' is 1 the result is stored back in register |
||
'f'. |
||
Words: |
1 |
|
Cycles: |
1 |
|
Example 1:
comf |
reg1,0 |
|||
Before Instruction: |
reg1 |
= |
0x13 |
|
After Instruction: |
reg1 |
= |
0x13 |
|
w = 0xEC |
||||
Example 2: |
||||
comf |
INDF,1 |
|
Before Instruction: |
FSR = 0xc2 |
|
[FSR]= 0xAA |
||
After Instruction: |
FSR = 0xc2 |
|
[FSR] = 0x55 |
||
Example 3: |
||
comf |
reg1,1 |
|
Before Instruction: |
reg1= 0xff |
|
After Instruction: |
reg1 = 0x00 |
|
Mid-range Instruction Set |
635 |
DECF |
Decrement f |
||
Syntax: |
[ label ] DECF f,d |
||
Operands: |
f in range 0 to 127 |
||
d is either 0 or 1 |
|||
Operation: |
(f) - 1 -> destination |
||
Status Affected: |
Z |
||
Description: |
Decrement register 'f'. If 'd' is 0 the result is |
||
stored in the w register. If 'd' is 1 the |
|||
result is stored back in register 'f'. |
|||
Words: |
1 |
||
Cycles: |
1 |
||
Example 1: |
|||
decf |
count,1 |
||
Before Instruction: |
count = 0x01 |
||
Z = 0 |
|||
After Instruction: |
count = 0x00 |
||
Z = 1 |
|||
Example 2: |
|||
decf |
INDF,1 |
||
Before Instruction: |
FSR = 0xc2 |
||
[FSR] = 0x01 |
|||
Z = 0 |
|||
After Instruction: |
FSR = 0xc2 |
||
[FSR] = 0x00 |
|||
Z = 1 |
|||
Example 3: |
|||
decf |
count,0 |
||
Before Instruction: |
count = 0x10 |
||
w = x |
|||
Z = 0 |
|||
After Instruction: |
count = 0x10 |
||
w = 0x0f |
|||
636 |
Appendix C |
DECFSZ |
Decrement f, Skip if 0 |
|
Syntax: |
[ label ] DECFSZ f,d |
|
Operands: |
f in the range 0 to 127 |
|
d is either 0 or 1 |
||
Operation: |
(f) - 1 -> destination; skip if result = 0 |
|
Status Affected: |
None |
|
Description: |
The contents of register 'f' are |
|
decremented. If 'd' is 0 the result is placed |
||
in the w register. If 'd' is 1 the result is |
||
placed back in register 'f'. |
||
If the result is 0, then the next instruction |
||
(fetched during the current instruction |
||
execution) is discarded and a NOP is |
||
executed instead, making this a 2 cycle |
||
instruction. |
||
Words: |
1 |
|
Cycles: |
1(2) |
|
Example |
||
here: |
||
decfsz |
count,1 |
|
goto |
here |
|
Case 1: |
||
Before Instruction: |
PC = $ |
|
count = 0x01 |
||
After Instruction: |
count = 0x00 |
|
PC = $ + 2 (goto skipped) |
||
Case 2: |
||
Before Instruction: |
PC = $ |
|
count = 0x04 |
||
After Instruction: |
count = 0x03 |
|
PC = $ + 1 (goto executed) |
||
Mid-range Instruction Set |
637 |
GOTO |
Unconditional Branch |
||
Syntax: |
[ label ] GOTO k |
||
Operands: |
0 £ k £ 2047 |
||
Operation: |
k -> PC<10:0> |
||
PCLATH<4:3> ->PC<12:11> |
|||
Status Affected: |
None |
||
Description: |
GOTO is an unconditional branch. The eleven |
||
bit immediate value is loaded into PC bits |
|||
<10:0>. The upper bits of PC are loaded from |
|||
PCLATH<4:3>. |
|||
GOTO is a two cycle instruction. |
|||
Words: |
1 |
||
Cycles: |
2 |
||
Example |
|||
goto |
There |
||
After Instruction: |
PC = address of There |
||
638 Appendix C
INCF |
Increment f |
||
Syntax: |
[ label ] INCF f,d |
||
Operands: |
f in range 0 to 127 |
||
d is either 0 or 1 |
|||
Operation: |
(f) + 1 -> destination |
||
Status Affected: |
Z |
||
Description: |
The contents of register 'f' are incremented. If |
||
'd' is 0 the result is placed in the w register. If 'd' |
|||
is 1 the result is placed back in register 'f'. |
|||
Words: |
1 |
||
Cycles: |
1 |
||
Example 1 |
|||
incf |
count,1 |
||
Before Instruction: |
count = 0xff |
||
Z = 0 |
|||
After Instruction: |
count = 0x00 |
||
Z = 1 |
|||
Example 2 |
|||
incf |
INDF,1 |
||
Before Instruction: |
FSR = 0xC2 |
||
[FSR] = 0xff |
|||
Z = 0 |
|||
After Instruction: |
FSR = 0xc2 |
||
[FSR] = 0x00 |
|||
Z = 1 |
|||
Example 3 |
|||
incf |
count,0 |
||
Before Instruction: |
count = 0x10 |
||
w = x |
|||
Z = 0 |
|||
After Instruction: |
count = 0x10 |
||
w = 0x11 |
|||
Z = 0 |
|||