- #include<STC15F2K60S2.h>
- #include<DS1302.H>
- #include<DS18B20.h>
- #include<KEY.H>
- 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 discom=0;
- unsigned char keyzhi,Dtime=1,shi,fen,miao,suoyin=0;
- unsigned char Kflag=1,Cflag=0,CFflag=0,Lflag=0x00;
- unsigned char wendu[10];
- void display()
- {
- P0=0xff;
- P2=0xe0;
- P0=0xff;
- P2=0x1f;
- P0=0x00;
- 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;
- P0=0xff;
- 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
- {
- static unsigned int tt=0,a=0,t=0;
- display();
- if(Cflag==1)
- {
- tt++;
- if(tt==Dtime*1000)
- {
- tt=0;
- wendu[a]=DS18B20read();
- a++;
- if(a==10)
- {
- a=0;
- Cflag=0;
- CFflag=1;
- }
- }
- }
- if(CFflag==1)
- {
- t++;
- if(t==500)
- {
- t=0;
- Lflag=~(Lflag);
- }
- }
- }
- void main()
- {
- comment();
- Ds1302init();
- Timer0Init();
- while(1)
- {
- AA1: disbuff[0]=10;
- disbuff[1]=10;
- disbuff[2]=10;
- disbuff[3]=10;
- disbuff[4]=10;
- disbuff[5]=11;
- disbuff[6]=Dtime/10;
- disbuff[7]=Dtime%10;
- keyzhi=keyscan();
- switch(Kflag)
- {
- case 1:Dtime=1;break;
- case 2:Dtime=5;break;
- case 3:Dtime=30;break;
- case 4:Dtime=60;break;
- default:break;
- }
- if(keyzhi==4)
- {
- Kflag++;
- if(Kflag==5)
- Kflag=1;
- }
-
- if(keyzhi==5)
- {
- Cflag=1;
- while(CFflag==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(CFflag==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();
-
- if(keyzhi==6)
- {
- Lflag=0xcc;
- P0=0xff;
- P2=0x80;
- P0=0xff;
- P2=0x1f;
- while(CFflag)
- {
- disbuff[0]=11;
- disbuff[1]=0;
- disbuff[2]=suoyin;
- disbuff[3]=10;
- disbuff[4]=10;
- disbuff[5]=11;
- disbuff[6]=wendu[suoyin]/10;
- disbuff[7]=wendu[suoyin]%10;
- keyzhi=keyscan();
- if(keyzhi==6)
- {
- suoyin++;
- if(suoyin==10)
- suoyin=0;
- }
- if(keyzhi==7)
- {
- CFflag=0;
- Lflag=0x00;
- goto AA1;
- }
- }
- }
- }
- }
- }
- }
-
复制代码
|