单片机流水灯。号称花样灯

 #include<reg52.h>
void Delay(unsigned int n);
void shine_1();
void shine_2();
void shine_3();
void shine_4();
void fun1();


 void main()
 {
fun1();
 }


 void Delay(unsigned int n)
{
unsigned int i,j;
for(i = n;i > 0;i--)
{
   for(j = n/2;j > 0; j--)
{}
}
}


void fun1()
{

P1 = 0xfe;
Delay(200);
P1 = 0xfd;
Delay(200);
P1 = 0xfb;
Delay(200);
P1 = 0xf7;
Delay(200);


while(1)
{
shine_1();
shine_2();
shine_3();
shine_4();

P1 = 0x3d;
Delay(200);
P1 = 0x7b;
Delay(200);
P1 = 0xf7;
Delay(200);
}
}


void shine_1()
{
    unsigned char tmp;
unsigned int i;
tmp =0x10;
for(i = 0;i < 13;i++)
{
      P1 = ~tmp;
  Delay(200);
  tmp <<= 1;
  if(tmp == 0)
  {
      tmp = 0x01;
  }
}
}


void shine_2()
{
    unsigned char temp;
unsigned int i;
  temp = 0x03;
P1 = 0xfe;
  for(i = 0;i < 17;i++)
{
   
    
if(temp == 0x80)
{
    temp = 0x81;
}else if(temp == 0x02)
{
    temp = 0x03;
}
P1 = ~temp;
    temp <<= 1;
Delay(200);
}


}


void shine_3()
{
    unsigned char temp;
unsigned int i;
  temp = 0x07;
//P1 = 0xfe;
//Delay(200);
P1 = 0xfc;
  for(i = 0;i < 16;i++)
{
   
    Delay(200);
if(temp == 0xc0)
{
    temp = 0xc1;
}else if(temp == 0x82)
{
    temp = 0x83;
}
else if(temp == 0x06)
{
    temp = 0x07;
}
P1 = ~temp;
    temp <<= 1;
 
}
}
void shine_4()
{
    unsigned char temp;
unsigned int i;
  temp = 0x0f;
P1 = 0xfc;
Delay(200);
P1 = 0xf8;
  for(i = 0;i < 16;i++)
{
   
    Delay(200);
if(temp == 0xe0)
{
    temp = 0xe1;
}else if(temp == 0xc2)
{
    temp = 0xc3;
}
else if(temp == 0x86)
{
    temp = 0x87;
}
else if(temp == 0x0e)
{
    temp = 0x0f;
}
P1 = ~temp;
    temp <<= 1;
 
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值