#include<stc15f2k60s2.h>
#include<intrins.h>
#include"onewire.h"
typedef unsigned int uint;
typedef unsigned char uchar;
uint smgduan[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff,0xc6};
uint yi,er,san,si,wu,liu,qi,ba;
uchar s7=0,s6=0,s5=0,s4=0;
void bzcsh();
void delay(uint ms);
void anjian();
void smgduan1(uint yi,uint er);
void smgduan2(uint san,uint si);
void smgduan3(uint wu,uint liu);
void smgduan4(uint qi,uint ba);
void Timer0Init(void); //5毫秒@11.0592MHz
void zd();
uint wendu;
uint moshi=1,sdsj=0;
uint tt=0,ttt=0,a=0;
void main()
{
bzcsh();
Timer0Init();
while(1)
{
anjian();
smgduan1( yi, er);
smgduan2( san, si);
smgduan3( wu, liu);
smgduan4( qi, ba);
wendu=ds18b20();
if(sdsj==0){EA=0;ET0=0;P2=0x80;P0=0xff;P34=0;}
if(s7==0)
{
if(sdsj!=0){EA=1;ET0=1;}
yi=10;er=moshi;san=10;si=11;wu=sdsj/1000;liu=sdsj/100%10;qi=sdsj/10%10;ba=sdsj%10;
if((moshi==1)&&(sdsj!=0)){P2=0x80;P0=0xfe;}
if((moshi==2)&&(sdsj!=0)){P2=0x80;P0=0xfd;}
if((moshi==3)&&(sdsj!=0)){P2=0x80;P0=0xfb;}
}
if(s7==1){yi=10;er=4;san=10;si=11;wu=11;liu=wendu/10;qi=wendu%10;ba=12;}
if(s5==1){s5=0;a++;if(a==3)a=0;if(a==1)sdsj=60;if(a==2)sdsj=120;if(a==0)sdsj=0;EA=0;ET0=0;}
if(s6==1){s6=0;sdsj=0;P34=0;}
if(s4==1){s4=0;moshi++;if(moshi==4)moshi=1;}
}
}
void Timer0Init(void) //100微秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0xAE; //设置定时初值
TH0 = 0xFB; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void zd() interrupt 1
{
tt++;ttt++;
if(tt==10000)
{
tt=0;
sdsj=sdsj-1;
}
if(moshi==1)
{
if(ttt<2){P34=1;}
if((ttt>=2)&&(ttt<10)){P34=0;}
}
if(moshi==2)
{
if(ttt<3){P34=1;}
if((ttt>=3)&&(ttt<10)){P34=0;}
}
if(moshi==3)
{
if(ttt<7){P34=1;}
if((ttt>=7)&&(ttt<10)){P34=0;}
}
if(ttt==10)ttt=0;
}
void bzcsh()
{
P2=0XA0;P0=0X00;
P2=0X80;P0=0XFF;
P2=0XC0;P0=0XFF;
P2=0XFF;P0=0XFF;
}
void delay(uint ms)
{
uint i,j;
for(i=0;i<ms;i++)
for(j=845;j>0;j--);
}
void anjian()
{
if(P30==0)
{
delay(7);
if(P30==0)
{
s7=!s7;
}
while(!P30);
}
if(P31==0)
{
delay(7);
if(P31==0)
{
s6=1;
}
while(!P31);
}
if(P32==0)
{
delay(7);
if(P32==0)
{
s5=1;
}
while(!P32);
}
if(P33==0)
{
delay(7);
if(P33==0)
{
s4=1;
}
while(!P33);
}
}
void smgduan1(uint yi,uint er)
{
P2=0XC0;
P0=0X01;
P2=0XFF;
P0=smgduan[yi];
delay(1);
P2=0XC0;
P0=0X02;
P2=0XFF;
P0=smgduan[er];
delay(1);
P2=0XC0;P0=0XFF;
P2=0XFF;P0=0XFF;
}
void smgduan2(uint san,uint si)
{
P2=0XC0;
P0=0X04;
P2=0XFF;
P0=smgduan[san];
delay(1);
P2=0XC0;
P0=0X08;
P2=0XFF;
P0=smgduan[si];
delay(1);
P2=0XC0;P0=0XFF;
P2=0XFF;P0=0XFF;
}
void smgduan3(uint wu,uint liu)
{
P2=0XC0;
P0=0X10;
P2=0XFF;
P0=smgduan[wu];
delay(1);
P2=0XC0;
P0=0X20;
P2=0XFF;
P0=smgduan[liu];
delay(1);
P2=0XC0;P0=0XFF;
P2=0XFF;P0=0XFF;
}
void smgduan4(uint qi,uint ba)
{
P2=0XC0;
P0=0X40;
P2=0XFF;
P0=smgduan[qi];
delay(1);
P2=0XC0;
P0=0X80;
P2=0XFF;
P0=smgduan[ba];
delay(1);
P2=0XC0;P0=0XFF;
P2=0XFF;P0=0XFF;
}
|