- #include<STC15F2K60S2.h>
- #include<DS1302.H>
- #include<DS18B20.h>
- #include<KEY.H>
- unsigned char discom=0;
- unsigned char shuma[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};
- unsigned char disbuff[]={10,10,10,10,10,10,10,10};
- unsigned char flag=1;
- unsigned char jiange,keyzhi,shi,fen,miao,caiflag=0,wancheng=0, Lflag=0x00;
- unsigned char wendu[10];
- void display()
- {
-
- P2=0xe0;
- P0=0xff;
- P2=0x1f;
- P2=0xc0;
- P0=(1<<discom);
- P2=0x1f;
- P0=0xff;
- P2=0xe0;
- P0=shuma[disbuff[discom]];
- P2=0x1f;
- if(++discom==8)
- {
- discom=0;
- }
- }
- void comment()
- {
- P2=0XA0;
- P0=0X00;
- P2=0X1F;
-
- P2=0X80;
- P0=0XFF;
- P2=0X1F;
- }
- void Timer0Init() //1毫秒@11.0592MHz
- {
- AUXR |= 0x80; //定时器时钟1T模式
- TMOD &= 0xF0; //设置定时器模式
- TL0 = 0xCD; //设置定时初值
- TH0 = 0xD4; //设置定时初值
- TF0 = 0; //清除TF0标志
- TR0 = 1; //定时器0开始计时
- EA=1;
- ET0=1;
- }
- void Timer0() interrupt 1
- {
- unsigned int tt=0,a=0,t=0;
- display();
- if(caiflag==1)
- {
- tt++;
- if(tt==jiange*1000)
- {
- tt=0;
- wendu[a]=DS18B20read();
- a++;
- if(a==10)
- {
- a=0;
- caiflag=0;
- wancheng=1;
- }
- }
- }
- if(wancheng==1)
- {
- t++;
- if(t==500)
- {
- t=0;
- Lflag=~(Lflag);
- }
-
-
- }
-
- }
- void main()
- {
- comment();
- Ds1302init();
- Timer0Init();
- while(1)
- {
- disbuff[0]=10;
- disbuff[1]=10;
- disbuff[2]=10;
- disbuff[3]=10;
- disbuff[4]=10;
- disbuff[5]=11;
- disbuff[6]=jiange/10;
- disbuff[7]=jiange%10;
- keyzhi=keyscan();
- switch (flag)
- {
- case 1:jiange=1;break;
- case 2:jiange=5;break;
- case 3:jiange=30;break;
- case 4:jiange=60;break;
- }
- if(keyzhi==4)
- {
- flag++;
- if(flag==5)
- flag=1;
- }
- if(keyzhi==5)
- {
- caiflag=1;
- while (wancheng==0)
- {
- shi=Ds1302_Single_Byte_Read(0x85);
- fen=Ds1302_Single_Byte_Read(0x83);
- miao=Ds1302_Single_Byte_Read(0x81);
- disbuff[0]=shi/16;
- disbuff[1]=shi%16;
-
- disbuff[3]=fen%16;
- disbuff[4]=fen/16;
-
- disbuff[6]=miao/16;
- disbuff[7]=miao%16;
- if(miao%2==0){disbuff[2]=11;disbuff[5]=11;}
- else {disbuff[2]=10;disbuff[5]=10;}
- }
- }
-
- if(wancheng==1)
- {
- while(1)
- { if(Lflag==0xff)
- {
- P0=0xff;
- P2=0x80;
- P0=0xfe;
- P2=0x1f;
- }
- else
- {
- P0=0xff;
- P2=0x80;
- P0=0xff;
- P2=0x1f;
- }
- disbuff[0]=11;
- disbuff[1]=0;
- disbuff[2]=0;
- disbuff[3]=10;
- disbuff[4]=10;
- disbuff[5]=11;
- disbuff[6]=wendu[0]/10;
- disbuff[7]=wendu[0]%10;
- keyzhi=keyscan();
-
- }
- }
- }
- }
复制代码
|