如何用两个键控制流水灯的花样和速度(求大侠帮忙)

2019-03-24 19:23发布

这是我找到的流水灯花样程序,现在希望用两个键,一个键控制流水灯的延时时间,另外一个控制流水灯的花样变换。求大侠帮忙,不胜感激啊!  #include<reg51.h>   #define uchar unsigned char #define uint unsigned int void Delayms(uint x) { uint i,j;
for(i=x;i>0;i--)
   for(j=110;j>0;j--);
}
void main(){ uchar i,j;
while(1)
   {    j=0x01;    //8个流水灯逐个闪动
   for(i=0;i<8;i++)
   {
    P1=~j;
    Delayms(300);
   j<<=1;
   }
 j=0x80;   //8个流水灯反向逐个闪动
   for(i=0;i<8;i++)
   {
    P1=~j;
    Delayms(300);
    j>>=1;
   }
  j=0xfe;    //8个流水灯依次全部点亮
   for(i=0;i<8;i++)
   {
    P1=j;
    Delayms(300);
  j<<=1;
   }
   j=0x7f; //8个流水灯依次反向全部点亮
   for(i=0;i<8;i++)
   {
    P1=j;
    Delayms(300);
   j>>=1;
   }    j=0xff;    //8个流水灯全亮/灭闪4次
   for(i=0;i<8;i++)
   {  P1=j;
 
   Delayms(300);
  j=~j;     }
  P1=0x01; //先奇数亮再偶数亮
  Delayms(500);
  P1=0xFB;
   Delayms(500);
  P1=0xEF;
   Delayms(500);
  P1=0xBF;
  Delayms(500);
  P1=0xFD;
  Delayms(500);
  P1=0xF7;
  Delayms(500);
  P1=0xDF;
   Delayms(500);
  P1=0x7F;
  Delayms(500) ;
  P1=0xFF;
  Delayms(500) ;
  P1=0xff;
  Delayms(500) ;
  Delayms(500) ;
   P1=0xe7;//从中间往两边亮,循环3次
   Delayms(500) ;
   P1=0xdb;
    Delayms(500);
   P1=0xbd;
   Delayms(500) ;
    P1=0x7e;
   Delayms(500);
    P1=0xff;
  Delayms(500) ;
  Delayms(500) ;
    P1=0xe7;
   Delayms(500) ;
   P1=0xdb;
    Delayms(500);
   P1=0xbd;
   Delayms(500) ;
    P1=0x7e;
   Delayms(500);
 P1=0xff;
  Delayms(500) ;
  Delayms(500) ;
    P1=0xe7;
   Delayms(500) ;
   P1=0xdb;
    Delayms(500);
   P1=0xbd;
   Delayms(500) ;
    P1=0x7e;
   Delayms(500);
   
}
}
此帖出自小平头技术问答
0条回答

一周热门 更多>