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

QQ登錄

只需一步,快速開始

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

單片機(jī)60s計(jì)時(shí)器程序,自動(dòng)計(jì)時(shí),無返回 求幫助

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:825693 發(fā)表于 2020-11-28 16:17 | 只看該作者 |只看大圖 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
60s計(jì)時(shí)器,自動(dòng)計(jì)時(shí),無返回

單片機(jī)源程序如下:
  1. //0-59自動(dòng)計(jì)數(shù)器
  2. //跳線設(shè)置:默認(rèn)
  3. #include<reg51.h>
  4. unsigned char code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  5. unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  6. unsigned char timer=0;
  7. unsigned char second;
  8. main()
  9. {
  10.                 TMOD = 0x01;        
  11.                 EA=1;            //總中斷打開
  12.                 ET0=1;           //定時(shí)器中斷打開
  13.                 second=0;
  14.                 TR0=1;
  15.                 P0=discode1[second/10];
  16.                 P2=discode2[second%10];
  17.                 while(1)
  18.                 {
  19.                         
  20.                 }

  21. }
  22. void int_T0() interrupt 1 using 0
  23. {
  24.         TR0=0;
  25.         TH0=0xee;
  26.         TL0=0x00;
  27.         timer ++;
  28.         if(timer==200)
  29.         {
  30.                 timer = 0;
  31.                 second ++;
  32.                 P0=discode1[second/10];
  33.                 P2=discode2[second%10];
  34.         }
  35.         if(second==60)
  36.         {
  37.                 TR0=0;
  38.                 second=0;
  39.         }
  40.         else
  41.         {
  42.                 TR0=1;
  43.         }
  44. }
復(fù)制代碼

所有資料51hei提供下載:
jishi.zip (18.68 KB, 下載次數(shù): 13)

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:278840 發(fā)表于 2020-11-28 17:39 | 只看該作者
你是有問題,還是叫人幫你寫?樓主
回復(fù)

使用道具 舉報(bào)

板凳
ID:278840 發(fā)表于 2020-11-28 17:42 | 只看該作者
驗(yàn)證過了,程序電路都沒有問題
回復(fù)

使用道具 舉報(bào)

地板
ID:278840 發(fā)表于 2020-11-28 17:50 | 只看該作者
  1. //0-59自動(dòng)計(jì)數(shù)器
  2. //跳線設(shè)置:默認(rèn)
  3. #include<reg51.h>
  4. unsigned char code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  5. unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
  6. unsigned char timer=0;
  7. unsigned char second;
  8. bit back;
  9. main()
  10. {
  11.                 TMOD = 0x01;        
  12.                 EA=1;            //總中斷打開
  13.                 ET0=1;           //定時(shí)器中斷打開
  14.                 second=0;
  15.                 TR0=1;
  16.                 P0=discode1[second/10];
  17.                 P2=discode2[second%10];
  18.                 while(1)
  19.                 {
  20.                         
  21.                 }

  22. }
  23. void int_T0() interrupt 1 using 0
  24. {
  25.         TR0=0;
  26.         TH0=0xee;
  27.         TL0=0x00;
  28.         timer ++;
  29.                 TR0 = 1;
  30.         if(timer==200)
  31.         {
  32.                 timer = 0;
  33.                                 if(second==0)
  34.                                 {
  35.                         back = 0;
  36.                                 }
  37.                                 if(second==60)
  38.                                 {
  39.                                         back = 1;
  40.                                 }
  41.                                 if(back==0)
  42.                                 {
  43.                                         second++;
  44.                                 }
  45.                                 else
  46.                                 {
  47.                                         second--;
  48.                                 }

  49.                 P0=discode1[second/10];
  50.                 P2=discode2[second%10];
  51.                        
  52.         }
  53.       
  54. }
  55. 帶返回的
復(fù)制代碼

評(píng)分

參與人數(shù) 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

5#
ID:838732 發(fā)表于 2020-11-28 18:10 | 只看該作者
  //0-59自動(dòng)計(jì)數(shù)器
//跳線設(shè)置:默認(rèn)
#include<reg51.h>
unsigned char code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char second;
unsigned int timer;
void main()
{
                TMOD = 0x01;        
                EA=1;            //總中斷打開
                ET0=1;           //定時(shí)器中斷打開
                second=0;
                TR0=1;
                 while(1)
                                 {
                                   if(second<60)
                                   {P0=~discode1[second/10];
                   P2=~discode2[second%10];
                                   }
                   else if(second==60)
                                   {second=0;}   
                   }
}
void int_T0() interrupt 1 using 0
{
                TH0=0xee;
        TL0=0x00;

        timer ++;
        if(timer==200)
        {
                timer = 0;
                second ++;

        }

}
我改了下程序,我的電路是共陽的,所以取反,測(cè)試時(shí)可行的,你試試
回復(fù)

使用道具 舉報(bào)

6#
ID:278840 發(fā)表于 2020-11-28 18:16 | 只看該作者
HAISONC 發(fā)表于 2020-11-28 18:10
//0-59自動(dòng)計(jì)數(shù)器
//跳線設(shè)置:默認(rèn)
#include

[code]
  //0-59自動(dòng)計(jì)數(shù)器
//跳線設(shè)置:默認(rèn)
#include<reg51.h>
unsigned char code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char second;
unsigned int timer;
void main()
{
                TMOD = 0x01;        
                EA=1;            //總中斷打開
                ET0=1;           //定時(shí)器中斷打開
                second=0;
                TR0=1;
                 while(1)
                                 {
                                   if(second<60)
                                   {P0=discode1[second/10];
                   P2=discode2[second%10];
                                   }
                   else if(second==60)
                                   {second=0;}   
                   }
}
void int_T0() interrupt 1 using 0
{
                TH0=0xee;
        TL0=0x00;

        timer ++;
        if(timer==200)
        {
                timer = 0;
                second ++;

        }

}//這個(gè)是循環(huán)計(jì)時(shí)我驗(yàn)證過了
回復(fù)

使用道具 舉報(bào)

7#
ID:535215 發(fā)表于 2020-11-28 18:28 | 只看該作者
#include<reg51.h>
unsigned char code discode1[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char code discode2[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char second;
unsigned int timer;
void main()
{
                TMOD = 0x01;        
                EA=1;            //總中斷打開
                ET0=1;           //定時(shí)器中斷打開
                second=0;
                TR0=1;
                 while(1)
                                 {
                                   if(second<60)
                                   {P0=discode1[second/10];
                   P2=discode2[second%10];
                                   }
                   else if(second==60)
                                   {second=0;}   
                   }
}
void int_T0() interrupt 1 using 0
{
                TH0=0xee;
        TL0=0x00;

        timer ++;
        if(timer==200)
        {
                timer = 0;
                second ++;

        }

}
按照這個(gè)來 你試一試
回復(fù)

使用道具 舉報(bào)

8#
ID:825693 發(fā)表于 2020-12-15 12:29 | 只看該作者
統(tǒng)一回復(fù)下,這是做的一個(gè)分享作品,不是求幫的
回復(fù)

使用道具 舉報(bào)

9#
ID:860490 發(fā)表于 2020-12-15 12:51 | 只看該作者
驗(yàn)證過了,程序電路都沒有問題
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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