找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

单片机60s计时器程序,自动计时,无返回 求帮助

查看数: 3009 | 评论数: 8 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2020-11-28 16:17

正文摘要:

60s计时器,自动计时,无返回

回复

ID:860490 发表于 2020-12-15 12:51
验证过了,程序电路都没有问题
ID:825693 发表于 2020-12-15 12:29
统一回复下,这是做的一个分享作品,不是求帮的
ID:535215 发表于 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:278840 发表于 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 ++;

        }

}//这个是循环计时我验证过了
ID:838732 发表于 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 发表于 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:278840 发表于 2020-11-28 17:42
验证过了,程序电路都没有问题
ID:278840 发表于 2020-11-28 17:39
你是有问题,还是叫人帮你写啊?楼主

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表