PIC instruction
instruction | Instruction description | influence flag | Reference page number | |||
BYTE-ORIENTED FILE REGISTER OPERATIONS | ||||||
ADDWF | f, d, a | Add W and f and put the result in W or f. | C, DC, Z, OV, N | 7 | ||
ADDWFC | f, d, a | Add W and C and put the result in W or f. | C, DC, Z, OV, N | 10 | ||
ANDWF | f, d, a | Perform an AND operation on W and f, and put the result in W or f. | Z,N | 14 | ||
CLRF | f, a | Clear all values in f to 0. | Z | 31 | ||
COMF | f, d, a | Complement the value in f and place the result in W or f. | Z,N | 33 | ||
CPFSEQ | f, a | If the values of f and W are equal, the next instruction is skipped. | none | 35 | ||
CPFSGT | f, a | If f is greater than W, skip the next instruction. | none | 36 | ||
CPFSLT | f, a | If f is less than W, skip the next instruction. | none | 37 | ||
DECF | f, d, a | Decrement the value in f by 1 and place the result in W or f. | C, DC, Z, OV, N | 40 | ||
DECFSZ | f, d, a | Decrement the value in f by 1. If it is 0, skip the next instruction and put the result in W or f. | none | 43 | ||
DCFSNZ | f, d, a | Decrement the value in f by 1. If it is not 0, skip the next instruction and put the result in W or f. | none | 45 | ||
INCF | f, d, a | Add 1 to the value in f and place the result in W or f. | C, DC, Z, OV, N | 48 | ||
INCFSZ | f, d, a | Add 1 to the value in f. If it is 0, skip the next instruction and put the result in W or f. | none | 51 | ||
INFSNZ | f, d, a | Add 1 to the value in f. If it is not 0, skip the next instruction and put the result in W or f. | none | 53 | ||
IORWF | f, d, a | Perform an OR operation on W and f, and put the result into W or f. | Z,N | 57 | ||
MOVF | f, d, a | Move the value in f to W or f. | Z,N | 61 | ||
MOVFF | Move the data inside . | none | 63 | |||
MOVWF | f, a | Move the value in W to f. | none | 66 | ||
MULWF | f, a | Multiply W and f. | none | 68 | ||
NEGF | f, a | Take the 2's complement of the value in f. | C, DC, Z, OV, N | 70 | ||
RLCF | f, d, a | Move the value in f to the left together with C, and put the result in W or f. | C, Z, N | 80 | ||
RLNCF | f, d, a | Move the value in f to the left and put the result in W or f. | Z,N | 82 | ||
RRCF | f, d, a | Move the value in f right together with C, and put the result into W or f. | C, Z, N | 84 | ||
RRNCF | f, d, a | Move the value in f right and put the result in W or f. | Z,N | 86 | ||
SETF | f, a | Set the value in f to 0xFF. | none | 88 | ||
SUBFWB | f, d, a | Subtract C and f from the value in W and place the result in W or f. | C, DC, Z, OV, N | 90 | ||
SUBWF | f, d, a | Subtract f from the value in W and place the result in W or f. | C, DC, Z, OV, N | 94 | ||
SUBWFB | f, d, a | Subtract W and C from the value in f and place the result in W or f. | C, DC, Z, OV, N | 96 | ||
SWAPF | f, d, a | Swap the high 4 bits and low 4 bits of the value in f, and place the result in W or f. | none | 98 | ||
TSTFSZ | f, a | Test whether the value in f is equal to 0. If it is 0, skip the next instruction. | none | 105 | ||
XORWF | f, d, a | Perform XOR operation on W and f, and put the result into W or f. | Z,N | 108 | ||
Bit operation instructions (BIT-ORIENTED FILE REGISTER OPERATIONS) | ||||||
BCF | f, b, a | Set a certain bit in f to 0. | none | 17 | ||
BSF | f, b, a | Set a certain bit in f to 1. | none | twenty four | ||
BTFSC | f, b, a | Test whether the value of a certain bit in f is equal to 0. If it is 0, skip the next instruction. | none | 25 | ||
BTFSS | f, b, a | Test whether the value of a certain bit in f is equal to 1. If it is 1, skip the next instruction. | none | 26 | ||
BTG | f, d, a | Perform NOT operation on a certain bit in f. | none | 27 | ||
Note: | Ff represents the temporary register. | Fd indicates where the data is stored, d = 0 indicates it is stored in the W accumulator; d = 1 indicates it is stored in the f register. | ||||
Fb represents the b-th bit of the temporary register. | ||||||
Fk represents an 8-bit constant. | Fa indicates which memory location the data is stored in. a = 0 indicates that it is placed in the current memory location; a = 1 indicates that it is placed in the memory location specified in the BSR register. | |||||
Fn represents the address of the program memory. | ||||||
PIC18 Series Family Instructions Quick Index (continued)
instruction | Instruction description | influence flag | Reference page number | |||
Program flow control instructions (CONTROL OPERATIONS) | ||||||
B.C. | n | If C = 1, jump to address n. | none | 16 | ||
BN | n | If N = 1, jump to address n. | none | 18 | ||
BNC | n | If C = 0, jump to address n. | none | 19 | ||
BNN | n | If N = 0, jump to address n. | none | 20 | ||
BNOV | n | If OV = 0, jump to address n. | none | twenty one | ||
BNZ | n | If Z = 0, jump to address n. | none | twenty two | ||
BOV | n | If OV = 1, jump to address n. | none | 28 | ||
BRA | n | Unconditionally jump to address n ( ). | none | twenty three | ||
BZ | n | If Z = 1, jump to address n. | none | 29 | ||
CALL | n, s | Store the PC value of the next instruction to the top level of the stack and jump to address n ( ). | none | 30 | ||
CLRWDT | Clear the watchdog timer to 0. | none | 32 | |||
DAW | Make BCD adjustments to the values in W. | none | 38 | |||
GOTO | n | Unconditionally jump to address n ( ). | none | 47 | ||
NOP | Empty command. | none | 72 | |||
POP | Take out the value at the top of the stack. | none | 73 | |||
PUSH | Store the PC value of the next instruction to the top level of the stack. | none | 74 | |||
RCALL | n | Store the PC value of the next instruction to the top level of the stack and jump to address n ( ). | none | 75 | ||
RESET | Use software to reset the system. | none | 76 | |||
RETFIE | s | The interrupt subroutine returns to the main program, and the value at the top of the stack is taken out and placed in the PC, and the main program starts execution from the current PC value. | none | 77 | ||
RETURN | s | Return to the main program from the sub-program, take out the value at the top of the stack and put it into the PC, and the main program starts executing from the current PC value. | none | 79 | ||
SLEEP | Go to sleep. | none | 89 | |||
Note: | Ff represents the temporary register. | Fd indicates where the data is stored, d = 0 indicates it is stored in the W accumulator; d = 1 indicates it is stored in the f register. | ||||
Fb represents the b-th bit of the temporary register. | ||||||
Fk represents an 8-bit constant. Fn represents the address of the program memory. | Fa indicates which memory location the data is stored in. a = 0 indicates that it is placed in the current memory location; a = 1 indicates that it is placed in the memory location specified in the BSR register. | |||||
PIC18 Series Family Instructions Quick Index (continued)
instruction | Instruction description | influence flag | Reference page number | |||
Immediate constant addressing (LITERAL OPERATIONS) | ||||||
ADDLW | k | Add the constant k and W. | C, DC, Z, OV, N | 4 | ||
ANDLW | k | Do an AND operation with the constant k and W. | Z,N | 12 | ||
IORLW | k | Do an OR operation with the constant k and W. | Z,N | 55 | ||
LFSR | f,k | Move the constant k (12-bit) to the f-th FSR register (f = 0 ~ 2). | none | 59 | ||
MOVLB | k | Move the constant k to the BSR register. | none | 64 | ||
MOVL | k | Move the constant k to W. | none | 65 | ||
MULLW | k | Multiply the constant k and W. | none | 67 | ||
RETLW | k | Take out the value of the top layer of the stack and put it into PC, and set the value of W to k ( ), and the main program starts executing from the current PC value. | none | 78 | ||
SUBLW | k | Subtract the constant k from W. | C, DC, Z, OV, N | 92 | ||
XORLW | k | Perform XOR operation on constant k and W. | Z,N | 106 | ||
Program memory read and write instructions (DATA MEMORY <-> PROGRAM MEMORY OPERATIONS) | ||||||
TBLRD* | Using the contents of the TBLPTRH and TBLPTRL registers as address pointers, read the contents of the program memory into the TABLAT register. | none | 99 | |||
TBLRD*+ | Using the contents of the TBLPTRH and TBLPTRL recorders as address pointers, read the contents of the program memory into the TABLAT register, and then automatically add 1 to the address pointer. | none | 99 | |||
TBLRD*- | Using the contents of the TBLPTRH and TBLPTRL recorders as address pointers, read the contents of the program memory into the TABLAT register, and then automatically decrement the address pointer by 1. | none | 99 | |||
TBLRD+* | First add 1 to the TBLPTRH and TBLPTRL recorders, and then use the contents of the TBLPTRH and TBLPTRL recorders as address pointers to read the contents of the program memory into the TABLAT register. | none | 99 | |||
TBLWT* | Using the contents of the TBLPTRH and TBLPTRL registers as address pointers, write the value in the TABLAT register into the program memory. | none | 102 | |||
TBLWT*+ | Using the contents of the TBLPTRH and TBLPTRL registers as address pointers, write the value in the TABLAT register into the program memory, and then automatically increase the address pointer by 1. | none | 102 | |||
TBLWT*- | Using the contents of the TBLPTRH and TBLPTRL recorders as the address pointer, write the value in the TABLAT register into the program memory, and then automatically decrement the address pointer by 1. | none | 102 | |||
TBLWT+* | First add 1 to the TBLPTRH and TBLPTRL recorders, and then use the contents of the TBLPTRH and TBLPTRL recorders as address pointers to write the value in the TABLAT register into the program memory. | none | 102 | |||
Note: | Ff represents the temporary register. | Fd indicates where the data is stored, d = 0 indicates it is stored in the W accumulator; d = 1 indicates it is stored in the f register. | ||||
Fb represents the b-th bit of the temporary register. | ||||||
Fk represents an 8-bit constant. Fn represents the address of the program memory. | Fa indicates which memory location the data is stored in. a = 0 indicates that it is placed in the current memory location; a = 1 indicates that it is placed in the memory location specified in the BSR register. | |||||
Command name: ADDLW
Original meaning: ADD literal to W
Syntax: [label] ADDLW k
Operator:
Operation description: (W) + K -> W
Impact flags: N, OV, C, DC, Z
Instruction description: Add the value in the W accumulator to the k value, and put the operation result back into the W accumulator.
Category: Immediate constant addressing method.
Group: Mathematical operation addition instructions.
Example 1:
ADDLW 0x11; Add the value of 0x11 to the W accumulator, and put the result back into the W accumulator.
Before execution:
W = 0x1F; Assume that the value of W accumulator before execution is 0x1F.
N = OV = C = DC = Z = 0; Assume that the values of the status register before execution are all 0.
After execution:
W = 0x30; After execution, the value of W accumulator is 0x30.
N = OV = C = 0, DC = 1; the half-carry flag is equal to 1, because a carry occurs after the low four bits are added, so the half-carry flag DC is equal to 1 and the status of the other flags remains unchanged.
Example 2:
ADDLW 0x11; Add the value of 0x11 to the W accumulator, and put the result back into the W accumulator.
Before execution:
W = 0x7F; Assume that the value of W accumulator before execution is 0x7F.
N = OV = C = DC = Z = 0; Assume that the values of the status register before execution are all 0.
After execution:
W = 0x90; after execution, the value of W accumulator is 0x90.
N = OV = DC = 1, Z = C = 0; the half-carry flag DC is equal to 1, because a carry occurs after the low four bits are added; the overflow flag OV is equal to 1, because after the two numbers are added, the third A carry situation occurs in 7 bits; the negative flag N is equal to 1, because the result after adding the two numbers is greater than 127, and because 2's complement is used for the operation, the result greater than 127 is considered a negative sign.
Example three:
Previous article:Ultrasonic PIC microcontroller C program
Next article:Single chip microcomputer EC1 digital rotary encoder simulation program
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Pingtouge RVB2601 board-GUI and operating system tasks
- MSP430G2553ADC conversion program
- How to choose the right fuse for your design
- Build an IP surveillance camera system using low-cost FPGA
- Microwave Heating Principle
- 【Development Kit for nRF52840】+ Hardware Review
- [Repost] Comparison between aluminum electrolytic capacitors and tantalum capacitors
- Programming example: CPU card response data command
- How to use multiple devices to study radiation signals - Part 1
- Tianjin - Recruiting embedded software and hardware engineers - fresh graduates preferred