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

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 兩片74HC595級(jí)聯(lián)動(dòng)態(tài)驅(qū)動(dòng)8位數(shù)碼管 51單片機(jī)

          兩片74HC595級(jí)聯(lián)動(dòng)態(tài)驅(qū)動(dòng)8位數(shù)碼管 51單片機(jī)

          作者: 時(shí)間:2016-11-25 來源:網(wǎng)絡(luò) 收藏
          功能 : 用2片74HC595驅(qū)動(dòng)8位數(shù)碼管, 級(jí)聯(lián)的最低1片595控制位選,那么第一片控制段選

          時(shí)間 : 2013-3-28 21:11:59
          作者 : Stone
          版本 : REV1
          平臺(tái) : STC89C52 11.0592MHz
          現(xiàn)象 : 8位數(shù)碼管從第一位開始從0計(jì)數(shù),滿10進(jìn)位
          版本說明 : 第0版本沒有使用定時(shí)器中斷,同時(shí)定義了一個(gè) unsigned long int 變量計(jì)數(shù)
          再把這個(gè)數(shù)的每位分離出來顯示,所以導(dǎo)致有點(diǎn)閃屏,此版本使用定時(shí)器中斷,
          而且沒有用 unsigned long int 之類的變量,而是用數(shù)組 Val[8] 來計(jì)數(shù),
          主函數(shù)只負(fù)責(zé)顯示,其它的在中斷函數(shù)里面處理,這樣顯示一點(diǎn)都不閃屏,
          備注 : 可以用 ULN2003A 接在數(shù)碼管的 com 口來提高驅(qū)動(dòng)能力,ULN2003A里面有7個(gè)NPN三極管,
          可以大大提高驅(qū)動(dòng)能力

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


          #include


          sbit SCK = P1^1; // 數(shù)據(jù)輸入時(shí)鐘線,脈沖
          sbit SI = P1^0; // 數(shù)據(jù)線
          sbit RCK = P1^2; // 鎖存

          unsigned char code SMG[10] = {0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90}; // 段碼
          unsigned char code Wei[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; // 位選
          unsigned char Val[8] = {0}; // 要顯示的數(shù)據(jù)


          ************************ 函數(shù)聲明 ************************
          void interrupt_init(void);
          void timer_init(void);

          控制74HC595輸出數(shù)據(jù)
          void Output(void)
          {
          RCK = 0;
          RCK = 1;
          }

          向74HC595中寫入一字節(jié)數(shù)據(jù)
          void Write_Byte(unsigned char dat)
          {
          unsigned char i = 0;

          for(i=0; i<8; i++)
          {
          SCK = 0;
          SI = dat & 0x80;
          SCK = 1;

          dat <<= 1;
          }
          }

          顯示函數(shù)

          void Display(unsigned char * p)
          {
          unsigned char * pt = Wei;

          Write_Byte(*(pt+0));
          Write_Byte(SMG[*(p+7)]);
          Output();

          Write_Byte(*(pt+1));
          Write_Byte(SMG[*(p+6)]);
          Output();

          Write_Byte(*(pt+2));
          Write_Byte(SMG[*(p+5)]);
          Output();

          Write_Byte(*(pt+3));
          Write_Byte(SMG[*(p+4)]);
          Output();

          Write_Byte(*(pt+4));
          Write_Byte(SMG[*(p+3)]);
          Output();

          Write_Byte(*(pt+5));
          Write_Byte(SMG[*(p+2)]);
          Output();

          Write_Byte(*(pt+6));
          Write_Byte(SMG[*(p+1)]);
          Output();

          Write_Byte(*(pt+7));
          Write_Byte(SMG[*(p+0)]);
          Output();

          }

          int main(void)
          {
          timer_init();
          interrupt_init();

          while(1)
          {
          Display(Val);
          }

          return 0;
          }

          void interrupt_init(void)
          {
          EA = 1;//開總中斷
          ET0 = 1;//開定時(shí)器0中斷
          ET1 = 1;//開定時(shí)器1中斷
          }

          void timer_init(void)
          {
          TMOD = TMOD | 0x01;//定時(shí)器0工作方式1
          TMOD = TMOD & 0xFD;

          TH0 = 0x4B;//裝初值,50ms計(jì)數(shù)
          TL0 = 0xFF;

          TR0 = 1;//開啟定時(shí)器0
          }

          void timer0() interrupt 1
          {
          static unsigned char counter0 = 0;
          counter0++;
          TH0 = 0x4B;//重新裝入初值,定時(shí)器0從頭開始計(jì)數(shù),計(jì)數(shù)50ms
          TL0 = 0xFF;

          if(2 == counter0)//2*50 ms = 100ms = 0.1s
          {
          counter0 = 0;//counter0置零,定時(shí)器0從頭開始計(jì)數(shù)

          Val[0]++;
          if(10==Val[0])
          {
          Val[0] = 0;
          Val[1]++;

          if(10==Val[1])
          {
          Val[1] = 0;
          Val[2]++;

          if(10==Val[2])
          {
          Val[2] = 0;
          Val[3]++;

          if(10==Val[3])
          {
          Val[3] = 0;
          Val[4]++;

          if(10==Val[4])
          {
          Val[4] = 0;
          Val[5]++;

          if(10==Val[5])
          {
          Val[5] = 0;
          Val[6]++;

          if(10==Val[6])
          {
          Val[6] = 0;
          Val[7]++;

          if(10==Val[7])
          {
          Val[7] = 0;
          }
          }
          }
          }
          }
          }
          }
          }
          }
          }



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