Logical operation on the accumulator A of the microcontroller :
CLR A; clear the value in A to 0, single-cycle single-byte instruction, with the same effect as MOV A, #00H.
CPL A ; reverse the value in A bit by bit
RL A ; logically shift the value in A to the left
RLC A; logically shift left the value in A plus the carry bit
RR A ; logically shift the value in A to the right
RRC A; add the value in A to the carry bit and perform a logical right shift
SWAP A; swap the high and low 4 bits of the value in A.
For example: (A) = 73H, then execute CPL A, as follows:
73H is converted to binary as 01110011.
The bit-by-bit inversion is 10001100, which is 8CH.
RL A sends the 7th bit of the value in (A) to the 0th bit, the 1st bit to the 0th bit, and so on.
For example: The value in A is 68H, and RL A is executed. 68H is converted to binary as 01101000, and the shift is performed as shown above. 01101000 is converted to 11010000, which is D0H.
RLC A shifts the value in (A) with the carry bit (C).
For example: if the value in A is 68H and the value in C is 1, then RLC A is executed.
After 1 01101000, the result is 0 11010001, that is, the value of the carry bit of C becomes 0, and (A) becomes D1H.
I won’t talk much about RR A and RRC A. Please refer to the two examples above and practice on your own.
SWAP A swaps the high and low 4 bits of the value in A.
For example: (A) = 39H, then after executing SWAP A, the value in A is 93H. Why is it swapped like this? Because this is a hexadecimal number, and each hexadecimal digit represents 4 binary bits. Note that if it is like this: (A) = 39, without H behind it, after executing SWAP A, (A) = 93 is not. It needs to be converted into binary and then calculated: 39 is converted into binary 10111, which is 0001. The upper 4 bits of 0111 are 0001, and the lower 4 bits are 0111. After swapping, it is 01110001, which is 71H, or 113.
Exercise, given (A) = 39H, execute the following microcontroller instructions and write out the results of each step
CPL A
RL A
CLR C
RRC A
SETB C
RLC A
SWAP A
Through the previous learning, we have mastered quite a few MCU instructions. You may be a little bored with these boring MCU instructions. Let's relax and do an experiment.
Experiment 5:
ORG 0000H
LJMP START
ORG 30H
START:
MOV SP,#5FH
MOV A,#80H
LOOP:
MOV P1,A
RL A
LCALL DELAY
LJMP LOOP
delay:
mov r7,#255
d1: mov r6,#255
d2: nop
nop
nop
nop
djnz r6,d2
djnz r7,d1
ret
END
Let us first write the program into the chip, install it into the experimental board, and see the phenomenon.
What we see is a phenomenon of dark spots flowing. Let us analyze it.
We will analyze the previous ORG 0000H, LJMP START, ORG 30H later. Starting from START, MOV SP, #5FH, this is to initialize the stack. It doesn't matter whether this sentence exists in this program, but we are slowly starting to get in touch with formal programming, so I will slowly cultivate the habit for everyone.
MOV A, #80H, sends the number 80H to A. What does it do? I don't know. Read on.
MOV P1, A. Send the value in A to the P1 port. At this time, the value in A is 80H, so the value sent out is 80H, so the value of the P1 port is 80H, which is 10000000B. Through the previous analysis, we should know that at this time, the LED connected to P1.7 is not bright, while the other LEDs are bright, so a "dark spot" is formed. Continue to look at RL A, RL A is to shift the value in A to the left. Calculate, what is the result after the shift? Yes, it is 01H, which is 00000001B. In this way, the LED connected to P1.0 should not be bright, while the others are bright. From the phenomenon, the "dark spot" flows to the back. Then call the delay program, which we are very familiar with, to make this "dark spot" "dark" for a while. Then transfer to LOOP (LJMP LOOP). Please calculate which light should be off below. . . . . Yes, it should be connected to P1.1. The light is not on. This cycle forms the phenomenon of "dark spot flow".
question:
How to achieve highlight flow?
How to change the direction of flow?
Answer:
1. Change the initial value in A to 7FH.
2. Change RL A to RR A.
Previous article:51 MCU Tutorial from Scratch - 12 MCU Arithmetic Instructions
Next article:51 MCU tutorial from scratch - 14 MCU logical AND or XOR instructions detailed explanation
Recommended ReadingLatest update time:2024-11-17 01:27
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- Low power mode of msp430f149
- GaN Reference Designs
- How to get started with embedded development?
- [Perf-V Review] Transplanting the Hummingbird E203 open source SOC to the FPGA board
- How to control a switch with stm32
- Design USB3.1 high-speed SD Card reader based on Genesys GL3224
- If you want to make the three-pole tube work in the amplification area, what is the idea? You need to calculate the static working point ib ic VCE three...
- How to save the bricks with the RVB2601 board
- Does the AD18 library have this kind of package? Do I have to draw it myself?
- What is the function of this circuit in ESP32_Audio_kit?