LED working conditions
The operating voltage drop of ordinary light-emitting diodes is 1.6V – 2.1V
Working current 1-20mA
Here I = U/R = 3mA
Light up the LED
Here, you only need to control the P1 port to output a low level to light up the LED (that is, assign a value of 0 to the P1 port during programming).
MCU Programming
/***Light up the third and sixth lights***/
#include sbit LED3 = P1^2; //bit defines the third light sbit LED6 = P1^5; //The sixth light void main(){ LED3 = 0 ; LED6 = 0; } If there are many lights, the above method is too troublesome Can be rewritten as the following code #include void main(){ P1 = 0xdb; //1101 1011 } LED water light Delay function /*Custom delay function delay (milliseconds)*/ void delay(unsigned int z){ unsigned int x,y; for (x=z;x>0;x--) for (y=114;y>0;y--); Circular shift function #include #include /*Custom delay function delay (milliseconds)*/ void delay(unsigned int z){ unsigned int x,y; for (x=z;x>0;x--) for (y=114;y>0;y--); } void main(){ unsigned int defult; defult = 0xfe ; //1111 1110 while (1){ defult = _crol_(defult,1); //left shift _crol_(variable, number of shifts) right shift _cror_() P1 = defult; delay(100); P1 = 0xff; //1111 1111 delay(10); } } Difference between shift function and shift operator
Previous article:Snake program based on 51 single-chip development board 8*8LED matrix
Next article:51 MCU Learning (II) 74HC595 Module to Realize Dot Matrix Screen
- 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
- 【GD32E503 Review】Part 7: What is screen tearing? Let’s take a look!
- 【ESP32-Korvo Review】 04 Development Environment Construction
- How to remove the AD official logo from the PCB template
- Requirements for using IAR ETM Trace debugging features
- Will the basic technology of PA become more complex with the advent of the 5G era?
- [NXP Rapid IoT Review] Unboxing photos and simple connection test
- [Reprint] Open-loop full sine sensorless FOC
- [Project source code] Use of digital filter based on FPGA
- GD32F310 series introduction and data download
- CB5654 Development Board Review 5——Compiling in Linux Environment (But Burning Failed)