【蓝桥杯】一个流水灯左右移动代码


#include<stc15f2k60s2.h>

void delayms(int ms);

unsigned char num;

void main()
{
    P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;   //初始化LED,关闭数码管,关闭继电器蜂鸣器

    while(1)
    {
        for(num=0;num<8;num++)
        {
            P0=~(0x01<<num);//左移 0000 0001 --1111 1110>   0000 0001 -- 0000 0010 --- 1111 1101 
                      //P0=~(0x80>>num);//右移
            delayms(1000);
        }
    }
}

void delayms(int ms)
{
    int i,j;
    for(i=0;i<ms;i++)
        for(j=845;j>0;j--);
}

猜你喜欢

转载自blog.csdn.net/g1fdgfgdf2_/article/details/79967555