切换到宽版
爱科技/爱创意/爱折腾;电子/数码爱好者的家!欢迎访问新版数码之家网站
  • 1834阅读
  • 6回复

[C51]求助    有没有人可以在19位万年历帮我加个DS12C887+程序 有源码 [复制链接]

上一主题 下一主题
离线一缕阳光
 

发帖
1727
M币
2621
专家
10
粉丝
42
只看楼主 倒序阅读 我要置顶 楼主  发表于: 2015-08-03
求助    有没有人可以在19位万年历帮我加个DS12C887+程序进去



这是原理图


这是源码  

#include<reg51.h>
#include<absacc.h>
#define uchar unsigned char
#define uint  unsigned int
#define ture  1
#define fault 0

sbit SET=P1^7;

void  delay(uchar  k) ;
uchar monthday(uchar a,uchar b);
void display()    ;

uchar code dayofmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
uchar code scan[]={0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
                    0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
                    0xf8,0xf9,0xfa,0xfb,0xfc,0xfd};
                    //扫描的译码信号
uchar i;
uchar code table[]={0xBF,0x86,0xDB,0xCF,0xE6,0xED,0xFD,0xA7,0xFF,0xEF,0xC0};
uchar  buffer[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
uchar  shuju=0;
uchar  state=0;
uchar  qxiang;

typedef  struct  
         {
         uchar year[2];
         uchar month;
         uchar day;
         uchar week;
         }date;
typedef  struct  
        {
        uchar hour;
        uchar minute;
        uchar second;
        }time;
uchar  count=0;
date today={{9,20},4,20,1};
time now={11,8,10};
void main()
{
TMOD=0x01;
TL0=(65536-1000)%256;
TH0=(65536-1000)/256;
IE=0x82;      //EA=1;ET0=1总中断允许和定时器中断允许
TCON=0x10;      //定时器启动计数
while(1)
    {
     P1=0xff;

     shuju=P1&0xff;
     qxiang=shuju&0x80;
        switch(qxiang)
        {
         case(0x80):switch(shuju)
                  {
                 case(0xfe) :               //秒调整
                    {
                     EA=1;
                     EX0=1;           //IE=0x83;            //EA=1;ET0=1;EX0=0总中断允许,定时器中断允许,外中断允许
                     IT0=1;           //TCON=0x11;            //TR0=1;IT0=1;定时器启动,外中断为负边沿触发
                     }break;
                    case(0xfd)    :             //分调整
                    {
                     EA=1;
                     EX0=1;                  // IE=0x83;
                     IT0=1;                    //TCON=0x11;
                     }break;
                    case(0xfb) :            //时调整
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                    
                     }break;
                 case(0xf7) :               //星期调整
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                  
                     }break;
                 case(0xef) :                    //日调整
                     {
                    EA=1;
                     EX0=1;
                     IT0=1;
                
                     }break;
                 case(0xdf):                 //月调整
                     {
                    EA=1;
                     EX0=1;
                     IT0=1;
                
                     }break;
                 case(0xbf):                    //年调整
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                    
                     }break;
                 default:                         //时钟正常计时
                    {
                    EA=1;
                    TR0=1;
                    EX0=0;
                
                    }break;
                }break;
         case(0x00) :switch(shuju)
                         {
               case(0x7e):
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                    
                    }break;
               case(0x7d):
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                
                    }break;
               case(0x7b):
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                
                    }break;
               case(0x77):
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                
                    }break;
               case(0x6f):
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                    
                    }break;
               case(0x5f):
                    {
                     EA=1;
                     EX0=1;
                     IT0=1;
                    
                    }break;
               case(0x3f):
                    {
                    EA=1;
                     EX0=1;
                     IT0=1;
                    
                    }break;
               default:                         //时钟正常计时
                    {
                    EA=1;
                    TR0=1;
                    EX0=0;
                        
                    }break;
                }break;      
        }
    }
}

