51 MCU PWM control LED brightness simulation program diagram

Publisher:码字狂徒Latest update time:2022-01-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The microcontroller outputs PWM chopping to control the brightness of the LED and display it on the graph

insert image description here
Simulation On

insert image description here

Reference Code:


#include "reg51.h"

unsigned int cd,dd;

unsigned char cc,ee;


sbit LED=P2^0;

void led_int() interrupt 1 using 0

{

TH0=0xf1;

TL0=0xf1;

TR0=1;

dd++;

if(dd11)

{

if((cc0x50)&&(ee0)){cd=0;}

if((cc0)&&(ee==0x50)){cd=1;}

if(cd){cc++;ee–;}

else {cc–;ee++;}

dd=0;

}

}

void delay(unsigned int i)

{

unsigned int j;

while(i–)

{

for(j=0;j<0x20;j++);

}

}


void main()

{

cc=0;

ee=0x50;

TMOD=0x01;

TH0=0xf0;

TL0=0xf0 ;

EA=1;

ET0=1;

TR0=1;

while(1)

{

LED = 0;

delay(ee);

LED=1;

delay(cc);

}

}

Reference address:51 MCU PWM control LED brightness simulation program diagram

Previous article:Creative invention: single chip microcomputer makes capacitance and resistance measuring instrument
Next article:Single chip intelligent temperature control fan design with intelligent speed regulation and human body sensing

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号