嵌入式 > 技术百科 > 详情

8个花样流水灯c程序

发布时间:2020-10-10 发布时间:
|
#include
#define uchar unsigned char
#define uint unsigned int
void delay(uint t)//延时函数
 {
  uint x,y;
  for(x=t;x>0;x--)
   for(y=110;y>0;y--);
 }
void main()//主函数
 {
  uchar temp,i;
  while(1)
  {
   temp=0x01; //8盏灯单个亮向左移
   for(i=0;i<8;i++)
     {
      P2=~temp;
      delay(50);
      temp<<=1;
     }
   temp=0x80;
   for(i=0;i<8;i++)//8盏灯单个亮反向右移
     {
      P2=~temp;
      delay(50);
      temp>>=1;
      }
   temp=0xfe;     
   for(i=0;i<8;i++)//8盏灯逐个向右亮
     {
      P2=temp;
      delay(50);
      temp<<=1;
     }
   temp=0xfe;  
   for(i=0;i<8;i++)//8盏灯逐个灭向右
     {
      P2=~temp;
      delay(50);
      temp<<=1;
     }
   temp=0x7f;  
   for(i=0;i<8;i++)//8盏灯逐个亮向左
     {
      P2=temp;
      delay(50);
      temp>>=1;
     }
   temp=0x7f;  
   for(i=0;i<8;i++)//8盏灯逐个灭向右
     {
      P2=~temp;
      delay(50);
      temp>>=1;
     }
    delay(100);
    P2=0x55;//隔一个亮
    delay(100);
    P2=0xaa;//隔一个亮
    delay(100);
    P2=0x00;//全亮
    delay(100);
    P2=0xff;//全灭
  }
 }
 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
用于MAX7456随屏显示器SPI