赞
踩
创新:显示时间和日期;有音乐背景等。
任务区分:
A——早晨起床、上午上课准备、下午上课准备、晚上熄灯准备播放不同的音乐。
B——早晨起床、上午上课准备、下午上课准备、晚上熄灯准备在显示屏上文字提示。
主程序:
- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit key1=P1^0;
- sbit key2=P1^1;
- sbit key3=P1^2;
- sbit rs=P2^0;
- sbit rw=P2^1;
- sbit en=P2^2;
- sbit light=P2^6;
- sbit sound=P2^7;
- int a,b,i,j,min,hour,minge,minshi,hourge,hourshi,sec=0,secge,secshi,cnt,cnt1,nian=2022,yue=11,ri=19;
- int xdata
- amin1=00,ahour1=6,aminge1,aminshi1,ahourge1,ahourshi1,
- amin2=45,ahour2=6,aminge2,aminshi2,ahourge2,ahourshi2,
- amin3=45,ahour3=7,aminge3,aminshi3,ahourge3,ahourshi3,
- amin4=00,ahour4=10,aminge4,aminshi4,ahourge4,ahourshi4,
- amin5=00,ahour5=12,aminge5,aminshi5,ahourge5,ahourshi5,
- amin6=15,ahour6=14,aminge6,aminshi6,ahourge6,ahourshi6,
- amin7=30,ahour7=14,aminge7,aminshi7,ahourge7,ahourshi7,
- amin8=00,ahour8=21,aminge8,aminshi8,ahourge8,ahourshi8,
- amin9=30,ahour9=21,aminge9,aminshi9,ahourge9,ahourshi9;
-
- uchar code table1[]={'0','1','2','3','4','5','6','7','8','9'};
- uchar code table2[]={"Time:00:00"};
- uchar xdata tips[]={"Tips:"};
- uchar xdata Date[]={"Date:"};
- uchar xdata clock_0[]={" "};
- uchar xdata clock_1[]={"clock:06:00"};
- uchar xdata clock_2[]={"clock:06:45"};
- uchar xdata clock_3[]={"clock:07:45"};
- uchar xdata clock_4[]={"clock:10:00"};
- uchar xdata clock_5[]={"clock:12:00"};
- uchar xdata clock_6[]={"clock:14:15"};
- uchar xdata clock_7[]={"clock:14:30"};
- uchar xdata clock_8[]={"clock:21:00"};
- uchar xdata clock_9[]={"clock:21:30"};
- uchar xdata qc[]={"ZCQC"};
- uchar xdata sk1[]={"SWSK"};
- uchar xdata sk2[]={"XWSK"};
- uchar xdata xd[]={"XDJQ"};
- uchar xdata rest[]={"Rest"};
- uchar xdata clock[]={"CLOCK"};
- uchar xdata riqi[]={"2022-11-19"};
-
-
- void delay(unsigned int z)
- {
- uint i,j;
- for(i=z;i>0;i--)
- for(j=110;j>0;j--);
- }
- void write_com(uchar com)
- {
- en=0;
- rw=0;
- rs=0;
- P0=com;
- en=1;
- delay(5);
- en=0;
- }
- void write_data(uchar date)
- {
- en=0;
- rw=0;
- rs=1;
- P0=date;
- en=1;
- delay(5);
- en=0;
- }
- void write_nian(uchar add,uint date)
- {
- uchar qian,bai,shi,ge;
- qian=date/1000;
- bai=(date-qian*1000)/100;
- shi=(date-qian*1000-bai*100)/10;
- ge=date%10;
- write_com(0x80+0x40+add);
- write_data(table1[qian]);
- write_data(table1[bai]);
- write_data(table1[shi]);
- write_data(table1[ge]);
- }
- void write_yue(uchar add,uint date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- write_com(0x80+0x40+add);
- write_data(0x30+shi);
- write_data(0x30+ge);
- }
- void write_ri(uchar add,uint date)
- {
- uchar shi,ge;
- shi=date/10;
- ge=date%10;
- write_com(0x80+0x40+add);
- write_data(0x30+shi);
- write_data(0x30+ge);
- }
- void qi()
- {
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_nian(5,nian);
- write_yue(10,yue);
- write_ri(13,ri);
- write_com(0x80+0x40+12);
- write_data('-');
- write_com(0x80+0x40+9);
- write_data('-');
-
- }
- void tip()
- {
- if(hour>=0&&hour<5)
- {
- write_com(0x80+20+5);
- for(i=0;i<4;i++)
- write_data(xd[i]);
- }
- else
- if(hour>=5&&hour<7)
- {
- write_com(0x80+20+5);
- for(i=0;i<4;i++)
- write_data(qc[i]);
- }
- else
- if(hour>=7&&hour<12)
- {
- write_com(0x80+20+5);
- for(i=0;i<4;i++)
- write_data(sk1[i]);
- }
- else
- if(hour>=12&&hour<14)
- {
- write_com(0x80+20+5);
- for(i=0;i<4;i++)
- write_data(rest[i]);
- }
- else
- if(hour>=14&&hour<18)
- {
- write_com(0x80+20+5);
- for(i=0;i<4;i++)
- write_data(sk2[i]);
- }
- else
- if(hour>=18&&hour<24)
- {
- write_com(0x80+20+5);
- for(i=0;i<4;i++)
- write_data(xd[i]);
- }
- }
-
- void show()
- {
- if(ahour1==hour&&amin1==min)
- {
- tip();
- }
- else
- if(ahour2==hour&&amin2==min)
- {
- tip();
- }
- else
- if(ahour3==hour&&amin3==min)
- {
- tip();
- }
- else
- if(ahour4==hour&&amin4==min)
- {
- tip();
- }
- else
- if(ahour5==hour&&amin5==min)
- {
- tip();
- }
- else
- if(ahour6==hour&&amin6==min)
- {
- tip();
- }
- else
- if(ahour7==hour&&amin7==min)
- {
- tip();
- }
- else
- if(ahour8==hour&&amin8==min)
- {
- tip();
- }
- else
- if(ahour9==hour&&amin9==min)
- {
- write_com(0x80+20+5);
- for(i=0;i<11;i++)
- write_data(clock_9[i]);
- }
- else
- write_com(0x80+20+5);
- for(i=0;i<11;i++)
- write_data(clock_0[i]);
-
- }
-
- void time()
- {
- while(1)
- {
- if(key1==0)
- {
-
- if(key1==0)
- {
- if(hour==23)
- hour=0;
- else
- hour++;
- hourge=hour%10;
- hourshi=hour/10;
- write_com(0x0f);
- delay(2);
- write_com(0x80+6);
- write_data(table1[hourge]);
- delay(5);
- write_com(0x80+5);
- delay(2);
- write_data(table1[hourshi]);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(min==59)
- min=0;
- else
- min++;
- minge=min%10;
- minshi=min/10;
- write_com(0x0f);
- write_com(0x80+9);
- write_data(table1[minge]);
- delay(1);
- write_com(0x80+8);
- write_data(table1[minshi]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
- delay(10);
- if(key3==0)
- {
- write_com(0x0c);
- TR1=1;
- while(!key3);
- break;
- }
- }
- }
- }
-
- void display1()//set clock time 1
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour1==23)
- ahour1=0;
- else
- ahour1++;
- ahourge1=ahour1%10;
- ahourshi1=ahour1/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge1]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi1]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin1==59)
- amin1=0;
- else
- amin1++;
- aminge1=amin1%10;
- aminshi1=amin1/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge1]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi1]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
-
- void display2()//set clock time 2
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour2==23)
- ahour2=0;
- else
- ahour2++;
- ahourge2=ahour2%10;
- ahourshi2=ahour2/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge2]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi2]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin2==59)
- amin2=0;
- else
- amin2++;
- aminge2=amin2%10;
- aminshi2=amin2/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge2]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi2]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
-
- void display3()//set clock time 3
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour3==23)
- ahour3=0;
- else
- ahour3++;
- ahourge3=ahour3%10;
- ahourshi3=ahour3/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge3]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi3]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin3==59)
- amin3=0;
- else
- amin3++;
- aminge3=amin3%10;
- aminshi3=amin3/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge3]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi3]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
-
- void display4()//set clock time 4
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour4==23)
- ahour4=0;
- else
- ahour4++;
- ahourge4=ahour4%10;
- ahourshi4=ahour4/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge4]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi4]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin4==59)
- amin4=0;
- else
- amin4++;
- aminge4=amin4%10;
- aminshi4=amin4/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge4]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi4]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
-
- void display5()//set clock time 5
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour5==23)
- ahour5=0;
- else
- ahour5++;
- ahourge5=ahour5%10;
- ahourshi5=ahour5/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge5]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi5]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin5==59)
- amin5=0;
- else
- amin5++;
- aminge5=amin5%10;
- aminshi5=amin5/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge5]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi5]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
-
- void display6()//set clock time 6
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour6==23)
- ahour6=0;
- else
- ahour6++;
- ahourge6=ahour6%10;
- ahourshi6=ahour6/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge6]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi6]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin6==59)
- amin6=0;
- else
- amin6++;
- aminge6=amin6%10;
- aminshi6=amin6/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge6]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi6]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
- }
- }
- }
-
- void display7()//set clock time 7
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour7==23)
- ahour7=0;
- else
- ahour7++;
- ahourge7=ahour7%10;
- ahourshi7=ahour7/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge7]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi7]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin7==59)
- amin7=0;
- else
- amin7++;
- aminge7=amin7%10;
- aminshi7=amin7/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge7]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi7]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
-
- void display8()//set clock time 8
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour8==23)
- ahour8=0;
- else
- ahour8++;
- ahourge8=ahour8%10;
- ahourshi8=ahour8/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge8]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi8]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin8==59)
- amin8=0;
- else
- amin8++;
- aminge8=amin8%10;
- aminshi8=amin8/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge8]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi8]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
- void display9()//set clock time 9
- {
- while(1)
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- if(ahour9==23)
- ahour9=0;
- else
- ahour9++;
- ahourge9=ahour9%10;
- ahourshi9=ahour9/10;
- write_com(0x0f);
- write_com(0x80+0x40+8);
- write_data(':');
- write_com(0x80+0x40+7);
- write_data(table1[ahourge9]);
- delay(1);
- write_com(0x80+0x40+6);
- write_data(table1[ahourshi9]);
- delay(1);
- while(!key1);
- }
- }
- if(key2==0)
- {
- delay(10);
- if(key2==0)
- {
- if(amin9==59)
- amin9=0;
- else
- amin9++;
- aminge9=amin9%10;
- aminshi9=amin9/10;
- write_com(0x0f);
- write_com(0x80+0x40+10);
- write_data(table1[aminge9]);
- delay(1);
- write_com(0x80+0x40+9);
- write_data(table1[aminshi9]);
- delay(1);
- while(!key2);
- }
- }
- if(key3==0)
- {
-
-
- write_com(0x0c);
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- while(!key3);
- break;
-
- }
- }
- }
- void keyscan()//keyscan
- {
- if(key1==0)
- {
- delay(10);
- if(key1==0)
- {
- while(!key1);
- time();
- }
- }
- else
- if(key2==0)
- {
- cnt1++;
- delay(10);
- if(cnt1==1)
- {
- while(!key2)
- {
- ahourge1=ahour1%10;
- ahourshi1=ahour1/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge1]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi1]);
- aminge1=amin1%10;
- aminshi1=amin1/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge1]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi1]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_1[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
-
- }
- if(cnt1==2)
- {
- while(!key2)
- {
- ahourge2=ahour2%10;
- ahourshi2=ahour2/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge2]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi2]);
- aminge2=amin2%10;
- aminshi2=amin2/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge2]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi2]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_2[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==3)
- {
- while(!key2)
- {
- ahourge3=ahour3%10;
- ahourshi3=ahour3/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge3]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi3]);
- aminge3=amin3%10;
- aminshi3=amin3/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge3]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi3]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_3[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==4)
- {
- while(!key2)
- {
- ahourge4=ahour4%10;
- ahourshi4=ahour4/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge4]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi4]);
- aminge4=amin4%10;
- aminshi4=amin4/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge4]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi4]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_4[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==5)
- {
- while(!key2)
- {
- ahourge5=ahour5%10;
- ahourshi5=ahour5/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge5]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi5]);
- aminge4=amin4%10;
- aminshi4=amin4/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge5]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi5]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_5[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==6)
- {
- while(!key2)
- {
- ahourge6=ahour6%10;
- ahourshi6=ahour6/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge6]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi6]);
- aminge6=amin6%10;
- aminshi6=amin6/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge6]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi6]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_6[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==7)
- {
- while(!key2)
- {
- ahourge7=ahour7%10;
- ahourshi7=ahour7/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge7]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi7]);
- aminge7=amin7%10;
- aminshi7=amin7/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge7]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi7]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_7[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==8)
- {
- while(!key2)
- {
- ahourge8=ahour8%10;
- ahourshi8=ahour8/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge8]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi8]);
- aminge8=amin8%10;
- aminshi8=amin8/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge8]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi8]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_8[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1==9)
- {
- while(!key2)
- {
- ahourge9=ahour9%10;
- ahourshi9=ahour9/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge9]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi9]);
- aminge9=amin9%10;
- aminshi9=amin9/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge9]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi9]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_9[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- }
- write_com(0x80+0x40+0);
- for(i=0;i<5;i++)
- write_data(Date[i]);
- write_com(0x80+0x40+5);
- for(i=0;i<11;i++)
- write_data(riqi[i]);
- }
- if(cnt1>9)
- cnt1=0;
- }
- else if(key3==0)
- {
- cnt++;
- delay(10);
- if(cnt==1)
- {
- while(!key3);
- ahourge1=ahour1%10;
- ahourshi1=ahour1/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge1]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi1]);
- aminge1=amin1%10;
- aminshi1=amin1/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge1]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi1]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_1[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display1();
- }
- if(cnt==3)
- {
- while(!key3);
- ahourge2=ahour2%10;
- ahourshi2=ahour2/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge2]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi2]);
- aminge2=amin2%10;
- aminshi2=amin2/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge2]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi2]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_2[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display2();
- }
- if(cnt==5)
- {
- while(!key3);
- ahourge3=ahour3%10;
- ahourshi3=ahour3/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge3]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi3]);
- aminge3=amin3%10;
- aminshi3=amin3/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge3]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi3]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_3[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display3();
- }
- if(cnt==7)
- {
- while(!key3);
- ahourge4=ahour4%10;
- ahourshi4=ahour4/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge4]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi4]);
- aminge4=amin4%10;
- aminshi4=amin4/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge4]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi4]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_4[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display4();
- }
- if(cnt==9)
- {
- while(!key3);
- ahourge5=ahour5%10;
- ahourshi5=ahour5/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge5]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi5]);
- aminge5=amin5%10;
- aminshi5=amin5/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge5]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi5]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_5[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display5();
- }
- if(cnt==11)
- {
- while(!key3);
- ahourge6=ahour6%10;
- ahourshi6=ahour6/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge6]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi6]);
- aminge6=amin6%10;
- aminshi6=amin6/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge6]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi6]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_6[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display6();
- }
- if(cnt==13)
- {
- while(!key3);
- ahourge7=ahour7%10;
- ahourshi7=ahour7/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge7]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi7]);
- aminge7=amin7%10;
- aminshi7=amin7/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge7]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi7]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_7[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display7();
- }
- if(cnt==15)
- {
- while(!key3);
- ahourge8=ahour8%10;
- ahourshi8=ahour8/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge8]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi8]);
- aminge8=amin8%10;
- aminshi8=amin8/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge8]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi8]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_8[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display8();
- }
- if(cnt==17)
- {
- while(!key3);
- ahourge9=ahour9%10;
- ahourshi9=ahour9/10;
- write_com(0x80+0x40+7);
- write_data(table1[ahourge9]);
- delay(5);
- write_com(0x80+0x40+6);
- delay(2);
- write_data(table1[ahourshi9]);
- aminge9=amin9%10;
- aminshi9=amin9/10;
- write_com(0x80+0x40+10);
- write_data(table1[aminge9]);
- delay(5);
- write_com(0x80+0x40+9);
- delay(2);
- write_data(table1[aminshi9]);
- write_com(0x80+0x40);
- for(i=0;i<11;++i)
- write_data(clock_9[i]);
- write_com(0x80+0x40+11);
- for(i=0;i<5;i++)
- write_data(clock_0[i]);
- display9();
- }
- if(cnt>20)
- {
- cnt=0;
- }
- }
-
-
- }
- void ruler()//
- {
- if(sec==60)
- {
- min++;
- sec=0;
- }
- if(min==60)
- {
- hour++;
- min=0;
- }
- if(hour==24)
- {
- ri++;
- hour=0;
- }
- if(ri==30)
- {
- yue++;
- ri=0;
- }
- if(yue==12)
- {
- nian++;
- yue=1;
- }
- }
-
- void init()//danpianji chushihua
- {
- key1=1;key2=1;key3=1;sec=0;sound=1;
- TMOD=0x10;
- TL1=0xB0;
- TH1=0x3C;//¼ÆÊý³õֵΪ15536
- EA=1;
- ET1=1;
- TR1=1;
- }
-
- void speak()// music
- {
- if(amin1==min&&ahour1==hour||amin2==min&&ahour2==hour||amin3==min&&ahour3==hour||amin4==min&&ahour4==hour||amin5==min&&ahour5==hour||amin6==min&&ahour6==hour||amin7==min&&ahour7==hour||amin8==min&&ahour8==hour||amin9==min&&ahour9==hour)
- {
- delay(5);
- sound=0;
-
- }
- delay(10);
- delay(10);
- delay(10);
- sound=1;
- }
- void led1() interrupt 3
- {
- TL1=0xB0;
- TH1=0x3C;
- speak();
- num1++;
- num2++;
- if(num2==20)
- {
- sec++;
- num2=0;
- ruler();
- }
-
- }
- void lcd_init()//lcd chushihua
- {
- en=0;
- rw=0;
- write_com(0x01);
- write_com(0x06);
- write_com(0x0c);
- write_com(0x38);
- delay(2);
- write_com(0x80);
- for(i=0;i<16;i++)
- {
- write_data(table2[i]);
- delay(1);
- }
- }
-
-
- void displays()
- {
- minge=min%10;
- minshi=min/10;
- write_com(0x80+9);
- write_data(table1[minge]);
- delay(5);
- write_com(0x80+8);
- write_data(table1[minshi]);
- hourge=hour%10;
- hourshi=hour/10;
- write_com(0x80+6);
- write_data(table1[hourge]);
- delay(5);
- write_com(0x80+5);
- write_data(table1[hourshi]);
- write_com(0x80+7);
- write_data(':');
- write_com(0x80+10);
- write_data(':');
- write_com(0x80+15);
- for(i=0;i<5;i++)
- write_data(clock[i]);
- delay(5);
- secge=sec%10;
- secshi=sec/10;
- write_com(0x80+12);
- write_data(table1[secge]);
- delay(5);
- write_com(0x80+11);
- write_data(table1[secshi]);
- write_com(0x80+20+0);
- for(i=0;i<5;i++)
- write_data(tips[i]);
- }
- void main()
- {
-
- lcd_init();
- init();
- while(1)
- {
- keyscan();
- displays();
- qi();
- show();
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。