色婷婷AⅤ一区二区三区|亚洲精品第一国产综合亚AV|久久精品官方网视频|日本28视频香蕉

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)數(shù)碼管顯示數(shù)字為流水燈亮的個(gè)數(shù)

          單片機(jī)數(shù)碼管顯示數(shù)字為流水燈亮的個(gè)數(shù)

          作者: 時(shí)間:2016-12-02 來(lái)源:網(wǎng)絡(luò) 收藏
          本程序所用的原理圖下載:點(diǎn)這里,單片機(jī)芯片使用的stc89c52;


          /**
          *Function:數(shù)碼管顯示數(shù)字為流水燈亮的個(gè)數(shù)
          *Author: 徐冉
          *Time: 2013-07-28
          **/
          /*************基于AT89C52-RC MCU************/
          /************基于HL-1開(kāi)發(fā)板****************/

          本文引用地址:http://cafeforensic.com/article/201612/324598.htm

          #include
          typedef unsigned int uint;
          typedef unsigned char uchar;

          /*數(shù)碼管鎖存器位聲明*/
          sbit wela = P2^7;
          sbit dula = P2^6;

          /*數(shù)碼管編碼表*/
          uchar code table[] = {
          0x3F, //"0"
          0x06, //"1"
          0x5B, //"2"
          0x4F, //"3"
          0x66, //"4"
          0x6D, //"5"
          0x7D, //"6"
          0x07, //"7"
          0x7F, //"8"
          0x6F //"9"
          };

          /*全局變量定義*/
          uchar num, counter;

          /*延時(shí)子程序*/
          void delay(uint xms)
          {
          uint x, y;
          for(x = xms; x > 0; x--)
          for(y = 125; y > 0; y--);
          }

          /*定時(shí)器T0初始化程序*/
          void Time0_init()
          {
          P1 = 0xff;//關(guān)閉led
          TMOD = 0x01;//設(shè)置定時(shí)器T0工作方式0
          TH0 = 0xB8;//設(shè)定T0定時(shí)20ms
          TL0 = 0x00;
          TR0 = 1;//打開(kāi)定時(shí)器T0
          EA = 1;//開(kāi)總中斷
          ET0 = 1;//開(kāi)定時(shí)器T0中斷
          }

          /*數(shù)碼管顯示子程序*/
          void Display(uint num)
          {
          uchar shi, ge;

          shi = num / 10 % 10;
          ge = num % 10;

          dula = 1;
          P0 = table[shi];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfe;
          wela = 0;
          P0 = 0x00;
          delay(5);

          dula = 1;
          P0 = table[ge];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfd;
          wela = 0;
          P0 = 0x00;
          delay(5);
          }

          /*主程序main()*/
          void main(void)
          {
          Time0_init();
          while(1)
          {
          if(num == 0)
          {
          P1 = 0xff;//1111 1111
          }
          else if(num == 1)
          {
          P1 = 0xfe;//1111 1110
          }
          else if(num == 2)
          {
          P1 = 0xfc; //1111 1100
          }
          else if(num == 3)
          {
          P1 = 0xf8;//1111 1000
          }
          else if(num == 4)
          {
          P1 = 0xf0;//1111 0000
          }
          else if(num == 5)
          {
          P1 = 0xe0;//1110 0000
          }
          else if(num == 6)
          {
          P1 = 0xc0;//1100 0000
          }
          else if(num == 7)
          {
          P1 = 0x80;//1000 0000
          }
          else if(num == 8)
          {
          P1 = 0x00;//0000 0000
          }
          Display(num);
          }
          }

          /*定時(shí)器T0中斷服務(wù)子程序*/
          void Time0_int() interrupt 1
          {
          TH0 = 0xB8;
          TL0 = 0x00;
          counter++;
          if(counter == 50)
          {
          counter = 0;
          num++;
          if(num > 8)
          {
          num = 0;
          }
          }
          }



          評(píng)論


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

          關(guān)閉