楼主我也遇到麻烦为啥用PWM。调光的呼吸灯的程序变成流水灯程序的一个函数调用的形式。结果只有流水没有呼吸。
求救大佬:'(
#include"reg52.h"
#include<intrins.h>
typedef unsigned int u16;
typedef unsigned char u8;
sbit led1=P2;
int PWM_Low,Clock=500;
#define led P2
void delay(u16 a)
{while(a--);
}
void main1(int t)
{
for(PWM_Low=Clock;PWM_Low>0;PWM_Low--)
{t=1;
delay(PWM_Low);
{int b;
for (b=0;b<PWM_Low;b++);}
t=0;
delay(Clock-PWM_Low);
{int b;
for (b=0;b<Clock-PWM_Low;b++);}
} }
void main()
{u8 i,t,t1,t2;
t1=0xfe;
t2=0x7f;
for(i=0;i<4;i++)
{t=t1&t2;
led=t;
main1(t);
delay(50000);
t1=_crol_(t1,1);
t2=_cror_(t2,1);} }
了 |