当前位置:首页 > 基于C51单片机为主控芯片的电子表(内附完整程序源码)
/* */ /* 闰年计算函数 */ /* */ /* 是闰年返回值为1 */ /**********************************************************************************/ int isleapyear(int year) {
year=year+2000; }
/**********************************************************************************/ /* */ /* */ /* 星期计算函数 */ /* */ /* 星期日返回值为0 */ /**********************************************************************************/ int week(int nian,int yue,int ri) { }
/**********************************************************************************/ /* */ /* */ /* 日期清零计算函数 */ /* */ /* 日期需要清零时返回值为1 */ /**********************************************************************************/ int delete_riqi(int ri) {
if(ri>28&&yue==2&&!isleapyear(nian)) return 1;
iWeek = y + y / 4 + c / 4 - 2 * c + 26 * ( m + 1 ) / 10 + d - 1; //蔡勒公式 iWeek = iWeek >= 0 ? ( iWeek % 7 ) : ( iWeek % 7 + 7 );
return iWeek;
//iWeek为负时取模
int iWeek,y,c,m,d;
c=nian/100; y=nian0; m=yue; d=ri;
return (year%4==0&&year0)||year@0==0;
}
/**********************************************************************************/ /* */ /* */ /* 1602液晶屏命令写入函数 */ /* */ /* */ /**********************************************************************************/ void write_com(uchar com) { }
/**********************************************************************************/ /* */ /* */ /* 1602液晶屏数据写入函数 */ /* */ /* */ /**********************************************************************************/ void write_date(uchar date) { }
rs=1; lcden=0; P0=date; delay(5); lcden=1; delay(5); lcden=0; rs=0; lcden=0; P0=com; delay(5); lcden=1; delay(5); lcden=0; if(ri>29&&yue==2) return 1;
if(ri>30&&(yue==4||yue==6||yue==9||yue==11)) return 1; if(ri>31) return 1; return 0;
/**********************************************************************************/ /* */ /* */ /* 初始化函数 */ /* */ /* */ /**********************************************************************************/ void init() { }
/**********************************************************************************/ /* */
uchar num; lcden=0; write_com(0x38); write_com(0x0c); write_com(0x06); write_com(0x01); write_com(0x80); nian=15; yue=5; ri=28; shi=0; fen=0; miao=0;
for(num=0;num<15;num++)
{ }
write_date(table[num]); delay(5);
write_com(0x80+0x40); for(num=0;num<12;num++)
{ }
write_date(table1[num]); delay(5);
TMOD=0x01;
TH0=(65536-50000)/256; TL0=(65536-50000)%6; EA=1; ET0=1; TR0=1;
/* */ /* 时间写入函数 */ /* */ /* */ /**********************************************************************************/ void write_sfm(uchar add,uchar date) { }
/**********************************************************************************/ /* */ /* */ /* 日期写入函数 */ /* */ /* */ /**********************************************************************************/ void write_nyr(uchar add,uchar date) { }
/**********************************************************************************/ /* */ /* */ /* 星期写入函数 */ /* */ /* */ /**********************************************************************************/ void write_xq(uchar week) {
write_com(0x80+12); write_date(table_w[week][0]); write_date(table_w[week][1]); uchar shi,ge; shi=date/10; ge=date; write_com(0x80+add); write_date(0x30+shi); write_date(0x30+ge); uchar shi,ge; shi=date/10; ge=date;
write_com(0x80+0x40+add); write_date(0x30+shi); write_date(0x30+ge);
共分享92篇相关文档