欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 單片機數碼管顯示(兩位學號)程序 [打印本頁]

作者: 希索加    時間: 2020-10-27 00:17
標題: 單片機數碼管顯示(兩位學號)程序
實現功能:數碼管可以顯示0-99兩位數字,用三個按鍵分別表示加、減、復位。
按一下加按鍵,數字加1;按一下減按鍵,數字減1。初始化顯示為學號后兩位。
Proteus仿真電路圖如下:


單片機源程序如下:
  1. #include<reg51.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int
  4. uchar code seg[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};//共陽極數碼管編碼
  5. sbit up=P2^2;      //加1按鍵
  6. sbit down=P2^3;    //減1按鍵
  7. sbit clear=P2^4;  //初始化按鍵,學號后兩位08  
  8. sbit shiwei=P2^0;   //數碼管十位位選
  9. sbit gewei=P2^1;   //數碼管個位位選
  10. char ge=0;                   //定義個位初始值
  11. char shi=0;                   //定義十位初始值
  12. char shuzi=8;     //定義初始化值
  13. void delay(uint);//延時函數
  14. void display();//數碼管顯示函數
  15. void main()
  16. {
  17.         while(1)
  18.           {
  19.                  if(up==0)//加1按鍵按下檢測
  20.                   {
  21.                          delay(10);//消抖
  22.                           if(up==0)
  23.                           {
  24.                             shuzi++;
  25.                                 if(shuzi==100)//加到99變回0
  26.                                 shuzi=0;
  27.                           }
  28.                           while(up==0)//松手檢測出后顯示數字
  29.                         {
  30.                                   display();
  31.                         }
  32.                   }
  33.        
  34.                 if(down==0)//減1按鍵按下檢測
  35.                 {
  36.                     delay(10);//消抖
  37.                         if(down==0)
  38.                         {
  39.                                   shuzi--;
  40.                                   if(shuzi==(-1))//減到0變回99
  41.                                  {
  42.                                             shuzi=99;
  43.                                   }
  44.                         }
  45.                         while(down==0)//松手檢測出后顯示數字
  46.                         {
  47.                                 display();
  48.                         }
  49.                   }
  50.             if(clear==0)//初始化(08)按鍵按下檢測
  51.                 {
  52.                         delay(10);//消抖
  53.                         if(clear==0)
  54.                         {
  55.                                   shuzi=8;//初始化顯示學號后兩位08
  56.                         }
  57.                         while(clear==0)//松手檢測出后顯示數字
  58.                         {
  59.                                    display();  
  60.                         }
  61.                   }
  62.                 display();
  63.         }
  64. }
  65. void delay(uint ms)//延時函數
  66. {
  67.         uint i,j;
  68.         for(i=ms;i>0;i--)
  69.           for(j=120;j>0;j--);
  70. }


  71. void display()  //數碼管顯示函數聲明
  72. {
  73.         ge=shuzi%10;        //計算個位處數碼管的數值
  74.         shi=shuzi/10;        //計算十位處數碼管的數值
  75.         gewei=1;                //關閉數碼管輸入,防止數據有誤
  76.         shiwei=1;                //關閉數碼管輸入,防止數據有誤
  77.         P0=seg[ge];         //送入段選值
  78.         gewei=0;                //導通數碼管個位位選
  79.         delay(2);
  80.         gewei=1;                //關閉個位位選
  81.         P0=seg[shi];         //送入段選值
  82.         shiwei=0;                //導通數碼管十位位選
  83.         delay(2);
  84.         shiwei=1;          //關閉十位位選
  85. }
復制代碼

所有資料51hei提供下載:
數碼顯示.zip (100.93 KB, 下載次數: 54)


作者: LGH850    時間: 2023-2-13 20:38
好程序……




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1