Let’s talk about PWM dimming first. PWM stands for “Pulse Width Modulation”, which means changing the ratio of high and low levels within a fixed cycle to make the LED show different brightness levels.
The blogger compiled a relatively simple one: within the cycle of CYCLE pulses, the number of low-level pulses PWM_LOW increases from 0 to CYCLE, and the number of high-level pulses will of course decrease, so that the LED will show a "gradually bright" effect, and the same applies to "gradually dimming".
Attached is the source code: (I am a rookie, so there are inevitably some poorly written parts. It is only for backup purposes. Welcome to give me some advice, and please go away if you hate me...)
#include
#define CYCLE 300 // Define a cycle with 300 pulses
void Delay(unsigned int t);
sbit LED = P1^0;
void main(void)
{
unsigned int PWM_LOW; //Number of low levels
unsigned int PWM_HIGH; //Number of high levels
while (1) {
for (PWM_LOW=0; PWM_LOW
Delay(PWM_LOW);
LED = 1;
Delay(CYCLE-PWM_LOW);
}
for (PWM_HIGH=0; PWM_HIGH
Delay(PWM_HIGH);
LED = 0;
Delay(CYCLE-PWM_HIGH);
}
}
}
void Delay(unsigned int t)
{
while (t--);
}
Previous article:【C51】Source code 2 -- Basic display of 8-bit common cathode digital tube
Next article:Simple calculator with remainder designed by single chip microcomputer
- 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
- Keysight Technologies Helps Samsung Electronics Successfully Validate FiRa® 2.0 Safe Distance Measurement Test Case
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- Innovation is not limited to Meizhi, Welling will appear at the 2024 China Home Appliance Technology Conference
- 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)
- [Operation Tutorial] Practical operation of ATX-100 series wire harness tester!
- MSP430 low power event driven working mode
- How to achieve communication between heterogeneous processors - Mir takes you to play with the i.MX 8M Plus development board
- How to select switching power supply topology-Video sharing
- 【AT32F421 Review】+ Introduction and Development Environment Construction
- How to make an embedded device enumerate as a WinUSB device
- All the TWS wireless Bluetooth headset designs you want are here!
- [Share] Overview of debugging methods for ARM development
- EEWORLD University Hall - Five Lectures on Microwaves
- [Environmental Expert’s Smart Watch] Part 1: Long-awaited unboxing!