DIY LED digital tube timer

Publisher:快乐航程Latest update time:2015-07-09 Source: 51heiKeywords:DIY  LED  timer Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Since there is only one digital tube, it can only display 0 to 15, so this timer can be used for 0 to 15 minutes, 0 to 15 hours, 0 to 15 days, and 0 to 15 weeks. I originally wanted to add a timer for 0 to 15 months in the program, but I thought that in actual situations, the 15-month timer has been more than a year, and it is estimated that it will be rarely used, so I will not write it. I added a relay to this timer, so it can control 220V AC, and the timing error is within a few milliseconds, which is quite accurate. . .

Here are a few early schematic diagrams:         Here is the source code of the microcontroller: #include #define uint unsigned int #define uchar unsigned char sbit ledg=P1^0;//second flashing (one second on and one second off) sbit ledb=P1^1;//minute flashing (one minute on and one minute off) sbit fmq=P3^3;//buzzer sbit ledx=P3^4;//timer week indicator sbit ledt=P3^6;//timer day indicator sbit ledf=P3^5;//timer minute indicator sbit leds=P3^7;//timer hour indicator sbit key1=P1^6;//start|pause sbit key2=P1^5;//adjust timer minutes sbit key3=P1^4;//adjust timer hours sbit key4=P1^3;//adjust timer day sbit key5=P1^2;// adjust the timing week sbit jdq=P1^7; //relay uint i,j,num,num1,num2,num3,num4,num5,num6; uchar shi,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,dsf,dss,dst,dsx; uchar code shuju[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8, 0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E                           }; void delayms(uint xms) { for(i=xms;i>0;i--) for(j=110;j>0;j--); } void display(shi) { P2=shuju[shi]; } void keyscan() { uchar i; if(key1==0) {     delayms(10); if(key1==0) { ledb=0; //Call the minute flashing indicator to indicate start|pausewhile (i==0&&P2!=0xC0) {    TR0=~TR0;// Start|Pausei  ++; } if(TR0==1) {        ledb=1;//Call the minute flashing indicator to indicate start|pause } else   {      TR0=0;    } } }   if(key2==0&&TR0==0)     {     dss=0; // Timer hour clears dst=0; // Timer day clears dsx=0; // Timer week clears temp1=1; //Enter switch-case    delayms(10);                  }   if(key3==0&&TR0==0)     {    dsf=0; dst=0; dsx=0; temp2=1;    delayms(10);                  }   if(key4==0&&TR0==0)     { dsf=0; dss=0; dsx=0; temp3=1;    delayms(10);                  }   if(key5==0&&TR0==0)     {    dsf=0; dss=0; dst=0; temp4=1;    delayms(10);                  }                      switch (temp1) {   case 1:  if(key2==0)    {  leds=1; // Turn off the timer hour indicator  ledt=1; // Turn off the timer day indicator  ledx=1; // Turn off the timer week indicator        ledf=0; // Turn on the timer minute indicator  ledg=1; // Turn off the second flashing  ledb=1; // Turn off the minute flashing  jdq=0; // Turn off the relay                          dsf++; // Minute increment







































































































 shi=dsf; // Send points to display
   if(dsf==16)
  {
     shi=0;
     dsf=0;  
   }
     while(!key2);
 temp1=2;
 temp5=1;
 num2=dsf;
 temp6=2;
 temp7=2;
 temp8=2;
 }
break;
    }
switch (temp2)
 {
 case 1:
if(key3==0)
  {
     ledf=1;
 ledt=1;
 ledx=1;
 leds=0;
 jdq=0;
 ledg= 1;
     ledb=1;
 dss++;
 shi=dss;
   if(dss==16)
 {
  shi=0;
  dss=0;
 }
                                      while(!key3);
 temp2=2;
 temp6=1;
     num4=dss;           
 temp5=2 ;
 temp7=2;
 temp8=2;
}
break;
  }
  switch (temp3)
 {
 case 1:
if(key4==0)
  {
     ledf=1;
 leds=1;
 ledx=1;
 ledt=0;
 jdq=0;
 ledg=1;
     ledb=1;
 dst++;
 shi=dst;
  if(dst==16)
    {
  shi=0;
  dst=0;
}
                                     while(!key4);
temp3=2;
temp7=1;
    num5=dst;           
    temp5=2;
temp6=2;
temp8=2;
  }
 break;
}
 switch (temp4)
{
 case 1:
  if(key5==0)
  {
     ledf=1;
 leds=1;
 ledt=1;
 ledx=0;
 jdq=0;
 ledg=1;
     ledb=1;
 dsx++;
 shi=dsx;
  if(dsx==16)
    {
      shi=0;
  dsx=0 ;
}
                                     while(!key5);
temp4=2;
temp8=1;
    num6=dsx;           
    temp5=2;
temp6=2;
temp7=2;
  }
 break;
}
 switch (temp5)
{
  case 1:
  if(num==3686)
{
   num=0;
   ledg=~ledg;
   num1++;
}

                   if(num1==60)
            {
num1=0;
num2--;
shi=num2;
                           if(num2==0)
                 {
    jdq=1;
TR0=0;
                 }
             }   
   break;

}
  switch (temp6)
{
    case 1:
       if(num==3686)
  {
   num=0;
   ledg=~ledg;
   num1++;
  }
     
if(num1==60)
{
num1=0;
ledb=~ledb;
num3++;
    if( num3==60)
   {
       num3=0;
num4--;
                   shi=num4;                                 
}
    if(num4==0)
   {
    jdq=1;
    TR0=0;
   }
                 }
    break;
         }
switch (temp7)
 {
    case 1:
 if( num==3686)
{
   num=0;
   ledg=~ledg;
   num1++;
}
     
if(num1==60)
{
num1=0;
ledb=~ledb;
num3++;
    if(num3==1440)
   {
       num3=0;
num5 --;
                   shi=num5;                                 
}
    if(num5==0)
   {
    jdq=1;
    TR0=0;
   }
                 }
    break;
         }
switch (temp8)
 {
    case 1:
 if(num==3686)
{
   num=0;
   ledg=~ledg;
   num1++;
}
     
if(num1==60)
{
num1=0;
ledb =~ledb;
num3++;
    if(num3==10080)
   {
       num3=0;
num6--;
                   shi=num6;                                 
}
    if(num6==0)
   {
    jdq=1;
    TR0=0;
   }
                 }
    break;
          }
}
  
void main() 
{
   TMOD=0x02;
TH0=6;
TL0=6;
EA=1;
ET0=1;
jdq=0;
while(1)
{
         keyscan();
     display(shi);
 while(jdq==1&&P2== 0xC0)
     {
      fmq=0;
ledg=1;
ledb=1;
     }
}
}
void T0_time()interrupt 1
{
    num++;
}
    
Download the full code: http://www.51hei.com/f/ledccr.rar
This is the circuit diagram drawn by the perforated board drawing software:



Keywords:DIY  LED  timer Reference address:DIY LED digital tube timer

Previous article:stc89c52+18b20 complete temperature collection together
Next article:Single chip 4-digit digital tube electronic clock

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号