51 MCU PWM modulation to achieve simulated breathing light

Publisher:RadiantBlossomLatest update time:2019-12-31 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Using PWM modulation to achieve the breathing light effect

. Without further ado,

the simulation schematic diagram is as follows

The microcontroller source program is as follows:

//Function: simulate breathing light through PWM modulation

//Name: Breathing Light

#include //Call the header file containing 51 special registers

#define uchar unsigned char // for uchar substitute for unsigned char

#define uint unsigned int // for uint alternative to unsigned int


void delayms(int xms) //Pulse width modulation function

{

while(xms--);

}


void main() //Main function

{

           uint T=400,N=0; //define cycle

   while(1)      

  {          

                                      

           for(N=1;N        {

          P1=0x00;           

          delayms(N);

          P1=0xff;

          delayms(T-N);        

        }

        P1=0xff;


  for(N=T-1;N>0;N--) //gradually change from bright to dark

        {

          P1=0x00;

          delayms(N);

          P1=0xff;

          delayms(T-N);        

        }

        delayms(N+10); //Increase the extinguishing effect seen

   }         

  }


Reference address:51 MCU PWM modulation to achieve simulated breathing light

Previous article:IIC communication establishment process
Next article:51 single-chip heart-shaped water flow and digital tube synchronization effect display simulation and program

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号