PIC16F877 - Instructions

Page 1


PIC - 16F877 Instructions

R. Theagarajan. ME., MSc., PhD Rtd. Professor in Engineering email: rtheagarajan@yahoo.com rtrajan59@gmail.com


Instruction Set 5 groups     

Data Transfer group Arithmetic & Logic operation group Bit operation group Program flow control Other instructions


Word list f - any memory location in a microcontroller w - work register b - bit position in 'f' register d - destination bit label group of eight characters which marks the beginning of a part of the program TOS - top of stack [ ] - option < > - bit position inside register


Instruction Set 5 groups     

Data Transfer group Arithmetic and Logic operation group Bit operation group Program flow control Other instructions


Data Transfer Group MOVLW Write constant into W register Syntax : Label MOVLW k Description : 8 bit constant is written in W reg. Operation : k to (W) Operand : 0 < k < 255 No. of words : 1 No. cycles : 1 Flags : Nil


Data Transfer Group MOVWF Copy W to specified register Syntax : Label MOVWF f Description : content of W is copied into f reg. Operation : W to (f) Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Nil


Data Transfer Group MOVF Copy f to specified register Syntax : Label MOVF f, d Description : content of f is copied into destination If d = 0, the destination is W register If d = 1, the destination is f register

Operation : f to (d) Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Data Transfer Group CLRW Write zero in W register Syntax : Label CLRW Description : Zero is copied into W register Z flag in status register is set to one Operation : 0 to (W) Operand : -No. of words : 1 No. cycles : 1 Flags : Z


Data Transfer Group CLRF f Write zero into specified register Syntax : Label CLRF f Description : Zero is copied into f register Z flag in status register is set to one Operation : 0 to (f) Operand : -No. of words : 1 No. cycles : 1 Flags : Z


Data Transfer Group SWAPF Swap the digits / nibbles Syntax : Label SWAPF f, d Description : Upper, Lower nibbles are exchanged If d = 0, the destination is W register If d = 1, the destination is f register

Operation : f(0:3) to d(4:7) and f(4:7) to d(0:3) Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : --


Instruction Set 5 groups     

Data Transfer group Arithmetic & Logic operation group Bit operation group Program flow control Other instructions


Arithmetic & Logic Group ADDLW Add the constant with W register Syntax : Label ADDLW k Description : given constant is added with W reg. Operation : (w) + k to w Operand : 0 < k < 255 No. of words : 1 No. cycles : 1 Flags : C, DC, Z


Arithmetic & Logic Group ADDWF Syntax Description Operation

Add the register content with W register : Label ADDWF f, d : Add W reg. content with f register : (w) + (f) to w if d = 0 (w) + (f) to f if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : C, DC, Z


Arithmetic & Logic Group SUBLW Subtract W content from given constant Syntax : Label SUBLW k Description : W reg. content is subtracted from k Operation : k - (w) to w Operand : 0 < k < 255 No. of words : 1 No. cycles : 1 Flags : C, DC, Z


Arithmetic & Logic Group SUBWF Syntax Description Operation

Subtract W content from f register : Label SUBWF f : W reg. content is subtracted from f : f - (w) to w if d = 0 f - (w) to f if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : C, DC, Z


Arithmetic & Logic Group ANDLW Logic AND the constant with W Syntax : Label ANDLW k Description : given constant is .and. with W reg. Operation : (w) .and. k to w Operand : 0 < k < 255 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group ANDWF Syntax Description Operation

Logic AND the W reg. with f : Label ANDWF f, d : W reg. is .and. with f reg. : (w) .and. f to w, if d = 0 (w) .and. f to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group IORLW Logic OR the constant with W Syntax : Label IORLW k Description : given constant is .or. with W reg. Operation : (w) .or. k to w Operand : 0 < k < 255 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group IORWF Syntax Description Operation

Logic OR the W reg. with f : Label IORWF f, d : W reg. is .or. with f reg. : (w) .or. f to w, if d = 0 (w) .or. f to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group XORLW Logic XOR the constant with W Syntax : Label XORLW k Description : given constant is .xor. with W reg. Operation : (w) .xor. k to w Operand : 0 < k < 255 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group XORWF Syntax Description Operation

Logic XOR the W reg. with f : Label XORWF f, d : W reg. is .xor. with f reg. : (w) .xor. f to w, if d = 0 (w) .xor. f to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group INCF Increment f register content Syntax : Label INCF f, d Description : Increment the content of f register Operation : (f) + 1 to w, if d = 0 (f) + 1 to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group DECF Syntax Description Operation

Decrement f register content : Label DECF f, d : Decrement the content of f register : (f) - 1 to w, if d = 0 (f) - 1 to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Arithmetic & Logic Group RLF Rotate register content left through Carry Syntax : Label RLF f, d Description : Rotate f content left through Carry Operation : Result to w, if d = 0 Result to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : C


Arithmetic & Logic Group RRF Rotate register content right through Carry Syntax : Label RRF f, d Description : Rotate f content right through Carry Operation : Result to w, if d = 0 Result to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : C


