找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1832|回復(fù): 5
打印 上一主題 下一主題
收起左側(cè)

有沒有幫我看看怎么做的

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:200305 發(fā)表于 2017-5-13 15:01 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
有沒有幫我看看怎么做的

$`E]EPTQH5EV{TP7ENWU~UH.png (55.9 KB, 下載次數(shù): 73)

$`E]EPTQH5EV{TP7ENWU~UH.png
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:200305 發(fā)表于 2017-5-14 22:38 | 只看該作者
有沒有大神給看看
回復(fù)

使用道具 舉報

受到警告 板凳
ID:200799 發(fā)表于 2017-5-15 00:47 | 只看該作者
幫頂!。。。。。!
回復(fù)

使用道具 舉報

地板
ID:82765 發(fā)表于 2017-5-15 06:22 | 只看該作者
提示: 作者被禁止或刪除 內(nèi)容自動屏蔽
回復(fù)

使用道具 舉報

5#
ID:155507 發(fā)表于 2017-5-15 09:23 | 只看該作者

  1. #include <reg51.h>                        //此文件中定義了單片機(jī)的一些特殊功能寄存器

  2. #define duan   P2                //段選
  3. typedef unsigned int u16;        //對數(shù)據(jù)類型進(jìn)行聲明定義
  4. typedef unsigned char u8;


  5. sbit s1=P3^2; //定義P32口是s1
  6. sbit s2=P3^7; //定義P37口是s2 開始/暫停/清零 按鈕

  7. u8 code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
  8.         0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};//顯示0~F的值
  9. u8 cnt=0, display=0;
  10. u8 status =0; //0: 開始/1:暫停 /2: 清零 按鈕

  11. /*******************************************************************************
  12. * 函 數(shù) 名         : delay
  13. * 函數(shù)功能                   : 延時函數(shù),i=1時,大約延時10us
  14. *******************************************************************************/
  15. void delay(u16 i)
  16. {
  17.         while(i--);       
  18. }

  19. /*******************************************************************************
  20. * 函 數(shù) 名         : keypros1
  21. * 函數(shù)功能                   : 按鍵處理函數(shù),判斷按鍵s1是否按下
  22. *******************************************************************************/
  23. void keypros1()
  24. {
  25.         if(s1==0)                  //檢測按鍵s1是否按下
  26.         {       
  27.                 delay(1000);   //消除抖動 一般大約10ms
  28.                 if(s1==0)         //再次判斷按鍵是否按下
  29.                 {
  30.                         if(!status) //檢測暫停
  31.                         cnt++;

  32.                         if(cnt > 5) //按6次
  33.                         {
  34.                                 cnt = 0;
  35.                                 display++;
  36.                                 if(display > 9)
  37.                                 {
  38.                                         display=0;
  39.                                 }
  40.                         }
  41.                 }
  42.                 while(!s1);         //檢測按鍵是否松開
  43.         }               
  44. }

  45. /*******************************************************************************
  46. * 函 數(shù) 名         : keypros2
  47. * 函數(shù)功能                   : 按鍵處理函數(shù),判斷按鍵s2是否按下
  48. *******************************************************************************/
  49. void keypros2()
  50. {
  51.         if(s2==0)                  //檢測按鍵s2是否按下
  52.         {       
  53.                 delay(1000);   //消除抖動 一般大約10ms
  54.                 if(s2==0)         //再次判斷按鍵是否按下
  55.                 {
  56.                         status++;
  57.                         if(status == 2)
  58.                         {
  59.                                 display=0;
  60.                                 cnt = 0;
  61.                         }
  62.                         if(status > 2)
  63.                         {
  64.                                 status=0;
  65.                         }                       
  66.                 }
  67.                 while(!s2);         //檢測按鍵是否松開
  68.         }               
  69. }

  70. /*******************************************************************************
  71. * 函 數(shù) 名       : main
  72. * 函數(shù)功能                : 主函數(shù)
  73. * 輸    入       : 無
  74. * 輸    出            : 無
  75. *******************************************************************************/
  76. void main()
  77. {       
  78.         while(1)
  79.         {       
  80.                 keypros1();  //按鍵處理函數(shù)       
  81.                 keypros2();  //按鍵處理函數(shù)       
  82.                 duan=smgduan[display]; //顯示
  83.         }               
  84. }

復(fù)制代碼
回復(fù)

使用道具 舉報

6#
ID:154074 發(fā)表于 2017-5-15 10:59 | 只看該作者
數(shù)碼管不知道你怎么接的,數(shù)組那里我隨便填了,你自己改上


#include "reg52.h"                         

          
#define        u16 unsigned int
#define u8 unsigned char

sbit k1=P3^7;                  

u8 c6=0;
u8 num=0;
u8 code duanma[]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
                                        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};

void delay(u16 i)
{
        while(i--);       
}


void keypress()
{
        if(k1==0)                 
        {       
                delay(1000);   //大約10ms
                if(k1==0)         
                {
                        c6++;
                        if(c6==6)
                        {
                                c6=0;
                                num++;
                                if(num==10)num=0;
                                P2=duanma[num];
                        }
                                 
                }
                while(!k1);         
        }               
}


void main()
{       
        k1=1;
        P2=duanma[0];
        while(1)
        {       
                keypress();  
        }               
}
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表