发一个关于10个流水灯的呼吸灯程序
晶振11.0592Mhz,用Keil编译的
#include<reg51.h>
/*-------------------------IO口定义----------------------------*/
sbit LED0=P0^0;
sbit LED1=P0^1;
sbit LED2=P0^2;
sbit LED3=P0^3;
sbit LED4=P0^4;
sbit LED5=P0^5;
sbit LED6=P0^6;
sbit LED7=P0^7;
sbit LED8=P2^0;
sbit LED9=P2^1;
//延时
void delay(unsigned int t)
{
while(--t);
}
//主函数
void main (void)
{
unsigned int CYCLE=250,PWM_LOW=0;
while (1)
{
// LED0
for(PWM_LOW=1WM_LOW<CYCLEWM_LOW++)
{
LED0=0;
delay(PWM_LOW);
LED0=1;
delay(CYCLE-PWM_LOW);
}
//与逐渐变亮相反的过程
LED0=0;
for(PWM_LOW=CYCLE-1WM_LOW>0WM_LOW--)
{//与逐渐变亮相反的过程
LED0=0;
delay(PWM_LOW);
LED0=1;
delay(CYCLE-PWM_LOW);
}
//LED1
LED1=1;
delay(1000); //可以看到熄灭的过程
for(PWM_LOW=1WM_LOW<CYCLEWM_LOW++)
{
LED1=0;
delay(PWM_LOW);
LED1=1;
delay(CYCLE-PWM_LOW);
}
//与逐渐变亮相反的过程
LED1=0;
for(PWM_LOW=CYCLE-1WM_LOW>0WM_LOW--)
{//与逐渐变亮相反的过程
LED1=0;
delay(PWM_LOW);
LED1=1;
delay(CYCLE-PWM_LOW);
}
// LED2
LED2=1;
delay(1000); //可以看到熄灭的过程
for(PWM_LOW=1WM_LOW<CYCLEWM_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);
}
// LED3
LED3=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED4
LED4=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED5
LED5=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED6
LED6=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED7
LED7=1;
delay(1000); //可以看到熄灭的过程
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);
}
//LED8
LED8=1;
delay(1000); //可以看到熄灭的过程
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED8=0;
delay(PWM_LOW);
LED8=1;
delay(CYCLE-PWM_LOW);
}
//与逐渐变亮相反的过程
LED8=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{//与逐渐变亮相反的过程
LED8=0;
delay(PWM_LOW);
LED8=1;
delay(CYCLE-PWM_LOW);
}
// LED9
LED9=1;
delay(1000); //可以看到熄灭的过程
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED9=0;
delay(PWM_LOW);
LED9=1;
delay(CYCLE-PWM_LOW);
}
//与逐渐变亮相反的过程
LED9=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{//与逐渐变亮相反的过程
LED9=0;
delay(PWM_LOW);
LED9=1;
delay(CYCLE-PWM_LOW);
}
//LED8
LED8=1;
delay(1000); //可以看到熄灭的过程
for(PWM_LOW=1;PWM_LOW<CYCLE;PWM_LOW++)
{
LED8=0;
delay(PWM_LOW);
LED8=1;
delay(CYCLE-PWM_LOW);
}
//与逐渐变亮相反的过程
LED8=0;
for(PWM_LOW=CYCLE-1;PWM_LOW>0;PWM_LOW--)
{//与逐渐变亮相反的过程
LED8=0;
delay(PWM_LOW);
LED8=1;
delay(CYCLE-PWM_LOW);
}
// LED7
LED7=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED6
LED6=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED5
LED5=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED4
LED4=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED3
LED3=1;
delay(1000); //可以看到熄灭的过程
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);
}
// LED2
LED2=1;
delay(1000); //可以看到熄灭的过程
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);
}
//LED1
LED1=1;
delay(1000); //可以看到熄灭的过程
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);
}
//LED0
LED0=1;
delay(1000); //可以看到熄灭的过程
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);
}
}
}
|