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

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 單片機驅動矩陣按鍵與獨立按鍵源代碼

          單片機驅動矩陣按鍵與獨立按鍵源代碼

          作者: 時間:2016-12-02 來源:網絡 收藏
          本程序所用的原理圖下載:點這里,單片機芯片使用的stc89c52;找到相應部分即可.這是一整個單片機開發(fā)板的電路圖其他的忽略.

          hex文件及其工程文件下載:http://www.51hei.com/f/pingfc.rar 下面是程序源碼:

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

          /*
          *功能:使用矩陣按鍵使得按鍵按下時數碼管上顯示各自對應的數字的立方數
          * 優(yōu)化顯示,只顯示有效位;
          * 且使用獨立按鍵實現(xiàn)key1清零,key2加數,key3減數;
          *日期:2013-05-07-10:20
          *作者:徐冉
          *特別說明:本程序代碼已經通過調試,僅供學習使用;
          *
          */
          /***********AT89C52-RC單片機-51hei實驗板***********/
          /*****************51hei開發(fā)板*********************/


          #include
          typedef unsigned int uint;
          typedef unsigned char uchar;
          sbit wela = P2^7;
          sbit dula = P2^6;
          sbit key1 = P3^4;
          sbit key2 = P3^5;
          sbit key3 = P3^6;
          sbit fm = P2^3;
          uint temp;
          uchar code table[] = {
          0x3F, //"0"
          0x06, //"1"
          0x5B, //"2"
          0x4F, //"3"
          0x66, //"4"
          0x6D, //"5"
          0x7D, //"6"
          0x07, //"7"
          0x7F, //"8"
          0x6F, //"9"
          0x77, //"A"
          0x7C, //"B"
          0x39, //"C"
          0x5E, //"D"
          0x79, //"E"
          0x71, //"F"
          0x76, //"H"
          0x38, //"L"
          0x37, //"n"
          0x3E, //"u"
          0x73, //"P"
          0x5C, //"o"
          0x40, //"-"
          0x00, //熄滅
          0x00 //自定義
          };
          // uchar key; Error!!! 此時的key值大于258 超出了uchar 故錯誤!!
          uint key;
          void display(num);
          void delay(uint xms);
          void max_kanscan();
          void keyscan();
          void main(void)
          {
          while(1)
          {
          keyscan();
          max_kanscan();
          display(key);
          }
          }


          void display(num)
          {
          uchar qian, bai, shi, ge;
          qian = num / 1000 % 10;
          bai = num / 100 % 10;
          shi = num / 10 % 10;
          ge = num % 10;

          if(num < 10)
          {
          dula = 1;
          P0 =table[ge];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfe;
          wela = 0;
          }
          else if(num < 100)
          {
          dula = 1;
          P0 =table[shi];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfe;
          wela = 0;
          P0 = 0x00;
          delay(1);


          dula = 1;
          P0 =table[ge];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfd;
          wela = 0;
          P0 = 0x00;
          delay(1);
          }
          else if(num < 1000)
          {
          dula = 1;
          P0 =table[bai];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfe;
          wela = 0;
          P0 = 0x00;
          delay(1);


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


          dula = 1;
          P0 =table[ge];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfb;
          wela = 0;
          P0 = 0x00;
          delay(1);
          }
          else if(num < 10000)
          {
          dula = 1;
          P0 =table[qian];
          dula = 0;
          P0 = 0xff;
          wela = 1;
          P0 = 0xfe;
          wela = 0;
          P0 = 0x00;
          delay(1);


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


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


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

          }


          上一頁 1 2 下一頁

          評論


          技術專區(qū)

          關閉