#include<STC15F2K60S2.h>
#include "ds18b20.h"
#define uchar unsigned char
#define uint unsigned int
uchar code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6};
uchar yi,er,san,si,wu,liu,qi,ba;
uchar mode=1;
uchar time=0;
uchar tt=0;
uint miao=0;
bit wendu=0;
void allinit(void);
void display1(uchar yi,uchar er);
void display2(uchar san,uchar si);
void display3(uchar wu,uchar liu);
void display4(uchar qi,uchar ba);
void delay(uint ms);
void keyscan(void);
void Timer0Init(void);
void main(void)
{
allinit();
Timer0Init();
yi=10;er=1;san=10;si=11;wu=0;liu=0;qi=5;ba=0;
while(1)
{
if(wendu==0)
{
yi=10;er=mode;san=10;si=11;wu=time/1000;liu=time%1000/100;qi=time%100/10;ba=time%10;
}
else if(wendu==1)
{
yi=10;er=4;san=10;si=11;wu=11;liu=Tempget()/10;qi=Tempget()%10;ba=12;
}
if(time>0)
{
if(mode==1)
{
P2=0x80;P0=0xfe;
}
if(mode==2)
{
P2=0x80;P0=0xfd;
}
if(mode==3)
{
P2=0x80;P0=0xfb;
}
}
if(time==0)
{
P2=0x80;P0=0xff;
}
keyscan();
display1(yi,er);
display2(san,si);
display3(wu,liu);
display4(qi,ba);
}
}
void allinit(void)
{
P2=0xa0;
P0=0x00;
P2=0x80;
P0=0xff;
}
void display1(uchar yi,uchar er)
{
P2=0xc0;
P0=0x01;
P2=0xff;
P0=tab[yi];
delay(1);
P2=0xc0;
P0=0x02;
P2=0xff;
P0=tab[er];
delay(1);
}
void display2(uchar san,uchar si)
{
P2=0xc0;
P0=0x04;
P2=0xff;
P0=tab[san];
delay(1);
P2=0xc0;
P0=0x08;
P2=0xff;
P0=tab[si];
delay(1);
}
void display3(uchar wu,uchar liu)
{
P2=0xc0;
P0=0x10;
P2=0xff;
P0=tab[wu];
delay(1);
P2=0xc0;
P0=0x20;
P2=0xff;
P0=tab[liu];
delay(1);
}
void display4(uchar qi,uchar ba)
{
P2=0xc0;
P0=0x40;
P2=0xff;
P0=tab[qi];
delay(1);
P2=0xc0;
P0=0x80;
P2=0xff;
P0=tab[ba];
delay(1);
P2=0xc0;
P0=0xff;
P2=0xff;
P0=0xff;
}
void delay(uint ms)
{
uint i,j;
for(i=ms;i>0;i--)
for(j=845;j>0;j--);
}
void keyscan(void)
{
if(P30==0)
{
delay(5);
if(P30==0)
{
wendu=~wendu;
}
while(!P30);
}
if(P31==0)
{
delay(5);
if(P31==0)
{
time=0;
}
while(!P31);
}
if(P32==0)
{
delay(5);
if(P32==0)
{
if(time==0)time=60;
else if((time<=60)&&(time>0))time=120;
else if((time<=120)&&(time>60))time=0;
}
while(!P32);
}
if(P33==0)
{
delay(5);
if(P33==0)
{
if(mode==1)mode=2;
else if(mode==2)mode=3;
else if(mode==3)mode=1;
}
while(!P33);
}
}
void Timer0Init(void)
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xAE;
TH0 = 0xFB;
TF0 = 0;
TR0 = 1;
ET0=1;
EA=1;
}
void Timer0() interrupt 1
{
tt++;miao++;
if(tt==11)tt=1;
if(time>0)
{
if(mode==1)
{
if(tt<3)P34=1;
else P34=0;
}
else if(mode==2)
{
if(tt<4)P34=1;
else P34=0;
}
else if(mode==3)
{
if(tt<8)P34=1;
else P34=0;
}
}
if(miao==10000)
{
if(time>0)time--;
miao=0;
}
} |