標(biāo)題: 單片機(jī)60s計(jì)時(shí)器程序,自動(dòng)計(jì)時(shí),無返回 求幫助 [打印本頁(yè)]

作者: AngelaChicken    時(shí)間: 2020-11-28 16:17
標(biāo)題: 單片機(jī)60s計(jì)時(shí)器程序,自動(dòng)計(jì)時(shí),無返回 求幫助
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)


作者: 器車人    時(shí)間: 2020-11-28 17:39
你是有問題,還是叫人幫你寫?樓主
作者: 器車人    時(shí)間: 2020-11-28 17:42
驗(yàn)證過了,程序電路都沒有問題
作者: 器車人    時(shí)間: 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ù)制代碼

作者: HAISONC    時(shí)間: 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 ++;

        }

}
我改了下程序,我的電路是共陽(yáng)的,所以取反,測(cè)試時(shí)可行的,你試試
作者: 器車人    時(shí)間: 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)證過了
作者: 杜少卿    時(shí)間: 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è)來 你試一試

作者: AngelaChicken    時(shí)間: 2020-12-15 12:29
統(tǒng)一回復(fù)下,這是做的一個(gè)分享作品,不是求幫的
作者: 青衣傲王侯    時(shí)間: 2020-12-15 12:51
驗(yàn)證過了,程序電路都沒有問題




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1