标题:求助:时钟程序,执行出错
只看楼主
lb4417
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-7-27
结帖率:0
已结贴  问题点数:20 回复次数:1 
求助:时钟程序,执行出错
问题:到了09月01后,自动跳到12月02,然后一直执行到年份加一年,可到了下一年的2月01,又跳到12月了。请大家帮帮忙,看看究竟哪里出问题了?谢谢!
程序:
#include<reg51.h>
#define uint unsigned int
#define uchar unsigned char
sbit lcdrw=P2^5;
sbit lcdrs=P2^6;
sbit lcden=P2^7;
uchar code table1[]="2012-07-26";
uchar year=12,month=07,day=26,gnsz,num,snum;
void delayms(uchar ms)
{
    uint i,j;
    for(i=ms;i>0;i--)
        for(j=110;j>0;j--);
}
void write_com(uchar com)
{
    lcdrw=0;
    lcdrs=0;
    P0=com;
    delayms(2);
    lcden=1;
    delayms(5);
    lcden=0;        
}
void write_date(uchar date)
{
    lcdrw=0;
    lcdrs=1;
    P0=date;
    delayms(2);
    lcden=1;
    delayms(5);
    lcden=0;
}
void init()
{
    lcden=0;
    write_com(0x38);
    write_com(0x0c);
    write_com(0x06);
    write_com(0x01);
    TMOD=0X01;
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    EA=1;
    ET0=1;
    TR0=1;
    write_com(0x80+0x03);
    for(num=0;num<10;num++)
    {
        write_date(table1[num]);
        delayms(5);
    }
}
void write_ymd(uchar add,uchar date)
{
    uchar shi,ge;
    shi=date/10;
    ge=date%10;
    write_com(0x80+add);
    write_date(0x30+shi);
    write_date(0x30+ge);
}
void main()
{
   
    init();
    while(1);
    {
        
    }        
   
}
void T0_time() interrupt 1
{
    TH0=(65535-50000)/256;
    TL0=(65535-50000)%256;
    snum++;
    if(snum==20)
          {
              snum=0;
            day++;
            if((month==1)||(month==3)||(month==5)||(month==7)||(month==8)||(month==10)||(month=12))
            {
                if(day>31)
                {
                    day=1;
                    month++;
                }   
            }
            if((month==4)||(month==6)||(month==9)||(month==11))  
            {
                 if(day>30)
                {
                    day=1;
                    month++;
                }
            }
            if(month==2)
            {
                if(year%4==0)
                {
                    if(day>29)
                    {
                        day=1;
                        month++;
                    }
                }
                else
                {
                    if(day>28)
                    {
                        day=1;
                        month++;   
                       }
                }
              }
            if(month>12)
            {
                month=1;
                year++;
            }
            write_ymd(0x0b,day);
            write_com(0x80+0x0b);
                    
            write_ymd(0x08,month);
            write_com(0x80+0x08);
            
            write_ymd(0x05,year);
            write_com(0x80+0x05);
            
        }   
}  
  
搜索更多相关主题的帖子: void include 
2012-07-27 22:39
wenyboy
Rank: 2
等 级:论坛游民
帖 子:4
专家分:20
注 册:2012-7-4
得分:20 
指针是不是用的正确?!
2012-07-28 13:53



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-374254-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.088417 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved