Without further ado, let’s start with the program
ORG 0000H
MAIN:MOV P1,#0O
LCALL DELAY
MOV A,#0FEH
SETB C
TO: MOV P1,A
LCALL DELAY
LCALL DELAY
RLC A
JC TO
MOV P1,A
LCALL DELAY
LCALL DELAY
TO1: RRC A
MOV P1,A
LCALL DELAY
LCALL DELAY
JC TO1
AJMP TO
DELAY:MOV R2,#0FEH
TC1:MOV R3,#0FEH
TC2:DJNZ R3,TC2
DJNZ R2,TC1
RET
END
The purpose of this program is to make 8 LEDs light up in a cycle, and one of them is not lit at all. My LED is connected to the P1 port and lights up when the level is low. The general phenomenon is that they all light up once, then light up in sequence from left to right, and then all go out, then light up once from right to left, and then go out, and then the cycle continues like this.
Now let's analyze the code step by step. I won't repeat the knowledge points I talked about before. I will write it briefly and if you don't understand, look ahead.
ORG 0000H; I won’t talk about this anymore
MAIN:MOV P1,#00; Let all lights turn on
LCALL DELAY; delay
MOV A,#0FEH; 11111110 is assigned to accumulator A. Accumulator A is equivalent to a temporary variable and temporary register in C language.
SETB C; Set the carry flag C to 1, which is equivalent to adding one bit to the eight bits. This can make the lights all off. Wait until you understand everything below to see the function of this statement. , which is better understood this way.
TO: MOV P1,A; This statement is labeled TO. After execution, the leftmost light will light up.
LCALL DELAY
LCALL DELAY
RLC A; This is a new statement, which performs circular left shift and carry on A. RLC, my understanding is recircle left carry. When translated into Chinese, it means circular left shift and carry, which means adding accumulator A and carry flag C together. Cycle left
It is equivalent to 9 numbers moving back and forth in a cycle, and there is a 0 in it. Wherever this 0 is moved, whichever light will light up. When it moves to the carry flag, every light will not light up, because the carry flag is not Control the lights on and off.
JC TO; JC means to judge whether to transfer based on whether the carry flag C is 1. Jump carry. If C is equal to 1, jump to TO and continue to perform the left shift. Otherwise, the following program will be executed. Since 8 1 and a 0 move in these nine positions, so only when 0 moves to the carry flag C, it will execute the following program, so when it does not cycle to the state of all off, it will continue to perform the left shift
MOV P1,A; assign the state that the carry flag C is 0 to the P1 port, and let all the lights go out.
LCALL DELAY
LCALL DELAY
TO1: RRC A; RRC, recircle right carry, cycle right shift with carry and RLC cycle in the opposite direction. There is no difference in essence. From this time on, the first light on the right will light up, and it will light up to the far left
MOV P1,A
LCALL DELAY
LCALL DELAY
JC TO1; rotate right
AJMP TO; move to the far right and jump back to the front to start looping left
DELAY:MOV R2,#0FEH; The following is the delay function
TC1:MOV R3,#0FEH
TC2:DJNZ R3,TC2
DJNZ R2,TC1
RET
END
You can try RL and RC, which do not have a carry flag, so there will not be a state where everything is turned off. If there is something wrong or not in place, please give me your advice. It is best for you to buy a 51 or 52 microcontroller and play with it to learn, otherwise it will be very ineffective. Try for yourself what will happen if those statements are missing. Then change the program according to your goals.
Previous article:51 microcontroller realizes temperature acquisition and display (2)
Next article:Use assembly to write the beginning of 51 microcontroller to light up the LED
- Popular Resources
- Popular amplifiers
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
- GD32L233C TRNG processing and PWM configuration (II)
- Introduction to basic parameters of analog switches and multiplexers
- Remote serial port debugging tool
- Power chip control
- EEWORLD University ---- Fundamentals of Electronic Design Huang Genchun
- 「Forum Skills」Usage of Markdown
- EEWORLD University Hall - Sharing of finger oximeter control and OTA upgrade application solutions based on Lingdong MM32W0 series MCU
- Basic knowledge of RF circuits
- ADC Research of msp430F5438A
- 【Sunbathe】Participate