Friends who read this article must have some interest in PIC microcontrollers, or have some use needs for PIC microcontrollers. In the previous article, the editor has explained part of the assembly language of PIC microcontrollers. In this article, the clearing instructions of PIC microcontrollers will be explained to help everyone better master PIC microcontroller programming.
1. Register clear instruction
1. Register clear instruction
Example: CLRW; register W is cleared
Note: This instruction is very simple, where W is the working register of the PIC microcontroller, equivalent to the accumulator A in the MCS-51 series microcontrollers, and CLR is the abbreviation of the English word Clear.
2. Watchdog timer clear instruction.
Example: CLRWDT; watchdog timer clear (if assigned, clear prescaler at the same time)
Note: WDT is the abbreviation of Watchdog Timer. CLR See the above description. Note that these two instructions have no operands.
3. Register f clear instruction. Instruction format: CLRF f
Example: CLRF TMRO; clear TMRO
Note: In the PIC series 8-bit microcontrollers, the symbol F (or f) is often used to represent various registers and the serial address of F. The value of F varies according to the different models of the PIC series, generally Ox00~Ox1F/7F/FF. TMRO represents the timer/counter TMRO, so CLRF clears the register and uses direct addressing to directly give the register TMRO to be accessed.
4. Bit clear instruction. Instruction format BCF f, b
Example: BCF REG1, 2; clear the D2 bit of register REG1 to zero
Note: BCF is the abbreviation of Bit Clear F. The F in the instruction format is the same as above; the symbol b represents the bit number (or bit address) of a certain 8-bit data register F in the PIC chip, so the value of b is 0 to 7 or D0 to D7. REG in the example is the abbreviation of Register. The 2 in the example represents b=2 in the instruction format, that is, D2 of register REG1.
Through the above four clear instruction formats and examples, it can be explained that when learning the instructions of the PIC series 8-bit microcontroller, you should first understand the mnemonic meaning (function) of the instruction, and then its expression method. Beginners do not need to memorize the instructions, the important thing is to understand and practice.
2. Instructions for bytes, constants and control operations
1. Transferring an immediate value to the working register W Instruction
format: MOVLW k; k represents a constant, an immediate value and a label
Note: MOVLW is the abbreviation of Move Literal to w
Example: MOVL 0x1E; constant 30 sent to W
2.I/O port control register TRIS setting instruction
Instruction format;TRIS f
Description: TRIS f is the abbreviation of Load TRIS Register. Its function is to send the content of the working register W to the I/O port control register f. When W=0, the corresponding I/O port is set as output; W=1, the I/O port is set as input.
Example: MOVLW 0x00; send 00H to W
TRIS RA; Set PIC RA port as output
MOVLW 0xFF ; send FFH to W
TRIS RB; Set PIC RB port as input
Description: These are some commonly used instructions in PIC assembly language, that is, the statements for setting a certain I/O port (here RA port and RB port) as input or output. It can be seen that when reading instructions, one should fully understand the function of the statement format and read it in conjunction with the previous and next instructions.
3. Move the contents of register W to register f (the contents of register W remain unchanged) Instruction
format: MOVWF f
Note: MOVWF is the abbreviation of Move W to f
Example: MOVLW 0x0B; send 0BH and send W
MOVWF 6; send W content to RB port
Explanation: The first instruction 0x0B (constant 11) is sent to the working register W. The second instruction sends the constant 11 in W to register F6. Looking up the table, F6 is port RB, so PORT_B (port B) = 0BH = D11
4. Register f transfer instruction
instruction format: MOVF f, d
Note: MOVF is the abbreviation of Move f. F represents a register in PIC. The d in the instruction specifies: when d=0, the content of f is sent to W; when d=1, the content of f is sent to the register.
Example: MOVF 6, 0; RB port content is sent to W
MOVWF 8; RB port content is sent to f8
Explanation: The 6 in the first instruction represents register f=6. Looking up the register table, f=6 is port RB; 0 represents d=0, indicating that the selected target is register W. The 8 in the second instruction represents register f=8. So the result of the two instructions is to send the content of port RB to f8. As for the content of f8, additional instructions should be added at the beginning of the assembly language, which is omitted here.
5. No operation instruction
instruction format: NOP
Note: NOP is the abbreviation of No Operation. NOP has no operand, so it is called no operation. Executing the NOP instruction only increases the program counter PC by 1, so it takes one machine cycle.
Example: MOVLW 0xOF; send OFH to W
MOVWF PORT_B ;W writes the contents to port B
NOP ; No operation
MOVF PORT_B, W ; read operation
Note: These three instructions are an example of continuous operation on port B of the I/O port. The purpose is to ensure that there is a stable time between writing and reading when the content written to port B is to be read out. Therefore, the no operation instruction NOP is added.
6. Unconditional jump instruction
instruction format: GOTO k
Description: When this instruction is executed, it will be transferred to the specified address (jump). The k in the instruction is often associated with the label in the program.
Example: See instruction No. 9
7. The register content is reduced by 1, and the result is zero. Instruction
format: DECFSZ f, d
Description: DECFSZ is the abbreviation of Decrement f, Skip of not 0. The meanings of the symbols f and d have been explained above. This instruction means that the content of the register is reduced by 1 and stored in W (d=0) or f (d=1). If the result of the instruction execution is not zero, the instructions are executed in sequence; if it is zero, the next instruction is skipped and then executed (equivalent to executing a null instruction NOP in sequence). In actual instructions, when d=1, this item is often omitted.
8. Add 1 to the register content, the result is zero jump instruction
instruction format: INCFSZ f, d
Note: INCFSZ is the abbreviation of Increment f, Skip of 0. The only difference between this instruction and the previous instruction (7) is the "1", that is, when this instruction is executed, the content of register f is increased by 1. If the result is not zero, the instructions are executed sequentially; if it is zero, the instructions are skipped. The other logical relationships of executing this instruction are the same as the previous one.
9. Subroutine return instruction
Instruction format: RETLW k
Description: RETLW is the abbreviation of Return Literal to W. This instruction represents the return from a subroutine. Before returning, the 8-bit immediate value is sent to W.
Previous article:PIC microcontroller assembly language explanation (Part 1)
Next article:Research on Adaptive Control Technology of Stepping Motor Based on PIC Microcontroller
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- 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
- C2000 Power-on Boot Mode Analysis
- CAN bus research notes
- DSP timer and interrupt system realizes variable frequency flashing of LED lights
- STM32F103VE DAC+DMA+TIM, channel 1, no signal output
- Show off the Jingdong E-card exchanged with E-coin
- Series shift register question
- PMOS Circuit Analysis
- CCS 7.4.0 imports routines of PDK_c667x_2_0_9
- 11 years of experience in microwave and radio frequency manufacturing
- I need a QFN24 packaged MCU with two ADCs, two serial ports, low power consumption, in stock, GD Zhaoyi Innovation has recommendations...