找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

帖子
查看: 2273|回復(fù): 7
打印 上一主題 下一主題
收起左側(cè)

如何改進(jìn)單片機(jī)程序(希望可以顯示一個(gè)十進(jìn)制數(shù),變化范圍為00-59,開(kāi)始時(shí)顯示00,)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
謝謝大家
單片機(jī)源程序如下:
  1. #include<reg52.h>
  2. #define uchar unsigned char
  3. #define uint unsigned int

  4. sbit DU=P2^6;
  5. sbit WE=P2^7;

  6. uchar code sz[18]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40};

  7. void delay(uint xms)   //延遲函數(shù),毫秒
  8. {
  9.   uint i,j;
  10.   for(i=xms;i>0;i--)
  11.     for(j=112;j>0;j--);
  12. }
  13. int a,b,c,d,e=1000,f;
  14. void shumaguan()
  15. {
  16.             for(e=10000;e>0;e--)
  17.            {
  18.                    P0=sz[d];
  19.                    DU=1;
  20.                    DU=0;
  21.                    P0=0xef;
  22.                    WE=1;
  23.                    WE=0;
  24.                    delay(2);

  25.                    P0=sz[c];
  26.                    DU=1;
  27.                    DU=0;
  28.                    P0=0xe7;
  29.                    WE=1;
  30.                    WE=0;
  31.                    delay(2);

  32.                    P0=sz[17];
  33.                    DU=1;
  34.                    DU=0;
  35.                    P0=0xfb;
  36.                    WE=1;
  37.                    WE=0;
  38.                    delay(2);

  39.                    P0=sz[b];
  40.                    DU=1;
  41.                    DU=0;
  42.                    P0=0xfd;
  43.                    WE=1;
  44.                    WE=0;
  45.                    delay(2);

  46.                    P0=sz[a];
  47.                    DU=1;
  48.                    DU=0;
  49.                    P0=0xfe;
  50.                    WE=1;
  51.                    WE=0;
  52.                    delay(2);
  53.    }
  54. }

  55. void main()
  56. {
  57.   while(1)
  58.   {
  59.      for(a=0;a<6;a++)
  60.        {

  61.          for(b=0;b<10;b++)
  62.            {

  63.              for(c=0;c<6;c++)
  64.                {

  65.                  for(d=0;d<10;d++)
  66.                  {
  67.                    for(f=0;f<10;f++)
  68.                    {
  69.                       shumaguan();
  70.                     }
  71.                   }
  72.                }
  73.            }
  74.         }
  75.    }
  76. }
復(fù)制代碼
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:584814 發(fā)表于 2021-3-31 23:30 | 只看該作者
看到只有一條注釋的代碼不想猜你要表達(dá)什么
回復(fù)

使用道具 舉報(bào)

板凳
ID:207421 發(fā)表于 2021-4-1 00:06 | 只看該作者
unsigned char num;//全局變量
num++;
if(num==100) num = 0;
shumaguan();//shumaguan()數(shù)碼管函數(shù)中,num取個(gè)位 num%10;    num取十位 num/10;
delay(5);
回復(fù)

使用道具 舉報(bào)

地板
ID:390416 發(fā)表于 2021-4-1 09:09 | 只看該作者
你這樣寫(xiě) 肯定是郭天祥那一套�?磮D片,使用緩存方式,讓顯示與其他模塊無(wú)關(guān)。

15 03 16 01 數(shù)碼管的數(shù)組存存放和調(diào)用出來(lái)的顯示原理.pdf

100.27 KB, 下載次數(shù): 1

回復(fù)

使用道具 舉報(bào)

5#
ID:332444 發(fā)表于 2021-4-1 09:36 | 只看該作者
回復(fù)

使用道具 舉報(bào)

6#
ID:213173 發(fā)表于 2021-4-1 11:10 | 只看該作者
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int

sbit DU=P2^6;
sbit WE=P2^7;

uchar i,num;
uint j;
uchar code sz[18]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00,0x40};

void delay(uint xms)   //延遲函數(shù),毫秒
{
        uint i,j;
        for(i=xms;i>0;i--)
                for(j=112;j>0;j--);
}
//int a,b,c,d,e=1000,f;
void shumaguan()
{
        uchar a[2];
        a[0]=sz[num/10];
        a[1]=sz[num%10];
        P0=0x00;
        DU=1;DU=0;
        P0=~(0x01<<i);
        WE=1;WE=0;
        P0=a[i];
        DU=1;DU=0;
        i=++i%2;
}

void main()
{
        while(1)
        {
                shumaguan();       
                j++;
                if(j>=1000)
                {
                        j=0;
                        num++;
                        if(num==60)
                                num=0;
                }
                delay(1);
        }
}
回復(fù)

使用道具 舉報(bào)

7#
ID:894974 發(fā)表于 2021-4-1 19:56 | 只看該作者
wulin 發(fā)表于 2021-4-1 11:10
#include
#define uchar unsigned char
#define uint unsigned int

這個(gè)時(shí)間準(zhǔn)確嗎?
回復(fù)

使用道具 舉報(bào)

8#
ID:894974 發(fā)表于 2021-4-1 19:57 | 只看該作者
man1234567 發(fā)表于 2021-3-31 23:30
看到只有一條注釋的代碼不想猜你要表達(dá)什么

嘻嘻嘻,新手不太懂,下次知道了
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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