<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 51單片機:數(shù)碼管c代碼集合

          51單片機:數(shù)碼管c代碼集合

          作者: 時間:2012-08-16 來源:網(wǎng)絡(luò) 收藏

          點擊瀏覽下一頁

          /*
          點亮第一個,因為板子是自已做的,到電子城買時說好要共陰的,拿來測時才發(fā)現(xiàn)是共陽的。
          */
          //------------------------------------------------------------
          /*
          #include reg52.h>
          #define uchar unsigned char
          sbit duan=P2^5 ; //注意,有分號
          sbit wei=P2^6; //注意,有分號+P是大寫的,若你寫成小寫的則會提示說找不到

          const unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,

          0xC6,0xA1,0x86,0x8E}; //共陽極數(shù)組,請注意,我使用的共陽極的數(shù)碼管,如果你是用買的現(xiàn)成板,一般是使用共陰極的
          void main()
          {
          duan=1;
          P0=table[1];
          duan=0;
          wei=1;
          P0=0x01;
          wei=0;
          while(1);
          }
          */
          //-----------------------------------------------------------------
          /*
          //靜態(tài)顯示,第一個數(shù)碼管顯示1
          #include reg52.h>
          sbit duan=P2^5;
          sbit wei=P2^6;

          void main()
          {
          duan=1;
          P0=0xF9; //共陽極數(shù)碼管 顯示1的編碼值是F9,如果你是買的開發(fā)板(共陰的數(shù)碼管)則為0x06;
          duan=0;
          wei=1;
          P0=0x01; //選中第1個數(shù)碼管
          wei=0;
          while(1); //一直顯示,以便我們觀察

          }
          */
          //-----------------------------------------------------------------
          /*
          //靜態(tài)顯示,全為1
          #include reg52.h>
          sbit duan=P2^5;
          sbit wei=P2^6;

          void main()
          {
          duan=1;
          P0=0xF9; //共陽極數(shù)碼管 顯示1的編碼值是F9,如果你是買的開發(fā)板(共陰的數(shù)碼管)則為0x06;
          duan=0;
          wei=1;
          P0=0xff; //選中所有的數(shù)碼管
          wei=0;
          while(1); //一直顯示,以便我們觀察

          }
          */
          //-----------------------------------------------------------------
          //靜態(tài)顯示:從0到F (所有的數(shù)碼管)
          #include reg52.h>
          #define uchar unsigned char
          sbit duan=P2^5 ; //注意,有分號+P是大寫的,若你寫成小寫的則會提示說找不到
          sbit wei=P2^6;
          const unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,

          0xC6,0xA1,0x86,0x8E}; //數(shù)碼管數(shù)組
          void delay(int x)
          {
          int a,b;
          for(a=x;a>0;a--)
          for(b=110;b>0;b--);
          }

          void main()
          {
          while(1)
          {
          uchar n=0;
          for(n=0;n=9;n++)
          {

          duan=1;
          P0=table[n];
          duan=0;
          wei=1;
          P0=0xff; //因為我的是共陽的,其數(shù)碼管選中得高電平,如果你是共低的則為0x
          wei=0;
          delay(600); //一定要加延時否則看起來亂碼實際上是閃爍太快了有余光
          }

          }

          }

          //-----------------------------------------------------------------

          /*
          數(shù)碼管從0開始到9變化,同時LED燈正流+倒流.
          */
          #includereg52.h>
          #include intrins.h> //LED燈用到移動關(guān)鍵字crol,調(diào)用此關(guān)鍵字
          #define uchar unsigned char
          const unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,

          0xC6,0xA1,0x86,0x8E}; //數(shù)碼管數(shù)組
          sbit wei=P2^6;
          sbit duan=P2^5;
          void delay(uchar x)
          {
          uchar a,b;
          for(a=x;a>0;a--)
          for(b=110;b>0;b--);
          }

          void LED()
          {
          uchar a,temp;
          temp=0xfe;
          for (a=8;a>0;a--) //循環(huán)8次,即流水燈8個循環(huán)8次即可點亮8個
          {
          P1=temp;
          temp=_crol_(temp,1); //移動
          delay(200);
          }
          delay(5);
          temp=0x7f;
          for (a=8;a>0;a--) //循環(huán)8次,即流水燈8個循環(huán)8次即可點亮8個
          {
          P1=temp;
          temp=_crol_(temp,-1); //移動
          delay(170);
          }
          }

          void scan()
          {
          uchar n=0;
          for(n=0;n=9;n++)
          {
          duan=1;
          P0=table[n];
          duan=0;
          wei=1;
          P0=0xff;
          wei=0;
          delay(1000);
          LED();
          }
          if(n==9){delay(100000);}

          }


          void main()
          {
          while(1)
          {
          // LED();
          scan();
          }
          }



          關(guān)鍵詞: 51單片機 數(shù)碼管 c代碼

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();