Now let's start the first experiment: an experiment in which eight light-emitting diodes light up in turn, which is commonly known as the marquee experiment. First, let us complete the necessary hardware part. We need to weld 8 light-emitting diodes and 8 For the current limiting resistor, you can refer to the schematic diagram and actual image below for operation. It should be noted that the LED has polarity. The long pin is the positive pole, and the short pin is the negative pole. The negative pole is connected to one side of the resistor. If connected If it is wrong, the corresponding path may not light up during the experiment. Please check it carefully before welding.
Next we will complete the software programming design. Here we do not use advanced programming skills, but use the stupidest and most direct method of sending numbers to the port. First of all, the program is relatively simple, there is no need to play deep, and beginners It seems intuitive and easy to understand.
ORG 0000H
START: MOV P1, #01111111B; The bottom LED lights up
LCALL DELAY; the delay is 1 second
MOV P1, #10111111B; the second bottom LED lights up
LCALL DELAY; the delay is 1 second
MOV P1, #11011111B ;The third LED at the bottom lights up (omitted below)
LCALL DELAY
MOV P1,#11101111B
LCALL DELAY
MOV P1,#11110111B
LCALL DELAY
MOV P1,#11111011B
LCALL DELAY
MOV P1,#11111101B
LCALL DELAY
MOV P1,#11111110B
LCALL DELAY
MOV P1, #11111111B; Complete the first cycle of lighting, with a delay of about 0.25 seconds
AJMP START; Cycle repeatedly
; Delay subroutine, 12M crystal oscillator delay of about 250 milliseconds
DELAY:
MOV R4, #2
L3: MOV R2, #250
L1: MOV R3 ,#250
L2: DJNZ R3 ,L2
DJNZ R2 ,L1
DJNZ R4 ,L3
RET
END This is the programmer
programming file obtained after the above program assembly : 201.hex How to download the programming file: Move the mouse to the super key link of the burning file, click the right button of the mouse, and select "Save target as (A)..." Do not select "Text file" as the save file type. You should select "All files", so that you can Got the *.hex file. How to accurately calculate the execution time of a delay subroutine? One of the advantages of assembly language is that it can accurately control the execution time of the program, which is very important when writing some peripheral device drivers that have strict timing requirements! ;Delay subroutine, 12M crystal oscillator delay is about 253 milliseconds DELAY: MOV R4, #2---execute 1 machine cycle, taking 1 microsecond L3: MOV R2,#250---execute 1 Machine cycle, takes 1 microsecond L1: MOV R3, #251——Executes 1 machine cycle, takes 1 microsecond L2: DJNZ R3, L2——Execute 2 machine cycles, repeatedly executes 251 times (2x251 ) = 502 microseconds) DJNZ R2, L1---execute 2 machine cycles, repeatedly executed 250 times (1+502+2)*250=126250 microseconds) DJNZ R4, L3---execute 2 machine cycles, Repeatedly executed 2 times (1+1+502+126250+2)*2=253512 microseconds) RET delay plus the first one, the total delay is 1+253512=253513 microseconds
Previous article:About the design of ATT7022B high-precision smart meter
Next article:Design and implementation of remote power safety measurement and control system
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- instaSPIN-FOC Motor Starting
- TGF4042 Function Signal Generator Evaluation: Pulse Waveform Generation
- Practical Hardware Manual
- Let's talk about the calculation method of RCD
- MSP430F5529 generates PWM waves with CCS
- TI C66x DSP QM queue reserve method
- GD32E231Cx builds its own project OK, share it with everyone
- How to deal with audio noise
- Wireless MIDI Control
- Terasic C5P FPGA development board and Intel Up2 Squared Grove development kit released