|
#include<reg51.h>
/*-----------定义单片机引脚-----*/
sbit LED0=P1^0;
sbit LED1=P1^1;
sbit LED2=P1^2;
sbit LED3=P1^3;
sbit LED4=P1^4;
sbit LED5=P1^5;
sbit LED6=P1^6;
sbit LED7=P1^7;
void Delay(unsigned int t); //函数声明
unsigned int z,y;
void main (void)//主函数
{
unsigned int CYCLE=500,PWM_LOW=0;//定义周期并赋值
while (1) //主循环
{
/*--------整排LED灯呼吸---------*/
P1=0x00;
Delay(500); //加延时,可以看到熄灭的过程(下面程序同理)
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++) //PWM_LOW表示低
{
P1=0x00;
Delay(PWM_LOW);
P1=0xff;
Delay(CYCLE-PWM_LOW);
}
// P1=0xff;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--) //与逐渐变亮相反的过程
{
P1=0x00; //点亮LED
Delay(PWM_LOW);
P1=0xff; //熄灭LED
Delay(CYCLE-PWM_LOW); //主循环中添加其他需要一直工作的程序,延时长度,600次循环中从599减至1
}
/*--------第一颗LED灯呼吸---------*/
LED0=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED0=0;
Delay(PWM_LOW);
LED0=1;
Delay(CYCLE-PWM_LOW);
}
LED0=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED0=0;
Delay(PWM_LOW);
LED0=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第二颗LED灯呼吸----------*/
LED1=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED1=0;
Delay(PWM_LOW);
LED1=1;
Delay(CYCLE-PWM_LOW);
}
LED1=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED1=0;
Delay(PWM_LOW);
LED1=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第三颗LED灯呼吸----------*/
LED2=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED2=0;
Delay(PWM_LOW);
LED2=1;
Delay(CYCLE-PWM_LOW);
}
LED2=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED2=0;
Delay(PWM_LOW);
LED2=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第四颗LED灯呼吸----------*/
LED3=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED3=0;
Delay(PWM_LOW);
LED3=1;
Delay(CYCLE-PWM_LOW);
}
LED3=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED3=0;
Delay(PWM_LOW);
LED3=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第五颗LED灯呼吸----------*/
LED4=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED4=0;
Delay(PWM_LOW);
LED4=1;
Delay(CYCLE-PWM_LOW);
}
LED4=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED4=0;
Delay(PWM_LOW);
LED4=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第六颗LED灯呼吸----------*/
LED5=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED5=0;
Delay(PWM_LOW);
LED5=1;
Delay(CYCLE-PWM_LOW);
}
LED5=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED5=0;
Delay(PWM_LOW);
LED5=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第七颗LED灯呼吸----------*/
LED6=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED6=0;
Delay(PWM_LOW);
LED6=1;
Delay(CYCLE-PWM_LOW);
}
LED6=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED6=0;
Delay(PWM_LOW);
LED6=1;
Delay(CYCLE-PWM_LOW);
}
/*--------第八颗LED灯呼吸----------*/
LED7=1;
Delay(500);
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED7=0;
Delay(PWM_LOW);
LED7=1;
Delay(CYCLE-PWM_LOW);
}
LED7=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{
LED7=0;
Delay(PWM_LOW);
LED7=1;
Delay(CYCLE-PWM_LOW);
}
P1=0x00;
for(z=500;z>0;z--)
for(y=110;y>0;y--);
P1=0xff;
for(z=500;z>0;z--)
for(y=110;y>0;y--);
P1=0x00;
for(z=500;z>0;z--)
for(y=110;y>0;y--);
P1=0xff;
for(z=500;z>0;z--)
for(y=110;y>0;y--);
}
}
void Delay(unsigned int t)
{
while(--t);
}
|
-
-
p2-3.rar
28.01 KB, 下载次数: 37, 下载积分: 黑币 -5
-
-
蓝牙点灯.rar
23.28 KB, 下载次数: 51, 下载积分: 黑币 -5
|