#include //The program is written based on KEIL-C51, which introduces 8051 header file sbit P10=P1^0; sbit P11=P1^1; unsigned int scale; //duty cycle control variable void main(void) { unsigned int n ; / / delay loop variable TMOD = 0x02; / / timer 0, working mode 2 (0000 0010), 8-bit timing TH0 = 0x06; / / timing 250us (12M crystal) TL0 = 0x06; / / preset value TR0 =1; //Start timer 0 ET0=1; //Start timer 0 interrupt EA=1; //Open total interrupt while(1) { for(n=0;n<50000;n++); Time scale++; //duty control variable plus one if(scale==10) scale=0; //reach loop effect} } timer0() interrupt 1 //timer 0 interrupt program { static unsigned int tt ; / / tt is used to save the current time in a clock cycle position tt + +; / / every interrupt, that is, every 250us, tt value is added 1 if (tt == 10) / / interrupt 10 times 2.5ms, { tt=0; // Make tt=0, start a new cycle, achieve the effect of the loop P10=0; //Light the LED } if( Scale>=tt) //If the duty cycle is the same as the number of interrupts, then the high level is output P10=1; //The LED light is off/* The previous program sets the duty cycle to 10 levels, scale The time to maintain high level when =1 is 1/10 PWM cycles (here is 2.5ms), because the time period of scale<=tt is low level to light the LED light, the time of scale>=tt is to extinguish the LED The brightness of the LED lamp or the speed of the motor can be controlled by changing the length of time during which the high and low levels are maintained in one cycle. This is how the PWM works*/}
PWM principle:
A slight modification to the program becomes the speed control of the motor. The simulation in proteus8.4 is as follows:
Product categories of Vozol, we are specialized electronic cigarette manufacturers from China, Vapes For Smoking, Vape Pen Kits, Vape Cartridge, Smoking Accessories,E-Cigarette suppliers/factory, wholesale high-quality products of Modern E-Cigarette R & D and manufacturing, we have the perfect
after-sales service and technical support. Look forward to your cooperation!
vozol disposable vape,puff bar vozol vape,vozol bar disposable vape kit,pod vozol bar vape,vozol vape pen
Ningbo Autrends International Trade Co.,Ltd. , https://www.supervapebar.com