/***** 呼吸灯流水程序 呼吸一下右移一下 *****/
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar i = 0;
uchar code LEDflow[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
void delay(uint t)
{
while(--t);
}
void pwm_led()
{
for (i=0; i<8; i++)
{
uint cycle=500, pwm=0;
for(pwm=cycle-1;pwm>0;pwm--)
{
P1 = 0x00;
delay(pwm);
P1 = LEDflow;
delay(cycle-pwm);
}
for(pwm=1;pwm<cycle;pwm++)
{
P1 = 0x00;
delay(pwm);
P1 = LEDflow;
delay(cycle-pwm);
}
}
}
void main()
{
while(1)
{
pwm_led();
}
}
你好
按照你的意思只增加少许, 这样可以吗.
|