I found a breathing light program on the Internet and wrote it myself.
I used a timer to generate pwm to realize the breathing light
. I can also control the speed of the DC motor by referring to the breathing light program. You can go to this page to see https://www.zhihu.com/tardis/sogou/art/83373994
pwm waveform:
The microcontroller source program is as follows:
#include #define uint unsigned int #define uchar unsigned char bit flag; //Determine whether to brighten or darken based on flag uchar count; //Enter interrupt times uchar pwm; //Turn on or off according to this value uint updata; //Update the duty cycle according to this value, period 120ms sbit LED=P2^0; //LED pin void timer0(); /*********Timer initialization function***********/ void timer0_init() { TMOD=0x02; //Timer 0, mode 2 TH0=0xa3; //Assume the crystal oscillator is 11.0592M, the timing is 100us TL0=0xa3; ET0=1; //Open timer 0 interrupt EA=1; //Open the general interrupt TR0=1; //Start the timer } void main() { flag=0; //Initial duty cycle rise count=0; pwm=10; //Pulse period is 2ms, initial duty cycle is 50% updata=0; LED=1; timer0_init(); while(1); } void timer0() interrupt 1 { count++; updata++; if(count==pwm) LED = 0; if(count==20) { LED=1; count=0; } if((updata==1200)&&(flag==0)) //120ms arrives, update the duty cycle according to flag { updata=0; pwm++; //Add 1 each time, the duty cycle increases by 5% if(pwm==19) flag=1; } if((updata==1200)&&(flag==1)) { updata=0; pwm--; if(pwm==1) flag=0; } } 3-Basic parameters of PWM In the figure above, the value of frequency F is 1/(T1+T2), and the value of duty cycle D is T1/(T1+T2). Frequency modulation can be achieved by changing the number of pulses per unit time; voltage regulation can be achieved by changing the duty cycle. The larger the duty cycle, the larger the average voltage and the larger the amplitude; the smaller the duty cycle, the smaller the average voltage and the smaller the amplitude. The dynamic diagram is shown in Figure 4.
Previous article:Single chip electronic perpetual calendar with lunar calendar display
Next article:51 MCU beginner practice: using BME280 module to obtain temperature, humidity and air pressure data
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Using Ultra-Wideband Technology to Display the Bible
- How is "u8 Dat2:7;" written in the structure? What does it mean?
- Modeling and Optimization Design of Finite State Machines
- Help! Can micropython do image processing or video processing?
- Pin-regulated 8mA output amplifier
- Is this the most comprehensive collection of RF project design tools?
- A pitfall in buying goods on a certain fish - BMW night vision camera
- Big Brother, please help
- Analog Engineer's Circuit Design Guide - Data Converters
- 54V, 1.5kW Power Stage Reference Design for Three-Phase BLDC Drives