单片机 花样灯

//杨玉祥  2018/7/20  花样灯

#include <reg51.h>

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);
        }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值