51單片機 數位管的顯示與解碼器

來源:互聯網
上載者:User

標籤:

共陽極數組0~9:display[]={0xC0,0xF9,0xA4,0xB0,0x91,0xA2,0x82,0xF8,0x80,0x90}

共陽極數組A~F:display[]={0x88,0x83,0xA6,0xC1,0x86,0x8E}

 

共陰極數組0~9:display[]={0x3F,0x06,0x5B,0x4F,0x6E,0x6D,0x7D,0x07,0x7F,0x6F}

共陰極數組A~F:display[]={0x77,0x7C,0x59,0x3E,0x79,0x71}

 

共陰、兩組四位一體數位管,位選接74LS138解碼器,輸入(位選)CBA接P20,P21,P22。段選通過74573後接P1口。

若不使用解碼器,可直接將位選段接IO口,賦值改變。

 1 /******************************************************************************* 2 * 實 驗 名         : 動態數位管顯示 3 * 實驗說明         : 8位元碼管依次顯示0~7 4 * 作    者         : L2 5 * 時    間         : 2016-08-02 6  7 *******************************************************************************/ 8 #include<reg51.h> 9 10 #define GPIO_DIG P1         //Digitron  數位管11 sbit LSA= P2^0;12 sbit LSB= P2^1;13 sbit LSC= P2^2;14 15 unsigned char code DIG_CODE[10]={16 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};  //0~9的顯示碼17 void DigDisplay();18 19 void main(void)20 {21     while(1)22         DigDisplay();                23 }24 25 26 void DigDisplay()27 {28     unsigned char i;29     unsigned int j;30     for(i=0;i<8;i++)31     {32         switch(i)     //位選,選擇點亮的數位管,33         {34             case(0):35                 LSA=0;LSB=0;LSC=0; break;//顯示第0位36             case(1):37                 LSA=1;LSB=0;LSC=0; break;//顯示第1位38             case(2):39                 LSA=0;LSB=1;LSC=0; break;//顯示第2位40             case(3):41                 LSA=1;LSB=1;LSC=0; break;//顯示第3位42             case(4):43                 LSA=0;LSB=0;LSC=1; break;//顯示第4位44             case(5):45                 LSA=1;LSB=0;LSC=1; break;//顯示第5位46             case(6):47                 LSA=0;LSB=1;LSC=1; break;//顯示第6位48             case(7):49                 LSA=1;LSB=1;LSC=1; break;//顯示第7位    50         }51         GPIO_DIG=DIG_CODE[i];//發送段碼52         j=10000;                         //掃描間隔時間設定,若減少j,可觀察到穩定顯示的0~7 (掃描速度太快,人眼識別不了)53         while(j--);    54         GPIO_DIG=0x00;//消隱55     }56 }

 

 

 

 1 /******************************************************************************* 2 * 實 驗 名         : 數位管秒錶顯示 3 * 實驗說明         : 0~59依次顯示 4 * 作    者         : L2 5 * 時    間         : 2016-08-03 6  7 *******************************************************************************/ 8 #include<reg51.h> 9 10 #define GPIO_DIG P1         //Digitron  數位管11 #define uchar unsigned char12 #define uint unsigned int13 sbit LSA= P2^0;14 sbit LSB= P2^1;15 sbit LSC= P2^2;16 17 uchar shi,ge,num1=0,num=0;18 uchar code DIG_CODE[10]={19 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};  //0~9的顯示碼20 void Delay5ms();21 void DigDisplay(uchar shi,uchar ge);22 23 24 void main()25 {                                                //200微秒@20MHz26     TMOD = 0x01;        //設定定時器模式27     TL0 = 0xA8;        //設定定時初值28     TH0 = 0xFD;    //設定定時初值29     EA = 1;         // 開總中斷30     TF0 = 0;        //清除TF0標誌31     ET0 = 1;        // 開定時器0中斷32     TR0 = 1;        //定時器0開始計時33     while(1)34     {35         DigDisplay(shi,ge);36     }37 }38 39 void DigDisplay(uchar shi,uchar ge)40 {41     GPIO_DIG=DIG_CODE[shi];        //段選42     LSA=0;LSB=0;LSC=0; 43     Delay5ms();44     GPIO_DIG=DIG_CODE[ge];     45     LSA=1;LSB=0;LSC=0;46     Delay5ms();   47 }48 49 void Timer0Init(void) interrupt 150 {51     TL0 = 0xA8;        //重裝初52     TH0 = 0xFD;53     num1++;54     if(num1==200)         //5次200ms即為1s到55     {56          num1=0;57          num++;58          if(num==60)59              num=0;60          shi=num/10;61          ge = num%10;62     }    63 }64 65 66 void Delay5ms()        //@12.000MHz67 {68     unsigned char i, j;69 70     i = 59;71     j = 90;72     do73     {74         while (--j);75     } while (--i);76 }

 

51單片機 數位管的顯示與解碼器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.