标题: 单片机60s计时器程序,自动计时,无返回 求帮助 [打印本页]

作者: AngelaChicken    时间: 2020-11-28 16:17
标题: 单片机60s计时器程序,自动计时,无返回 求帮助
60s计时器,自动计时,无返回

单片机源程序如下:
  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)


作者: 器车人    时间: 2020-11-28 17:39
你是有问题,还是叫人帮你写啊?楼主
作者: 器车人    时间: 2020-11-28 17:42
验证过了,程序电路都没有问题
作者: 器车人    时间: 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. 带返回的
复制代码

作者: HAISONC    时间: 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 ++;

        }

}
我改了下程序,我的电路是共阳的,所以取反,测试时可行的,你试试
作者: 器车人    时间: 2020-11-28 18:16
HAISONC 发表于 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 ++;

        }

}//这个是循环计时我验证过了
作者: 杜少卿    时间: 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 ++;

        }

}
按照这个来 你试一试

作者: AngelaChicken    时间: 2020-12-15 12:29
统一回复下,这是做的一个分享作品,不是求帮的
作者: 青衣傲王侯    时间: 2020-12-15 12:51
验证过了,程序电路都没有问题




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1