📄 text1
字号:
case 0:inc_time();
break;
// case 1:
// break;
case 1:inc_clock();
break;
default:
break;
}
}
/****************时间加法子函数*****************/
void inc_time(void)
{
if(set==1)
{
hour++;
if(hour==24)
hour=0;
}
if(set==2)
{
minite++;
if(minite==60)
minite=0;
}
if(set==3)
{
second++;
if(second==60)
second=0;
}
if(set==4)
{
year++;
}
if(set==5)
{
month++;
if(month>12)
month=1;
}
if(set==6)
{
day++;
k1=dayjudge(year,month);
if(day>k1)
day=1;
}
}
/****************闹钟加法子函数*****************/
void inc_clock(void)
{
if(set1==1)
{
hourjudge[set]++;
if(hourjudge[set]>23)
hourjudge[set]=0;
}
if(set1==2)
{
minitejudge[set]++;
if(minitejudge[set]>59)
minitejudge[set]=0;
}
if(set1==0)
set++;
if(set>31)
set=0;
}
/****************按键减法子函数*****************/
void dec_key(void)
{
// set2--;
// if(set2<0)
// {set2=6;}
disturb=0;
switch(status)
{
case 0:dec_time();
break;
case 1:dec_clock();
break;
// case 2:dec_clock();
// break;
default:
break;
}
}
/****************时间减法子函数*****************/
void dec_time(void)
{
if(set==1)
{
hour--;
if(hour<0)
hour=23;
}
if(set==2)
{
minite--;
if(minite<0)
minite=59;
}
if(set==3)
{
second--;
if(second<0)
second=59;
}
if(set==4)
{
year--;
}
if(set==5)
{
month--;
if(month<1)
month=12;
}
if(set==6)
{
day--;
k1=dayjudge(year,month);
if(day<1)
day=k1;
}
}
/****************闹钟减法子函数*****************/
void dec_clock(void)
{
if(set1==1)
{
hourjudge[set]--;
if(hourjudge[set]<0)
hourjudge[set]=23;
}
if(set1==2)
{
minitejudge[set]--;
if(minitejudge[set]<0)
minitejudge[set]=59;
}
if(set1==0)
set--;
if(set<0)
set=31;
}
/****************当月天数判断子函数*****************/
int dayjudge(int year,int month)
{
int s,judge1;
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0)) /*判断当年是否为闰年*/
judge1=1;
else judge1=0;
if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)/*判断每月的天数*/
{s=31;
return(s);
}
if(month==4||month==6||month==9||month==11)
{s=30;
return(s);
}
if(month==2&&judge1==0)
{s=28;
return(s);
}
if(month==2&&judge1==1)
{s=29;
return(s);
}
}
/****************星期判断子函数*****************/
int date(int year,int month)
{
int a,c,d,judge;
int year1;
year1=year;
if(year>2000) for(a=1,year--;year>2000;year--) /*计算除当年外有几个闰年*/
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
a++;
if(year<2000) for(a=0,year++;year<2000;year++)
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
a++;
year=year1;
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0)) judge=1;/*判断当年是否为闰年*/
else judge=0;
if(month==1) d=0;
if(month==2) d=31;
if(month==3) d=59+judge;
if(month==4) d=90+judge;
if(month==5) d=120+judge;
if(month==6) d=151+judge;
if(month==7) d=181+judge;
if(month==8) d=212+judge;
if(month==9) d=243+judge;
if(month==10) d=273+judge;
if(month==11) d=304+judge;
if(month==12) d=334+judge; /*计算月份的天数差*/
/*计算当月一日是星期几*/
if(year<2000)
{
c=((2000-year)*365+a+judge-d-day)%7;
switch(c)
{
case 0: c=5;break;
case 1: c=4;break;
case 2: c=3;break;
case 3: c=2;break;
case 4: c=1;break;
case 5: c=0;break;
case 6: c=6;break;
}
}
if(year==2000)
{
if((month==1)&&(day==1)) c=6;
else c=(day+d-2)%7;
}
if(year>2000) c=((year-2000)*365+a+d+day-2)%7;
return(c);
}
/****************年的转换子函数*****************/
int yearchange(int year)
{
s1=year/1000;
s2=(year-s1*1000)/100;
s3=(year-s1*1000-s2*100)/10;
s4=year-s1*1000-s2*100-s3*10;
}
/***************定时器t1初始化*******************/
void init_timer1(void)
{
TMOD=0x11; //time1为定时器,方式1
TH1=0x3c; //预置计数初值
TL1=0xb0;
ET1=1;
}
/***********定时器t0中断子函数**************/
void timer1(void) interrupt 3 using 3 //定时器1方式1,50ms中断一次
{
TH1=0x3c;
TL1=0xb0;
mstcnt1++;
if(disturb==1)
{
if(ss==0)
{
if(mstcnt1>=100)
{
speaker=0; //蜂鸣器关
mstcnt1=0;
ss=1;
}
}
if(ss==1)
{
if(mstcnt1>=40)
{
speaker=1;
mstcnt1=0;
ss=2;
}
}
if(ss==2)
{
if(mstcnt1>=100)
{
mstcnt1=0;
speaker=0;
ss=0;
TR1=0;
}
}
}
if(disturb==0)
{ speaker=0; TR1=0;ss=0; }
}
/***************定时器t0初始化*******************/
void init_timer0(void)
{
TMOD=0x01; //time0为定时器,方式1
TH0=0x3c; //预置计数初值
TL0=0xb0;
EA=1;
ET0=1;
TR0=1;
}
/***********定时器t0中断子函数**************/
void timer0(void) interrupt 1 using 0 //定时器0方式1,50ms中断一次
{
TH0=0x3c;
TL0=0xb0;
mstcnt0++;
if(mstcnt0>=20 )
{
second++;
mstcnt0=0;
}
if(second>59)
{
minite++;
second=0;
for(n=0;n<32;n++)
{
if((hourjudge[n]==hour)&&(minitejudge[n]==minite))
{
mstcnt1=0;
disturb=1;
TR1=1;
TH1=0x3c;
TL1=0xb0;
speaker=1;
}
}
}
if(minite>59)
{
hour++;
minite=0;
}
if(hour>23)
{
// week1++;
day++;
hour=0;
k=dayjudge(year,month);
if(status==0)
{
weekjudge=date(year,month);
if(weekjudge==0)
{
weekjudge=7;
}
DisplayOneChar(15,0,weekjudge+0x30);
}
if(day>k)
{
month++;
}
if(month>12)
{
year++;
month=0;
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
{DisplayListChar(11,1,"RUN ");}
else DisplayListChar(11,1,"PING");
}
}
}
/**********主程序*************/
void main(void)
{
speaker=0;
P1=0xff; //初始化p1口,全设为1
// week1=date(year,month);
delay(500); //延时500ms启动
LCDInit( ); //LCD初始化
init_timer0( );
init_timer1(); //时钟定时器0和1初始化
while (1)
{
keyscan();
}
}
void displaytime(void)
{
if(view==0)
{
view=1;
WriteCommand(0x01);
DisplayOneChar(2,1,0x3A);
DisplayOneChar(5,1,0x3A);
DisplayOneChar(7,0,0x2D);
DisplayOneChar(4,0,0x2D);
DisplayListChar(11,0,"Week");
weekjudge=date(year,month);
if(weekjudge==0)
{
weekjudge=7;
}
DisplayOneChar(15,0,weekjudge+0x30);
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
{DisplayListChar(11,1,"RUN ");}
else DisplayListChar(11,1,"PING");
// DisplayListChar(0,1,"Time:");
// DisplayListChar(0,0,"Date:");
}
if(set!=0)
{
TR0=0;
}
if(set>6)
{
set=0;
TR0=1;
mstcnt0=0;
// DisplayListChar(9,1,"Week")
weekjudge=date(year,month);
if(weekjudge==0)
{
weekjudge=7;
}
DisplayOneChar(15,0,weekjudge+0x30);
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
{DisplayListChar(11,1,"RUN ");}
else DisplayListChar(11,1,"PING");
}
switch(set) //LCD根据工作模式显示
{
case 0:displaytimejudge();//delay(800); //正常工作显示时间
break;
case 1:changehour();//delay(200); //调整分显示
break;
case 2:changeminite();//delay(1000); //调整时显示
break;
case 3:changesecond();//delay(1000); //调整时显示
break;
case 4:changeyear();//delay(1000);
break;
case 5:changemonth();//delay(1000);
break;
case 6:changeday();//delay(1000);
break;
default:
break;
}
delay(300);
} /*
void displaydate(void)
{
if(view==0)
{
WriteCommand(0x01);
view=1;
DisplayListChar(0,0,"Today is ");
}
DisplayListChar(9,0,week[date(year,month)]);
if((year%4==0&&year%100!=0)||(year%100==0&&year%400==0))
DisplayListChar(2,1,"Lesp year");
else DisplayListChar(1,1,"Non-Leap year");
} */
void displayclock(void)
{
if(view==0)
{
WriteCommand(0x01);
view=1;
DisplayListChar(0,0,"Set Clock:");
}
DisplayOneChar(11,1,0x3a);
DisplayOneChar(12,0,(set+1)/10+0x30);
DisplayOneChar(13,0,(set+1)%10+0x30);
switch(set1)
{
case 0:displayclockjudge();break;
case 1:displayclockjudge();
break;
case 2:displayclockjudge();break;
// case 3:displayclockjudge(); //WriteCommand(0x0f);WriteCommand(0x88+set2); delay(2000);
// break;
default:
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -