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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)程序-點(diǎn)陣LED

          單片機(jī)程序-點(diǎn)陣LED

          作者: 時(shí)間:2016-11-30 來源:網(wǎng)絡(luò) 收藏
          /****************點(diǎn)陣LED******************/

          /**
          *功能:點(diǎn)陣LED流動(dòng)顯示5,4,3,2,1后,會(huì)一直顯示閃動(dòng)的矩形
          *作者:徐冉
          *日期:2013-06-10
          *備注:已經(jīng)通過調(diào)試
          **/
          /*****************AT89C52-RC MCU****************/
          /***********************51hei開發(fā)板**************/

          本文引用地址:http://www.ex-cimer.com/article/201611/323718.htm

          #include
          typedef unsigned int uint;//數(shù)據(jù)類型聲明優(yōu)于#define
          typedef unsigned char uchar;
          sbit max7219_din = P2^0;//MAX7219串行數(shù)據(jù)輸入端
          sbit max7219_cs = P2^1; //MAX7219片選端
          sbit max7219_clk = P2^2;//MAX7219時(shí)鐘端
          //顯示取模編碼表
          uchar code dis[11][8] = {
          {0x3C,0x20,0x20,0x3C,0x4,0x4,0x3C,0x0},//5
          {0x8,0x18,0x28,0x48,0xFE,0x8,0x8,0x8},//4
          {0x3E,0x2,0x2,0x3E,0x2,0x2,0x3E,0x0},//3
          {0x7E,0x2,0x2,0x7E,0x40,0x40,0x40,0x7E},//2
          {0x10,0x18,0x14,0x10,0x10,0x10,0x10,0x10},//1
          {0xff,0x81,0x81,0x81,0x81,0x81,0x81,0xff},
          {0,0x7e,0x42,0x42,0x42,0x42,0x7e,0},
          {0,0,0x3c,0x24,0x24,0x3c,0,0},
          {0,0,0,0x18,0x18,0,0,0,},
          {0,0,0,0,0,0,0,0}
          };
          //毫秒延時(shí)程序
          void delay(uint xms)
          {
          uint x, y;
          for(x = 0; x < xms; x++)
          for(y = 0; y < 110; y++);
          }
          //寫MAX7219字節(jié)數(shù)據(jù)
          void write_byte_max7219(uchar dat)
          {
          uchar i;
          max7219_cs = 0;//選通max7219
          for(i = 0; i < 8; i++)
          {
          max7219_clk = 0;
          max7219_din = dat & 0x80;
          dat <<= 1;
          max7219_clk = 1;
          }
          }
          //寫數(shù)據(jù)到MAX7219
          void write_max7219(uchar address, uchar dat)
          {
          max7219_cs = 0;
          write_byte_max7219(address);
          write_byte_max7219(dat);
          max7219_cs = 1;
          }
          //MAX7219初始化
          void max7219_init()
          {
          //譯碼模式
          write_max7219(0x09, 0x00);
          //亮度模式
          write_max7219(0x0a, 0x06);//亮度為13/32
          //設(shè)置掉電模式
          write_max7219(0x0c, 0x01);
          //掃描模式0~7
          write_max7219(0x0b, 0x07);
          //顯示檢測(cè)
          write_max7219(0x0f, 0x00);
          }
          //主程序
          void main(void)
          {
          uchar i = 0, j = 0;
          delay(50);
          max7219_init();
          while(1)
          {
          //流動(dòng)顯示數(shù)字
          for(i = 0; i < 5; i++)
          {
          for(j = 0; j < 8; j++)
          { //此處的數(shù)據(jù)必須從0x01開始寫,否則寫不成功;
          write_max7219(j+1, dis[j]);
          }
          delay(500);
          }
          //矩形閃動(dòng)
          while(1)
          {
          for(i = 5; i < 10; i++)
          {
          for(j = 0; j < 8; j++)
          { //此處的數(shù)據(jù)必須從0x01開始寫,否則寫不成功;
          write_max7219(j+1, dis[j]);
          }
          delay(100);
          }
          }
          }
          }



          評(píng)論


          技術(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); })();