Arithmetic & Logic Group COMF Syntax Description Operation

Complement f register content : Label COMF f, d : Complement the register content : Result to w, if d = 0 Result to f, if d = 1 Operand : 0 < f < 127 No. of words : 1 No. cycles : 1 Flags : Z


Instruction Set 5 groups     

Data Transfer group Arithmetic & Logic operation group Bit operation group Program flow control Other instructions


Bit Operation Group BCF Reset the specified bit in f register Syntax : Label BCF f, b Description : Reset the specified bit of register f Operation : Result to f Operand : 0 < f < 127 0<b<7 No. of words : 1 No. cycles : 1 Flags : --


Bit Operation Group BSF Set the specified bit in f register Syntax : Label BSF f, b Description : Set the specified bit of register f Operation : Result to f Operand : 0 < f < 127 0<b<7 No. of words : 1 No. cycles : 1 Flags : --


Instruction Set 5 groups     

Data Transfer group Arithmetic & Logic operation group Bit operation group Program flow control Other instructions


Program Flow Control Group BTFSC Test the bit in f, skip if it is zero Syntax : Label BTFSC f, b Description : Test the specified bit of register f, skip the next instruction if it is zero Operation : skip the next instruction if f (b) = 0 Operand : 0 < f < 127 0<b<7 No. of words : 1 No. cycles : 1 or 2 depends on bit value Flags : --


Program Flow Control Group BTFSS Test the bit in f, skip if it is one Syntax : Label BTFSS f, b Description : Test the specified bit of register f, skip the next instruction if it is one Operation : skip the next instruction if f (b) = 1 Operand : 0 < f < 127 0<b<7 No. of words : 1 No. cycles : 1 or 2 depends on bit value Flags : --


Program Flow Control Group INCFSZ Increment f content, skip if it is zero Syntax : Label INCFSZ f, d Description : Increment the f content, skip the next instruction if f is zero Operation : skip the next instruction if f = zero Operand : (f) + 1 = w if d = 0 (f) + 1 = f if d = 1 No. of words : 1 No. cycles : 1 or 2 depends on bit value Flags : --


Program Flow Control Group DECFSZ Decrement f content, skip if it is zero Syntax : Label DECFSZ f, d Description : Decrement the f content, skip the next instruction if f is zero Operation : skip the next instruction if f = zero Operand : (f) - 1 = w if d = 0 (f) - 1 = f if d = 1 No. of words : 1 No. cycles : 1 or 2 depends on bit value Flags : --


Program Flow Control Group GOTO Jump to specified address Syntax : Label GOTO Label Description : Unconditional jump to specified label Operation : k to PC(10:0), PCLATH(4:3) to PC(12:11) Operand : 0 < k < 2048 No. of words : 1 No. cycles : 2 Flags : --


Program Flow Control Group CALL Call the required sub-program Syntax : Label CALL Label Description : Unconditional call the label Operation : (PC) + 1 to Top of stack k to PC(10:0), PCLATH(4:3) to PC(12:11)

Operand : 0 < k < 2048 No. of words : 1 No. cycles : 2 Flags : --


Program Flow Control Group RETURN Return to main program Syntax : Label RETURN Description : Unconditional return from subroutine Operation : Top of stack to (PC) Operand : -No. of words : 1 No. cycles : 2 Flags : --


Program Flow Control Group RETLW Return to main program with k in w reg. Syntax : Label RETLW k Description : Unconditional return from subroutine Operation : Top of stack to (PC) and k loaded in w register

Operand : 0 < k < 255 No. of words : 1 No. cycles : 2 Flags : --


Program Flow Control Group RETFIE Return from interrupt routine Syntax : Label RETFIE Description : Unconditional return from subroutine Operation : Top of stack to (PC) and Global Interrupt bit is Enabled

Operand : No. of words : No. cycles : Flags :

-1 2 --


Instruction Set 5 groups     

Data Transfer group Arithmetic & Logic operation group Bit operation group Program flow control Other instructions


Other Instructions NOP No Operation Syntax : Label NOP Description : No operation Operation : -Operand : -No. of words : 1 No. cycles : 1 Flags : --


Other Instructions CLRWDT Syntax Description

Operation

Initialize watchdog time : Label CLRWDT : Watchdog timer and pre-scalar is reset and TO and PD are set : 0 to WDT, 0 to pre-scalar and Status bits TO and PD are set

Operand No. of words No. cycles Flags

: : : :

TO and PD 1 1 --


Other Instructions SLEEP

Stand by mode Syntax : Label SLEEP Description : Goes into low consumption, OSC is stopped, Watchdog timer and pre-scalar is reset and TO and PD bits are set Operation : 0 to WDT, 0 to pre-scalar and Status bits, TO is set and PD is reset

Operand No. of words No. cycles Flags

: : : :

TO and PD 1 1 --



Avoid Plastics Plant a Tree Let us take care of our earth for future generation


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.