应该是万年历的程序出问题了。也就是计算农历的程序错了,如果是能修改程序的话,是可以修改过来日期的。但是,电子万年历的程序已经固化到硬件里面了,所以,基本不可能修改了,除非找到厂家给你换芯片。
#include<stdioh>
#include<windowsh>
int menu()
{
char ch;
int x;
system("cls");
printf("请选择相应的菜单:\n");
printf("\n");
printf("查询某年某月某日是星期几,输入1回车:\n");
printf("查询某年是否是闰年,输入2回车:\n");
printf("打印某年的全年日历,输入3回车:\n");
printf("退出,输入0回车:\n");
printf("\n");
scanf("%d",&x);
if(x==0)
{
printf("确认退出 Y/N ");
ch=getchar();
scanf("%c",&ch);
if(ch=='Y')
exit(0);
else
main();
}
return x;
}
int judge_week(year,mon,day)
{
int sum,i,flag=0;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
sum=30(mon-1)+day;
for(i=1;i<=mon-1;i++)
{
if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
sum+=1;
if(i==2)
{
if(flag==1)
sum-=1;
if(flag==0)
sum-=2;
}
}
return sum;
}
look_week()
{
int year,mon,day,C,S,k;
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要查询的年月日\nyear month day\n");
scanf("%d %d %d",&year,&mon,&day);
if(year<0 || mon<0 || mon>12 || day<0 || day>31)
{
system("cls");
printf("输入的年月日不正确,请重新输入!");
Sleep(3000);
look_week();
}
C=judge_week(year,mon,day);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
system("cls");
printf("\n%d年%d月%d日是星期%s\n\n",year,mon,day,week[k]);
printf("是否要继续查询 Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_week();
else
main();
}
look_runnian()
{
int flag=0,year;
char ch;
system("cls");
printf("请输入要查询的年份: ");
scanf("%d",&year);
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
system("cls");
if(flag==1)
printf("%d是润年\n",year);
else
printf("%d不是润年\n",year);
printf("是否要继续查询 Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
look_runnian();
else
main();
}
print_calendar()
{
int i,j=0,k,C,S,flag=0,m,year,mon,d[31];
char ch,week[7][3]={"日","一","二","三","四","五","六"};
system("cls");
printf("请输入要打印日历的年、月:\nyear month\n");
scanf("%d %d",&year,&mon);
C=judge_week(year,mon,1);
S=year-1+(year-1)/4+(year-1)/100+(year-1)/400+C+2;
if(year<=2000 && year>=1901)
S=S+2;
else if(year<=1900)
S+=4;
k=S%7;
if(year%400==0)
flag=1;
else if(year%4==0 && year%100!=0)
flag=1;
if(mon==1 || mon==3 || mon==5 || mon==7 || mon==8 || mon==10 || mon==12)
m=31;
else if(mon==2)
{
if(flag==1)
m=29;
if(flag==0)
m=28;
}
else
m=30;
for(i=1;i<=m;i++)
d[j++]=i;
system("cls");
printf("%d年%d月的日历如下:\n\n",year,mon);
for(i=0;i<7;i++)
printf("%s\t",week[i]);
putchar(10);
for(i=0;i<k;i++)
printf("\t");
j=k;
for(i=0;i<m;i++)
{
printf("%d\t",d[i]);
j++;
if(j%7==0)
putchar(10);
}
printf("\n\n是否要继续查询 Y/N ");
getchar();
ch=getchar();
if(ch=='Y')
print_calendar();
else
main();
}
main()
{
int a;
a=menu();
switch(a)
{
case 1:look_week();break;
case 2:look_runnian();break;
case 3:print_calendar();break;
default:
{
printf("输入有误,请重新选择相应的菜单:\n");
Sleep(3000);
main();
}
}
}
CD BIT P12;用于液晶
W BIT P36
R BIT P37
CE BIT P17
DATA1 EQU 43H;第一参数
DATA2 EQU 44H;第二参数
COM EQU 45H;命令寄存器
;
ORG 0000H
jmp MAIN
ORG 0100H
;
MAIN:
;;;;;;;;;;;;;;;;;;;液晶初始化;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV COM,#80H ;SET or 模式命令
LCALL WRITEDATA3
NOP
MOV DATA1,#00H ;SET TEXT HOME AREA ADDRESS 1000H
MOV DATA2,#10H
MOV COM,#40H
LCALL WRITEDATA
NOP
MOV DATA1,#1EH ;SET TEXT AREA ADDRESS 001EH
MOV DATA2,#00H
MOV COM,#41H
LCALL WRITEDATA
NOP
MOV DATA1,#00H ;SET GRAPHIC HOME AREA ADDRESS 2000H
MOV DATA2,#20H
MOV COM,#42H
LCALL WRITEDATA
NOP
MOV DATA1,#1EH ;SET GRAPHIC AREA ADDRESS 001EH
MOV DATA2,00H
MOV COM,#43H
LCALL WRITEDATA
NOP
MOV DATA1,#0FH ;SET OFFSET REGISTER 000FH
MOV DATA2,#00H
MOV COM,#22H
LCALL WRITEDATA
NOP
MOV DATA1,#00H ;SET ADDRESS POINTER 7C00H
MOV DATA2,#7CH
MOV COM,#24H
LCALL WRITEDATA
NOP
MOV COM,#9CH ;SET TEXT ON,GRAPHIC ON
LCALL WRITEDATA3
NOP
;
以上就是关于基于51单片机,DS1302,1602实现万年历(年月日时分秒)及闹钟功能的C程序,不要显示农历和温度,谢谢!!全部的内容,包括:基于51单片机,DS1302,1602实现万年历(年月日时分秒)及闹钟功能的C程序,不要显示农历和温度,谢谢!!、C51单片机的万年历程序设计、电子万年历公历和农历对不上了,是怎么回事等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)