Logical operations on accumulator A:
CLRA; clear the value in A to 0, single-cycle single-byte instruction, with the same effect as MOVA, #00H.
CPLA; reverse the value in A bit by bit
RLA; logically shift the value in A to the left
RLCA; logically shift left by adding the carry bit to the value in A
RRA; logically shift the value in A to the right
RRCA; logically shift right by adding the carry bit to the value in A
SWAPA; swap the high and low 4 bits of the value in A.
For example, if (A) = 73H, CPLA is executed as follows:
73H is converted to binary as 01110011.
The bit-by-bit inversion is 10001100, which is 8CH.
RLA 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 RLA is executed. 68H is converted to binary 01101000, and the shift is performed according to the above figure. 01101000 is converted to 11010000, which is D0H.
RLCA 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 RLCA is executed.
After 101101000, the result is 011010001, that is, the value of the carry bit of C becomes 0, and (A) becomes D1H.
I won’t talk much about RRA and RRCA. Please refer to the two examples above and practice on your own.
SWAPA swaps the high and low 4 bits of the value in A.
For example: (A) = 39H, then after executing SWAPA, 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 SWAPA, (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 instructions and write down the results of each step
CPLA
RLA
CLRC
RRCA
SETBC
RLCA
SWAPA
Through the previous learning, we have mastered quite a few instructions. You may be a little bored with these boring instructions. Let's relax and do an experiment.
Experiment 5:
ORG0000H
LJMPSTART
ORG30H
START:
MOVSP,#5FH
MOVA,#80H
LOOP:
MOVP1,A
RLA
LCALLDELAY
LJMPLOOP
delay:
movr7,#255
d1:movr6,#255
d2:nop
nop
nop
nop
djnzr6,d2
djnzr7,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 ORG0000H, LJMPSTART, ORG30H later. Starting from START, MOVSP, #5FH, this is to initialize the stack. It doesn't matter whether this sentence is in this program, but we are slowly starting to get in touch with formal programming, so I will slowly cultivate the habit for everyone.
MOVA, #80H, sends the number 80H to A. What is it for? I don't know. Read on.
MOVP1, 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 RLA, RLA 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 (LJMPLOOP). 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 RLA to RRA.
Previous article:8051 MCU Tutorial Lesson 11: Arithmetic Operation Instructions
Next article:Create a new Keil C51 project (3)
Recommended ReadingLatest update time:2024-11-16 15:55
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- Principles and Applications of Single Chip Microcomputers 3rd Edition (Zhang Yigang)
- Principles and Applications of Single Chip Microcomputers and C51 Programming (3rd Edition) (Xie Weicheng, Yang Jiaguo)
- STC32G Series MCU Technical Reference Manual
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
- A novice asks for advice on the MSP430 interrupt flag PxIFG
- ST MEMS sensor official Chinese technical documentation summary (continuously updated)
- What is 5G Super Uplink?
- Outsourcing of small brushless sensor driver
- Single-ended forward converter
- Bootloader issue of CH579
- SPI to USB CDC
- Battery Pack SOC
- Strange phenomenon of screen display and USB!
- 50 ohm impedance line problem