In the hardware structure of the MCS-51 microcontroller, there is a bit processor (also known as a Boolean processor) that has a set of instructions for bit variable processing . When performing bit processing, CY (the carry bit we mentioned earlier) is called a "bit accumulator". It has its own bit RAM, which is the 16-byte unit from 20H to 2FH of the internal RAM we just mentioned, that is, the 128-bit unit, and its own bit I/O space (i.e. P0.0...P0.7, P1.0...P1.7, P2.0...P2.7, P3.0...P3.7). Of course, in physical entities, they are exactly the same as the original byte-addressed RAM and ports, or in other words, these RAMs and ports can be used in two ways.
(1) Bit transfer instructions
MOV C, BIT The function of this group of instructions
MOV BIT, C
is to realize data transfer between the bit accumulator (CY) and other bit addresses.
Example: MOV P1.0,CY; Send the status in CY to the P1.0 pin (if we are doing arithmetic operations, we can know what CY is now by observation).
MOV P1.0,CY; Send the status of P1.0 to CY.
(2) Bit correction instructions
Bit clear instruction
CLR C; Make CY=0
CLR bit; Make the bit address of the instruction equal to 0. Example: CLR P1.0; Even if P1.0 becomes 0,
the position 1 instruction
SETB C; Make CY=1
SETB bit; Make the specified bit address equal to 1. Example: SETB P1.0; Make P.0 become 1
Bit complement instruction
CPL C; Make CY equal to the opposite value of the original, from 1 to 0, from 0 to 1.
CPL bit; Make the value of the specified bit equal to the opposite value of the original, from 0 to 1, from 1 to 0.
Example: CPL P1.0
Taking the experiment we have done as an example, if the light is on, the light will turn off after executing this instruction. Otherwise, if the light is off, the light will turn on after executing this instruction.
(3) Bit logic operation instructions
Bit AND instruction
ANL C, bit; CY is ANDed with the value of the specified bit address, and the result is sent back to CY
ANL C, /bit; First take out the value in the specified bit address and then invert it, and then AND it with CY, and the result is sent back to CY, but note that the value in the specified bit address itself does not change.
Example: ANL C, /P1.0
Assume that before executing this instruction, CY=1, P1.0 is equal to 1 (light off), then after executing this instruction, CY=0, and P1.0 is also equal to 1.
The following program can be used for verification:
ORG 0000H
AJMP START
ORG 30H
START: MOV SP, #5FH
MOV P1, #0FFH
SETB C
ANL C, /P1.0
MOV P1.1, C; Send the completed result to P1.1. The result should be that the light on P1.1 is on, while the light on P1.0 is still off. The function of the bit
or instruction
ORL C, bit
ORL C, /bit
is analyzed by yourself, and then compared with the above example, write a verification program to see if you are right?
(4) Bit conditional transfer instructions
CY transfer instructions
JC rel
JNC rel
The function of the first instruction is to transfer if CY is equal to 1, and execute in sequence if it is not equal to 1. So where to transfer to? We can understand it this way: JC label, if it is equal to 1, transfer to the label and execute. We have already talked about this instruction in the last class, so we will not repeat it.
The second instruction is the opposite of the first instruction, that is, if CY=0, it will be transferred, and if it is not equal to 0, it will be executed in sequence. Of course, we also understand: JNC label
judgment variable transfer instruction
JB bit,rel
JNB bit,rel
The first instruction is to transfer if the value in the specified bit is 1, otherwise it will be executed in sequence. Similarly, we can understand this instruction like this: JB bit, label.
Please analyze the second instruction by yourself first. Let
us give an example to illustrate:
ORG 0000H
LJMP START
ORG 30H
START: MOV SP, #5FH
MOV P1, #0FFH
MOV P3, #0FFH
L1: JNB P3.2,L2; There is a button connected to P3.2. When it is pressed, P3.2=0
JNB P3.3,L3; There is a button connected to P3.3. When it is pressed, P3.3=0
LJM P L1
L2: MOV P1,#00H
LJMP L1
L3: MOV P1,#0FFH
LJMP L1
END
Write the above example into the chip and see what happens...
Press the button connected to P3.2, and all the lights on port P1 will light up. Release it or press it again, and the lights will not go out. Then press the button connected to P3.3, and all the lights will go out. What does this look like? Isn't this the "start" and "stop" function often used in industrial sites?
How is it done? At the beginning, 0FFH is sent to the P3 port, so that all the leads of P3 are at a high level, and then L1 is executed. If P3.2 is at a high level (the key is not pressed), the JNB P3.3, L3 statement is executed in sequence. Similarly, if P3.3 is at a high level (the key is not pressed), the LJMP L1 statement is executed in sequence. In this way, P3.2 and P3.3 are continuously detected. If the button on P3.2 is pressed once, it will transfer to L2 and execute MOV P1, #00H to make all the lights on, and then transfer to L1 again, and the cycle will continue until P3.3 is detected to be 0, then transfer to L3, execute MOV P1, #0FFH, and all the lights will go out, and then transfer to L1, and the cycle will continue.
Previous article:51 MCU bit transfer instruction MOV
Next article:51 MCU bit addressing area and SFR capable of bit addressing
Recommended ReadingLatest update time:2024-11-16 21:48
- Popular Resources
- Popular amplifiers
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- 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)
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
- [Ateli Development Board AT32F421 Review] + Flash simulates EEprom to store data
- [Analysis of College Student Electronic Competition Topic] —— 2022 TI Cup Invitational Topic X "Lissajous Figure Demonstration Device"
- Effects of Differential Input Clamping on Operational Amplifiers
- ADI New Chinese Information
- Does anyone know what this board is used for?
- RISC-V core chip trial
- Two-way BUCK
- MSP430 Classic Textbook Recommendations
- GaN Technology Then and Now
- It is reported online that Zhang Rujing said that "the United States has little power to restrict China", and the organizer responded