找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 2873|回復: 8
收起左側

單片機60s計時器程序,自動計時,無返回 求幫助

[復制鏈接]
ID:825693 發(fā)表于 2020-11-28 16:17 | 顯示全部樓層 |閱讀模式
60s計時器,自動計時,無返回
51hei.png
單片機源程序如下:
  1. //0-59自動計數器
  2. //跳線設置:默認
  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;           //定時器中斷打開
  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. }
復制代碼

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

回復

使用道具 舉報

ID:278840 發(fā)表于 2020-11-28 17:39 | 顯示全部樓層
你是有問題,還是叫人幫你寫啊?樓主
回復

使用道具 舉報

ID:278840 發(fā)表于 2020-11-28 17:42 | 顯示全部樓層
驗證過了,程序電路都沒有問題
回復

使用道具 舉報

ID:278840 發(fā)表于 2020-11-28 17:50 | 顯示全部樓層
  1. //0-59自動計數器
  2. //跳線設置:默認
  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;           //定時器中斷打開
  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. 帶返回的
復制代碼

評分

參與人數 1黑幣 +20 收起 理由
admin + 20 回帖助人的獎勵!

查看全部評分

回復

使用道具 舉報

ID:838732 發(fā)表于 2020-11-28 18:10 | 顯示全部樓層
  //0-59自動計數器
//跳線設置:默認
#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;           //定時器中斷打開
                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 ++;

        }

}
我改了下程序,我的電路是共陽的,所以取反,測試時可行的,你試試
回復

使用道具 舉報

ID:278840 發(fā)表于 2020-11-28 18:16 | 顯示全部樓層
HAISONC 發(fā)表于 2020-11-28 18:10
//0-59自動計數器
//跳線設置:默認
#include

[code]
  //0-59自動計數器
//跳線設置:默認
#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;           //定時器中斷打開
                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 ++;

        }

}//這個是循環(huán)計時我驗證過了
回復

使用道具 舉報

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;           //定時器中斷打開
                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 ++;

        }

}
按照這個來 你試一試
回復

使用道具 舉報

ID:825693 發(fā)表于 2020-12-15 12:29 | 顯示全部樓層
統(tǒng)一回復下,這是做的一個分享作品,不是求幫的
回復

使用道具 舉報

ID:860490 發(fā)表于 2020-12-15 12:51 | 顯示全部樓層
驗證過了,程序電路都沒有問題
回復

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表