登錄|立即注冊|使用QQ帳號登錄
論壇 > 24小時必答區(qū)
發(fā)帖|
看2250|回7|收藏
樓主 ID:894974 只看他
2021-3-31 23:17
謝謝大家
單片機源程序如下:

代碼:

  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ā) ID:584814 只看他
2021-3-31 23:30
看到只有一條注釋的代碼不想猜你要表達什么
板凳 ID:207421 只看他
2021-4-1 00:06
unsigned char num;//全局變量
num++;
if(num==100) num = 0;
shumaguan();//shumaguan()數(shù)碼管函數(shù)中,num取個位 num%10;    num取十位 num/10;
delay(5);
地板 ID:390416 只看他
2021-4-1 09:09
你這樣寫 肯定是郭天祥那一套??磮D片,使用緩存方式,讓顯示與其他模塊無關(guān)。 51hei截圖20210401090851.png
附件列表
5# ID:332444 只看他
2021-4-1 09:36
6# ID:213173 只看他
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);
        }
}
7# ID:894974 只看他
2021-4-1 19:56

引用:

wulin 發(fā)表于 2021-4-1 11:10
#include
#define uchar unsigned char
#define uint unsigned int

這個時間準確嗎?
8# ID:894974 只看他
2021-4-1 19:57

引用:

man1234567 發(fā)表于 2021-3-31 23:30
看到只有一條注釋的代碼不想猜你要表達什么

嘻嘻嘻,新手不太懂,下次知道了

51黑電子論壇

Powered by Discuz! X3.1

首頁|標準版|觸屏版|電腦版