Light up the LED
principle:
The LED light of this single chip is a light emitting diode, which can only pass in one direction. In the figure, the cathode of the LED is connected to the IO port, and the anode is connected to VCC, that is, the power supply, which is a high level. Under normal circumstances, the P2 port outputs a high level by default, so you only need to make the P2 port output a low level.
Code:
#include sbit led=P2^0; //Through bit definition, let led represent port P20 void main() { while(1) { led=0; //Set P20 to low level } } Summarize: Knowledge points: Set pin sbit name = Px^x (IO port) Make the IO port corresponding to the target LED light output low level expand: You can also directly assign values to all IO ports of P2. That is, 1111 1111 from high to low corresponds to 1 to 8 LED lights from left to right. If you want to light it up, set the 1 in that position to 0, and then convert it to hexadecimal. For example, to light up all LEDs, set P2=0x00. At this time, you may see movement on the digital tube, which is normal because P2^2, 3, 4 correspond to the bit selection of the digital tube.
Previous article:51 MCU Learning——2--LED Flashing + Flowing Water
Next article:51 MCU Study Notes [Part 3] - Digital Tube Experiment
Recommended ReadingLatest update time:2024-11-15 10:15
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
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
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Five skills required for RF test engineers
- 【GD32L233C-START Review】Display driver for color OLED screen
- Would you choose the popular outdoor power supply?
- Solution to severe static heating of wireless network card
- China's latest classification catalogue of medical devices (No. 104, 2017)
- What is the function of the cross connection of the five tubes in the middle of this comparator?
- What is the difference between pyb.delay and time.sleep?
- Stepper motor current test
- [RVB2601 creative application development] + light intensity detection
- 【DIY Creative LED】Effect Demonstration