//杨玉祥 2018/7/20 花样灯
#include
void sleepUs(unsigned int t);
void sleepMs(unsigned int t);
void main()
{
char i,w,j,n;
unsigned char table[] = {0xe7,0xdb,0xbd,0x7e,0x7e,0xbd,0xdb,0xe7};
unsigned char table1[]= {0x81,0xc3,0xe7,0xe7,0xc3,0x81};
for(i=3;i>0;i--) //循环流水灯,逐渐加速
{
P1 = j = 0xfe;
sleepMs(50*i);
for(w=0;w<8;w++)
{
j <<= 1;
j = j|0x01;
P1 = j;
sleepMs(50*i);
}
P1 = j = 0x7f;
sleepMs(50*i);
for(w=0;w<8;w++)
{
j >>= 1;
j = j|0x80;
P1 = j;
sleepMs(50*i);
}
}
for(j=0;j<2;j++)
{
for(i=0;i<8;i++) //中间往两边跑,然后再跑回来
{
P1 = table[i];
sleepMs(50);
}
for(w=0;w<3;w++) //八个灯同时闪烁
{
P1 = 0x00;
sleepMs(50);
P1 = 0xff;
sleepMs(50);
}
for(n=0;n<6;n++) //偶数灯逐个闪亮
{
P1 = table1[n];
sleepMs(100);
}
}
while(1)
{
for(w=0;w<3;w++) //八个灯同时闪烁
{
P1 = 0x00;
sleepMs(50);
P1 = 0xff;
sleepMs(50);
}
}
}
void sleepUs(unsigned int t)
{
while(--t);
}
void sleepMs(unsigned int t)
{
while(t--)
{
sleepUs(245);
sleepUs(245);
}
}