欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2229|回復: 0
收起左側

51單片機流水燈多種方法實現

[復制鏈接]
ID:524018 發表于 2019-4-28 22:27 | 顯示全部樓層 |閱讀模式


原代碼:


#include<reg52.h>
#include<intrins.h>//字符循環移動函數庫
void delays()//延遲
{        
        int x,y;
           for(x=0;x<110;++x)        
        for(y=0;y<1000;++y);
}
         
void delayms(unsigned int xms)//x ms延遲
{
          unsigned int c,h;
          for(c = 0; c<xms; ++c)
        for(h = 0; h<110; ++h);
}


void main()
{        
        //從左到右,再從右到左的流水燈
        unsigned char j;
        unsigned char k;
        unsigned char temp;
        int i=0;
        P2 = 0xff;
        delays();
        temp=0x7f;


        for(k=0;k<7;k++)
        {        
                P2=temp;
                 delays();
                 temp=_cror_(temp,1);        //字符循環右移實現右移        
        }


        for(j=0;j<8;j++)
        {
                P2=temp;
                 delays();
                 temp=_crol_(temp,1);        //字符循環左移實現左移        
        }
        
        /*另外一種思路,用移位運算符實現
        unsigned char a,i;
        a=0xfe;
        for(i=0;i<7;i++)
        {
                P2=a;
                delays();
                a=a<<1;//1移動,其他補零
                a=a|0x01;//左移一位后與0x01相或(只要滿足一個條件)        0000 0001
                // //或a=a|0x00;逐個點亮
        }
        a=0x7f;
        for(i=0;i<7;i++)
        {
                P2=a;
                delays();
                a=a>>1;//1移動,其他補零
                a=a|0x80;//右移一位后與0x80相或(只要滿足一個條件)        1000 0000
                // //或a=a|0x00;逐個點亮
        }*/


        /*用數組實現從兩側到中間,再從中間到兩側流水燈
        int e;
        int i=0;
        unsigned char d[]={0x7e,0xbd,0xdb,0xe7};//定義亮燈熄燈數組


        for(e=0;e<3;e++)                         //兩側到中間
        {        
                P2=d[e];
                delays();
        }


        for(e=3;e>=0;e--)                         //中間到兩側
        {
                P2=d[e];
                delays();
        }*/
}

新手上路,請多指教,謝謝!





評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表