首页 🥳 笔记

本文最后更新于 2021 年 02 月 08 日,已超过 126 天没更新!内容可能已失效,请自行测试 ~

🔴第一种方法

#include "reg52.h"
#include "intrins.h"
#define uchar unsigned char
#define uint unsigned int
#define led P0

void delay()        //延时1s
{
    uint i,j;
    for(i=0;i<1139;i++)
    for(j=0;j<100;j++);
}
void main()
{
    uchar i;
    while(1)
    {
        led = 0xfe;
        for(i=0;i<7;i++)
        {
            led = _crol_(led,1);    //流水灯依次向左移
            delay();
        }
        for(i=0;i<7;i++)
        {
            led = _cror_(led,1);    //流水灯依次向右移
            delay();
        }
    }
}

🟠第二种方法

#include "reg52.h"
#define uchar unsigned char
#define uint unsigned int
#define led P0

void delay()        //延时1s
{
    uint i,j;
    for(i=0;i<1139;i++)
    for(j=0;j<100;j++);
}
void main()
{
    uchar cnt;
    while(1)
    {
        for(cnt=0;cnt<8;cnt++)  
        {
            led = ~(0x01 << cnt);    //流水灯依次向左移
            delay();
        }
        for(cnt=0;cnt<8;cnt++)
        {
            led = ~(0x80 >> cnt);    //流水灯依次向右移
            delay();
        }
    }
}

🟡第三种方法

#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
unsigned char led_left[8]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char led_right[8]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};

void delay(u16 i)
{
    while(i--);
}

void main()
{
    u8 i,j;
    while(1)
    {
        for(i=0;i<8;i++)
        {
            P0 = led_left[i];
            delay(50000);
        }
        for(j=0;j<8;j++)
        {
            P0 = led_right[j]; 
            delay(50000);
        }
    }
}



文章评论