PIC microcontroller assembly language explanation (Part 2)

Publisher:DelightfulWishLatest update time:2020-02-28 Source: eefocusKeywords:pic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:pic Reference address:PIC microcontroller assembly language explanation (Part 2)

Previous article:PIC microcontroller assembly language explanation (Part 1)
Next article:Research on Adaptive Control Technology of Stepping Motor Based on PIC Microcontroller

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号