void inter0()  interrupt 0  using 0
  {
  uchar result,z;
  result=shuju;
           switch(qxiang)
        {
         case(0x80):   switch(result)
                       {
                           case(0xfe) :                      // if(result==0xfe)                   //秒调整    +
                             {
                               now.second++;
                               if(now.second>=60)
                                  {
                                    now.second=0;
                                   }
                               display();
                              }break;
  
                         case(0xfd) :                     //if(result==0xfd)                     //分调整  +
                             {
                                now.minute++;
                                if(now.minute>=60)
                                 {
                                   now.minute=0;
                                  }
                                 display();
                             }break;
  
                            case(0xfb) :           //if(result==0xfb)                   //时调整    +
                              {
                                 now.hour++;
                                 if(now.hour>=24)
                                    {
                                      now.hour=0;
                                     }
                                    display();
                              }break;

                             case(0xf7)    :          // if(result==0xf7)                   //星期调整 +
                                  {          
                                     today.week++;
                                      if(today.week>=8)
                                          {
                                            today.week=1;
                                           }
                                      display();
                                  }break;

                              case(0xef) :            //if(result==0xef)                   //日期调整     +
                                  {
                                     today.day++;
                                     z = monthday( today.year[1]  ,  today.year[0] );
                                     if((z==1)&&(today.month==2))
                                        {
                                          if(today.day>=30)
                                             today.day=1;
                                        }

                                      else if (today.day>dayofmonth[today.month-1])
                                                    today.day=1;
                                       display();
                                    }break;      
      
                              case(0xdf) :             //if(result==0xdf)                    //月调整    +
        
                                    {
                                        today.month++;
                                           if(today.month>=13)
                                           {
                                             today.month=1;
                                            }
                                        display();
                                       } break;
  
        
                               case(0xbf) :                     //if(result==0xbf)                      //年调整 +
                                     {
                                       today.year[0]=today.year[0]+1;
                                       if(today.year[0]>=100)
                                           {
                                             today.year[0]=0;
                                             today.year[1]=today.year[1]+1;
                                             if(today.year[1]>=100)
                                                {
                                                   today.year[1]=0;
                                                 }
                                             }
                                         display();
                                       }break;
                               default:                         //时钟正常计时
                                     {
                                     EA=1;
                                     TR0=1;
                                     EX0=0;
                                                              
                                     }break;
                             }break;
                    
  case(0x00): switch(result)
            {
              case(0x7e):                //if(result==0x7f)                     //秒调整—
                      {
                          if(now.second>0)
                          now.second=now.second-1;
                       else  now.second=59;
                            display();
                      }break;
    
  case(0x7d):                        //if(result==0x7d)                      //分调整—
       {
           if(now.minute>0)
           now.minute=now.minute-1;
        else now.minute=59;
        display();
       }  break;
    
  case(0x7b) :                      //if(result==0x7b)                      //  时调整-
      
       {
           if(now.hour>0)
           now.hour=now.hour-1;
        else now.hour=23 ;
        display();
       }break;
    
    case(0x77) :                     //if(result==0x77)                     //     周调整—
       {
        if(today.week>1)
           today.week=today.week-1;
        else today.week=7;
        display();
       }break;

      
    case(0x6f):                                   //if(result==0x6f)                  //     日期调整—
       {
        z = monthday( today.year[1]  ,  today.year[0] );
           if((z==1)&&(today.month==2))
           {
           if(today.day>1)
              today.day=today.day-1;
            else today.day=29;
           }
        else {
              if(today.day>1)
                 today.day=today.day-1;
              else today.day=dayofmonth[today.month-1];
              }
        display();
       }break;

     case(0x5f):                            //if(result==0x5f)                    //    月调整—
       {
           if(today.month>1)
           today.month=today.month-1;
        else today.month=12;
        display();
       }break;
     case(0x3f) :      // 年调整——
       {
           if(today.year[0]>0)
           today.year[0]=today.year[0]-1;
        else
            {
             today.year[0]=99;
             today.year[1]=today.year[1]-1;
            }
        display();
       }break;
     default:                         //时钟正常计时
                    {
                    EA=1;
                    TR0=1;
                    EX0=0;    
                    }break;
         }break;
        }
    }

