您当前的位置:五五电子网电子知识单片机-工控设备51单片机基于51单片机的数字钟程序 正文
基于51单片机的数字钟程序

基于51单片机的数字钟程序

点击数:7979 次   录入时间:03-04 11:51:14   整理:http://www.55dianzi.com   51单片机
        else
                                      day=1;
          }
          else if(month==2)                                            //2月闰年29天
            { year=year4*1000+year3*100+year1*10+year1;
            if((year%4==0&&year%100!=0)||year%400==0)
            {if(day<29) //闰年
                day++;
          else
            day=1;
                                      }
        else
          {if(day<28) //非闰年
                day++;
          else
            day=1;
          }
          }
              ////////////////////////////////////////////
    }
  else if(state==7)  //
    {
            day=1;
    if(month<12)
    month++;
    else
    month=1;
    }
  else if(state==6)  // 1:显示时间 2:显示月日 3:显示年  4:修改分钟  5:修改时钟  6:修改年  7:修改月  8:修改日 ;
    {    day=1;
    if(year1<9)
    year1++;
    else
  {  year1=0;
    if(year2<9)
      year2++;
        else
    {year1=0;              //最高位2099年
    year2=1;
    year3=0;
    year4=2;
    }
            }
    }//state=6
//    for(d0=600000;d0>0;d0--);
    }  //调时 int0
//}
 } //dpi==0 ,2,4
 
} //timer0 时间  调时  改状态

     

   
void timer1() interrupt 3 using 3  //display
{
 TH1=(65536-3000)/256;
 TL1=(65536-3000)%256;        //0.006s
    monthl=tmonthl[month];
  monthh=tmonthh[month];
  dayl=tdayl[day];
  dayh=tdayh[day];
  hourl=thourl[hour];
  hourh=thourh[hour];
  if(slient==1)
  {  if(j<4)
      j++;
    else
      j=1;
    if(state==1 || state==4 || state==5) //显示时间  1:显示时间 2:显示月日 3:显示年  4:修改分钟  5:修改时钟  6:修改年  7:修改月  8:修改日 ;
    {
        if(j==1)
      {if(state==4 && dps==0 && int0!=0) // 闪烁,调节时不闪
  P1=0x00;
  else
  {P1=display[minl];    //p3.5,p3.4,p3.1,p3.0 为势能端
      }}  //11XX10
    else if(j==2)
      {if(state==4 && dps==0 && int0!=0) // 闪烁
  P1=0x00;
  else
  {P1=display[minh];
    }}  //11XX01
        else if(j==3)
      {if(state==5 && dps==0 && int0!=0) // 闪烁
    P1=0x00;
    else
    {P1=display[hourl];
    }}    //10XX11
      else if(j==4)
      {if(state==5 && dps==0 && int0!=0) // 闪烁
    P1=0x00;
    else
    {P1=display[hourh];
          }}      //01XX11
          }
  else if(state==2 || state==7 || state==8)  //显示月日    1:显示时间 2:显示月日 3:显示年  4:修改分钟  5:修改时钟  6:修改年  7:修改月  8:修改日 ;
    {
        if(j==1)
      {if(state==8 && dps==0 && int0!=0) // 闪烁
    P1=0x00;
    else
    {P1=display[dayl];    //p3.5,p3.4,p3.1,p3.0 为势能端
    }}  //11XX10
    else if(j==2)
      {if(state==8 && dps==0 && int0!=0) // 闪烁
    P1=0x00;
    else
    {P1=display[dayh];
    }}  //11XX01
        else if(j==3)
      {if(state==7 && dps==0 && int0!=0) // 闪烁
    P1=0x00;
    else
    {P1=display[monthl];
    }}    //10XX11
      else if(j==4)
      {if(state==7 && dps==0 && int0!=0) // 闪烁
    P1=0x00;
    else
    {P1=display[monthh];
          }}      //01XX11
    }
  else if(state==3 || state==6)  //显示年
  { 
  if(state==6 && dps==0 && int0!=0)
  P1=0x00;
  else
      {if(j==1)
      {P1=display[year1];    //p3.5,p3.4,p3.1,p3.0 为势能端
      }  //11XX10 3e
    else if(j==2)
      {P1=display[year2];
    }  //11XX01 3d
        else if(j==3)
      {P1=display[year3];
    }    //10XX11 2f
      else if(j==4)
      {P1=display[year4];
          }      //01XX11 1f
    }
  }

      if(j==1)
  {P3_0=0;P3_1=1;P3_4=1;P3_5=1;}
  else if(j==2)
  {P3_0=1;P3_1=0;P3_4=1;P3_5=1;}
  else if(j==3)
  {P3_0=1;P3_1=1;P3_4=0;P3_5=1;}
  else if(j==4)
  {P3_0=1;P3_1=1;P3_4=1;P3_5=0;}
/////////////////////////////////////////////////////////// DP
/////////////////////////////////////////////////////////// 1:显示时间 2:显示月日 3:显示年  4:修改分钟  5:修改时钟  6:修改年  7:修改月  8:修改日 ;
  if(dps==1)
  {if(state==1 || state==2)
  {  if(j==1)                //DP,显示时间,月日
      {DP=0;} 
    else if(j==2)
      {DP=0;} 
        else if(j==3)
      {DP=1;}   
    else if(j==4)
      {DP=0;}      }
  else if(state==3)
  {  if(j==1)                //DP,显示年
      {DP=0;} 
    else if(j==2)
      {DP=0;} 
        else if(j==3)
      {DP=0;}   
    else if(j==4)
      {DP=0;}      }

上一页  [1] [2] [3] [4]  下一页


本文关键字:单片机  程序  51单片机单片机-工控设备 - 51单片机