Home > other >  STC15 series microcontroller hardware PWM breathing lamp
STC15 series microcontroller hardware PWM breathing lamp

Time:12-01

Recently wanted to use single chip microcomputer hardware implementation RGB gray scale changes, such as R155 G120, B10, breathe the R10, G160, B200, breath, according to the sample application, three road PWM, single-channel breathing can implement now, but the specific colour breathing, how do you calculate to achieve?

 

Void modify_duty ();
Void Init_PWM ();
Void delay ();

Void main ()
{
Init_PWM ();

While (1)
{
Modify_duty ();
}
}

Void Init_PWM ()//
{
CMOD=0 x02;//

CCAPM0=0 x42;//
PCA_PWM0=0 x00;//
CCAP0L=0 x00;//
CCAP0H=0 x00;//

PCA_PWM1=0 x00;
CCAP1L=0 x00;
CCAP1H=0 x00;
CCAPM1=0 x42;

PCA_PWM2=0 x00;
CCAP2L=0 x00;
CCAP2H=0 x00;
CCAPM2=0 x42;


CL=0;//
CR=1;//
}

Void modify_duty ()
{
int i;

for(i=255; I>=1; I -)
{
CCAP0H=I;
CCAP1H=0 XFF;
CCAP2H=0 XFF;
delay();
}
for(i=0; i<255; I++)
{
CCAP0H=I;
CCAP1H=0 XFF;
CCAP2H=0 XFF;
delay();
}

for(i=255; I>=1; I -)
{
CCAP1H=I;
CCAP0H=0 XFF;
CCAP2H=0 XFF;
delay();
}
for(i=0; i<255; I++)
{
CCAP1H=I;
CCAP0H=0 XFF;
CCAP2H=0 XFF;
delay();
}

for(i=255; I>=1; I -)
{
CCAP2H=I;
CCAP0H=0 XFF;
CCAP1H=0 XFF;
delay();
}
for(i=0; i<255; I++)
{
CCAP2H=I;
CCAP0H=0 XFF;
CCAP1H=0 XFF;
delay();
}

}


CodePudding user response:

You want a what kind of color, three color for you choose light should have a corresponding form, detailed instructions for the proportion of each color and the corresponding color,

CodePudding user response:

Good, settled, formulated the form and store certain colors, read values
  • Related