First, let's make the first light flash:
start: SETB P0.0; (1) turns off the light
LCALL DELAY; (2) is a delay, calling the delay subroutine instruction
CLR P0.0; (3) turns on the light
LCALL DELAY; (4) is exactly the same as the second one, also calling the delay subroutine instruction
LJMP start; (5) Jump back to execute the first instruction
DELAY: MOV R7, #250; (6) Let R7 be a counter and load a constant
D1: MOV R6, #250; (7) Let R6 be a counter and load a constant
D2: DJNZ R6, D2; (8) Let R6 decrement by 1 and determine whether R6 is 0. If R6 is 0, execute the instruction below. If R6 is not 0, jump to D2 and continue to decrement R6 by 1.
DJNZ R7, D1; (9) Let R7 decrement by 1 and determine whether R7 is 0. If R7 is 0, execute the instruction below. If R7 is not 0, jump to D1 to make R6 complete a new round of counting.
RET; (10) Return instruction.
END; (11) End of program
Then there are the flashing programs:
;------------------Main program------------------
START: CLR P0.0;P0.0 outputs a low level to light up LED 1
ACALL DELAY;Call the delay subroutine
SETB P0.0;P0.0 outputs a high level to turn off LED1
CLR P0.1;P0.1 outputs a low level to light up LED2
ACALL DELAY;Call the delay subroutine
SETB P0.1;P0.1 outputs a high level to turn off LED2
CLR P0.2;P0.2 outputs a low level to light up LED3
ACALL DELAY;Call the delay subroutine
SETB P0.2;P0.2 outputs a high level to turn off LED3
CLR P0.3;P0.3 outputs a low level to light up LED4
ACALL DELAY;Call the delay subroutine
SETB P0.3;P0.3 outputs a high level to turn off LED4
CLR P0.4;P0.4 outputs a low level to light up LED5
ACALL DELAY;Call the delay subroutine
SETB P0.4;P0.4 outputs a high level to turn off LED5
CLR P0.5;P0.5 outputs a low level to turn on LED6
ACALL DELAY;Call the delay subroutine
SETB P0.5;P0.5 outputs a high level to turn off LED6
CLR P0.6;P0.6 outputs a low level to turn on LED7
ACALL DELAY;Call the delay subroutine
SETB P0.6;P0.6 outputs a high level to turn off LED7
CLR P0.7;P0.7 outputs a low level to turn on LED8
ACALL DELAY;Call the delay subroutine
SETB P0.7;P0.7 outputs a high level to turn off LED8
ACALL DELAY;Call the delay subroutine
AJMP START;After the eight lights are on, return to the beginning and loop again
;------Delay subroutine-------
DELAY: MOV R0,#255;R0 is loaded with 255
D1: MOV R1,#255;Load 255 into R1
DJNZ R1,$;Decrement R1 to zero and then execute the next instruction
DJNZ R0,D1;Decrement R0 by 1. If it is zero, execute the next instruction. If it is not zero, jump to D1
RET;Return from the subroutine
;============================================================================================================;
END;End of program
Previous article:Using C51 to make a running light
Next article:A simple alarm system based on 89C51
- 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
- I don't quite understand this thermal imager resolution comparison chart
- Where can I buy an LCD that works with the STM32F429IGT6?
- [TI recommended course] #Amplifier design in test and measurement#
- Seeking long-term cooperative lecturers for win-win cooperation
- MSP430F149 I/O port control
- Xunwei-i.MX6ULL Development Board-Busybox transplant DHCP (Part 3)
- Free download of test solutions: R&SCMA180 - ideal test tool for analog and digital radio walkie-talkies
- Review summary: APM32E103VET6S MINI development board with the Polar Ocean M3 core
- Live broadcast at 13:15 this afternoon [Keysight World 2020|Telecom Infrastructure, Cloud and Artificial Intelligence Forum]
- [RISC-V MCU CH32V103 Review] - 4: EXTI starts the troubleshooting journey