void  timer0_int() interrupt 1 using 1
{
uchar c;
TL0=(65536-1000)%256;          //中断时间是10ms
TH0=(65536-1000)/256;
TR0=1;
count++;
if(count==35)
    {
    count=0;
    now.second=now.second+1;
     if(now.second>=60)
        {
        now.second=0;
        now.minute++;
        if(now.minute>=60)
           {
           now.minute=0;
           now.hour++;
           if(now.hour>=24)
              {
              now.hour=0;
              today.week++;
              today.day++;
              if(today.week>=8)
                 {
                 today.week=1;
                 }
              c=monthday( today.year[1], today.year[0]);
              if((c==1)&&(today.month==2))
                 {
                 if(today.day>=30)
                   {
                    today.day=1;
                    today.month++;
                   }
                  
                 }
              else if(today.day>=(dayofmonth[today.month-1]+1))
                      {
                      today.day=1;
                      today.month++;
               if(today.month>=13)
                  {
                   today.month=1;
                   today.year[0]=today.year[0]+1;
                   if(today.year[0]>=100)
                      {
                      today.year[0]=0;
                      today.year[1]=today.year[1]+1;
                      if(today.year[1]>=100)
                         {
                         today.year[1]=0;
                         }
                      }
                  }
              }
           }
          }
        }
    }
    display();
}
void  delay(uchar  k)
  {
  uchar m,n;
  for(m=0;m<=k;m++)
   for(n=0;n<=40;n++);
  }
  //  计算年份程序
uchar  monthday(uchar a,uchar b)
  {
   uchar x,y;
   x=a*100+b;
   if(x%4!=0)
      y=0;
   else if(x%100!=0)
      y=1;
   else if(x%400!=0)
      y=0;
   else y=1;
  
//if((x%4==0 && x%100!=0)|| (x%400==0))
//   y=1;
// else y=0;
   return(y) ;
  }    
void display()
{
  buffer[0]=now.second%10;
  buffer[1]=now.second/10;
  buffer[2]=10;
  buffer[3]=now.minute%10;
  buffer[4]=now.minute/10;
  buffer[5]=10;
  buffer[6]=now.hour%10;
  buffer[7]=now.hour/10;
  buffer[8]=today.week%10;
  buffer[9]=today.week/10;
  buffer[10]=10;
  buffer[11]=today.day%10;
  buffer[12]=today.day/10;
  buffer[13]=10;
  buffer[14]=today.month%10;
  buffer[15]=today.month/10;
  buffer[16]=10;
  buffer[17]=today.year[0]%10;
  buffer[18]=today.year[0]/10;
  buffer[19]=today.year[1]%10;
  buffer[20]=today.year[1]/10;
  buffer[21]=10;
   for(i=0;i<=21;i++)
    {
    P0=table[buffer];    
    P2=scan;
    delay(8);
    P2=0xFF;
    }
}



希望有人可以帮到我
本文内容包含图片或附件,获取更多资讯,请 登录 后查看;或者 注册 成为会员获得更多权限
关键词: 原理图c51
M币换购:一键弹出,唯快不破!数码之家23合一全金属螺丝刀套装(拆客必备系列)
 
离线mei781023

发帖
7007
M币
9007
专家
2
粉丝
36
只看该作者 1楼 发表于: 2015-08-03
Re:求助    有没有人可以在19位万年历帮我加个DS12C887+程序  ..
不懂这个,帮不到你
离线一缕阳光

发帖
1727
M币
2621
专家
10
粉丝
42
只看该作者 2楼 发表于: 2015-08-03
回 mei781023 的帖子
mei781023:不懂这个,帮不到你 (2015-08-03 08:45) 回 mei781023 的帖子

没关系   还是要谢谢帮顶
离线z576421511
发帖
6
M币
-496
专家
-1
粉丝
0
只看该作者 3楼 发表于: 2015-08-03
Re:求助    有没有人可以在19位万年历帮我加个DS12C887+程序  ..
怎么感觉你是出来秀的。
离线一缕阳光

发帖
1727
M币
2621
专家
10
粉丝
42
只看该作者 4楼 发表于: 2015-08-03
回 z576421511 的帖子
z576421511:怎么感觉你是出来秀的。 (2015-08-03 09:35) 回 z576421511 的帖子

确实是求助   希望有人可以帮帮我   现在断电就没有时间了
离线benli

发帖
33704
M币
6633
专家
91
粉丝
484
只看该作者 5楼 发表于: 2015-08-03
Re:求助    有没有人可以在19位万年历帮我加个DS12C887+程序  ..
交作业??????
离线一缕阳光

发帖
1727
M币
2621
专家
10
粉丝
42
只看该作者 6楼 发表于: 2015-08-03
回 benli 的帖子
benli:交作业?????? (2015-08-03 17:38) 回 benli 的帖子

不是啊   我自己用的   没读书好多年了
快速回复
限80 字节
“新手上路”发帖需审核后才能显示(请认真发帖),达到数码9级后取消此限制
 
上一个 下一个