全部文件:提取码:azxy
#include "STC15F2K60S2.h"
#include "ds1302.h"
#include "onewire.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit S4=P3^3;
sbit S5=P3^2;
sbit S6=P3^1;
sbit S7=P3^0;
extern unsigned char Time[3];
u8 code duan[12]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff,0xbf};
u8 sz[3];
u8 Time1[3]={0x00,0x00,0x00};
u8 nz[3];
u8 time_t=0;
u8 clock=0;
u16 temp=0;
u8 clock_flag=0;
u8 count=0;
u8 count1=0;
void delay(u16 i)
{
while(i--);
}
void Chan_hc573(chose);
void Timer0Init(void)
{
AUXR |= 0x80;
TMOD &= 0xF0;
TL0 = 0xA0;
TH0 = 0x15;
TF0 = 0;
ET0=1;
}
void Service_T0() interrupt 1
{
count++;
if(count==40)
{
count1++;
count=0;
}
if(count1%2==1)
{
clock_flag=1;
}
else
{
clock_flag=0;
}
}
void Chan_hc573(chose)
{
switch(chose)
{
case 4:
P2 = (P2 & 0x1f) | 0x80; break;
case 5:
P2 = (P2 & 0x1f) | 0xa0; break;
case 6:
P2 = (P2 & 0x1f) | 0xc0; break;
case 7:
P2 = (P2 & 0x1f) | 0xe0; break;
case 0:
P2 = (P2 & 0x1f) | 0x00; break;
}
}
void Init_system()
{
Chan_hc573(5);
P0=0x00;
Chan_hc573(4);
P0=0xff;
}
void Smg_display(u8 com,u8 dat)
{
Chan_hc573(7);
P0=0xff;
Chan_hc573(6);
P0=0x01<<com;
Chan_hc573(7);
P0=dat;
}
void Close_smg()
{
Chan_hc573(6);
P0=0x00;
Chan_hc573(7);
P0=0xff;
}
void Time_display()
{
if(time_t==0&&clock==0&&S4==1)
{
Smg_display(0,duan[Time[0]/16]); delay(1000);
Smg_display(1,duan[Time[0]%16]); delay(1000);
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[Time[1]/16]); delay(1000);
Smg_display(4,duan[Time[1]%16]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[Time[2]/16]); delay(1000);
Smg_display(7,duan[Time[2]%16]); delay(1000);
Close_smg();
}
else if(time_t==1&&clock==0)
{
if(Time[2]%16%2==1)
{
Smg_display(0,duan[sz[0]/10]); delay(1000);
Smg_display(1,duan[sz[0]%10]); delay(1000);
}
else
{
Smg_display(0,duan[10]); delay(1000);
Smg_display(1,duan[10]); delay(1000);
}
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[sz[1]/10]); delay(1000);
Smg_display(4,duan[sz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[sz[2]/10]); delay(1000);
Smg_display(7,duan[sz[2]%10]); delay(1000);
Close_smg();
}
else if(time_t==2&&clock==0)
{
if(Time[2]%16%2==1)
{
Smg_display(3,duan[sz[1]/10]); delay(1000);
Smg_display(4,duan[sz[1]%10]); delay(1000);
}
else
{
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
}
Smg_display(2,duan[11]); delay(1000);
Smg_display(0,duan[sz[0]/10]); delay(1000);
Smg_display(1,duan[sz[0]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[sz[2]/10]); delay(1000);
Smg_display(7,duan[sz[2]%10]); delay(1000);
Close_smg();
}
else if(time_t==3&&clock==0)
{
if(Time[2]%16%2==1)
{
Smg_display(6,duan[sz[2]/10]); delay(1000);
Smg_display(7,duan[sz[2]%10]); delay(1000);
}
else
{
Smg_display(6,duan[10]); delay(1000);
Smg_display(7,duan[10]); delay(1000);
}
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[sz[1]/10]); delay(1000);
Smg_display(4,duan[sz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(0,duan[sz[0]/10]); delay(1000);
Smg_display(1,duan[sz[0]%10]); delay(1000);
Close_smg();
}
else if(time_t==0&&clock==1)
{
if(Time[2]%16%2==1)
{
Smg_display(0,duan[nz[0]/10]); delay(1000);
Smg_display(1,duan[nz[0]%10]); delay(1000);
}
else
{
Smg_display(0,duan[10]); delay(1000);
Smg_display(1,duan[10]); delay(1000);
}
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[nz[1]/10]); delay(1000);
Smg_display(4,duan[nz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[nz[2]/10]); delay(1000);
Smg_display(7,duan[nz[2]%10]); delay(1000);
Close_smg();
}
else if(time_t==0&&clock==2)
{
if(Time[2]%16%2==1)
{
Smg_display(3,duan[nz[1]/10]); delay(1000);
Smg_display(4,duan[nz[1]%10]); delay(1000);
}
else
{
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
}
Smg_display(2,duan[11]); delay(1000);
Smg_display(0,duan[nz[0]/10]); delay(1000);
Smg_display(1,duan[nz[0]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(6,duan[nz[2]/10]); delay(1000);
Smg_display(7,duan[nz[2]%10]); delay(1000);
Close_smg();
}
else if(time_t==0&&clock==3)
{
if(Time[2]%16%2==1)
{
Smg_display(6,duan[nz[2]/10]); delay(1000);
Smg_display(7,duan[nz[2]%10]); delay(1000);
}
else
{
Smg_display(6,duan[10]); delay(1000);
Smg_display(7,duan[10]); delay(1000);
}
Smg_display(2,duan[11]); delay(1000);
Smg_display(3,duan[nz[1]/10]); delay(1000);
Smg_display(4,duan[nz[1]%10]); delay(1000);
Smg_display(5,duan[11]); delay(1000);
Smg_display(0,duan[nz[0]/10]); delay(1000);
Smg_display(1,duan[nz[0]%10]); delay(1000);
Close_smg();
}
else if(time_t==0&&clock==0&&S4==0)
{
Smg_display(0,duan[10]); delay(1000);
Smg_display(1,duan[10]); delay(1000);
Smg_display(2,duan[10]); delay(1000);
Smg_display(3,duan[10]); delay(1000);
Smg_display(4,duan[10]); delay(1000);
Smg_display(5,duan[temp/10]); delay(1000);
Smg_display(6,duan[temp%10]); delay(1000);
Smg_display(7,0xc6); delay(1000);
Close_smg();
}
}
void Key_Down()
{
if(S7==0)
{
delay(100);
if(S7==0)
{
while(S7==0)
{
Time_display();
}
if(time_t==0)
{
sz[0]=(Time[0]/16)*10+(Time[0]%16);
sz[1]=(Time[1]/16)*10+(Time[1]%16);
sz[2]=(Time[2]/16)*10+(Time[2]%16);
}
if(EA==0)
{
time_t++;
}
TR0=0;EA=0;count1=0;
clock=0;
clock_flag=0;
if(time_t==4)
{
Time[0]=(sz[0]/10)*16+(sz[0]%10);
Time[1]=(sz[1]/10)*16+(sz[1]%10);
Time[2]=(sz[2]/10)*16+(sz[2]%10);
DS1302_Init();
time_t=0;
}
}
}
if(S6==0)
{
delay(100);
if(S6==0)
{
while(S6==0)
{
Time_display();
}
if(clock==0)
{
nz[0]=(Time1[0]/16)*10+(Time1[0]%16);
nz[1]=(Time1[1]/16)*10+(Time1[1]%16);
nz[2]=(Time1[2]/16)*10+(Time1[2]%16);
}
if(EA==0)
{
clock++;
}
TR0=0;EA=0;count1=0;
time_t=0;
clock_flag=0;
if(clock==4)
{
Time1[0]=(nz[0]/10)*16+(nz[0]%10);
Time1[1]=(nz[1]/10)*16+(nz[1]%10);
Time1[2]=(nz[2]/10)*16+(nz[2]%10);
clock=0;
}
}
}
if(S5==0)
{
delay(100);
if(S5==0)
{
while(S5==0)
{
Time_display();
}
TR0=0;EA=0;count1=0;
clock_flag=0;
if(time_t==1)
{
sz[0]++;
if(sz[0]==24)
{
sz[0]=0;
}
}
else if(time_t==2)
{
sz[1]++;
if(sz[1]==60)
{
sz[1]=0;
}
}
else if(time_t==3)
{
sz[2]++;
if(sz[2]==60)
{
sz[2]=0;
}
}
else if(clock==1)
{
nz[0]++;
if(nz[0]==24)
{
nz[0]=0;
}
}
else if(clock==2)
{
nz[1]++;
if(nz[1]==60)
{
nz[1]=0;
}
}
else if(clock==3)
{
nz[2]++;
if(nz[2]==60)
{
nz[2]=0;
}
}
}
}
if(S4==0)
{
delay(100);
if(S4==0)
{
while(S4==0)
{
Time_display();
temp=read_temp();
}
TR0=0;EA=0;count1=0;
clock_flag=0;
if(time_t==1)
{
sz[0]--;
if(sz[0]==-1)
{
sz[0]=23;
}
}
else if(time_t==2)
{
sz[1]--;
if(sz[1]==-1)
{
sz[1]=59;
}
}
else if(time_t==3)
{
sz[2]--;
if(sz[2]==-1)
{
sz[2]=59;
}
}
else if(clock==1)
{
nz[0]--;
if(nz[0]==-1)
{
nz[0]=23;
}
}
else if(clock==2)
{
nz[1]--;
if(nz[1]==-1)
{
nz[1]=59;
}
}
else if(clock==3)
{
nz[2]--;
if(nz[2]==-1)
{
nz[2]=59;
}
}
}
}
}
void Time_Clock()
{
if(Time[0]==Time1[0]&&Time[1]==Time1[1]&&Time[2]==Time1[2])
{
TR0=1;EA=1;
}
}
void LED()
{
if(clock_flag==1)
{
Chan_hc573(4);
P0 = (P0 & 0xfe) | 0x00;
}
else
{
Chan_hc573(4);
P0 = (P0 & 0xfe) | 0x01;
}
if(count1==25)
{
TR0=0;
EA=0;
count=0;
count1=0;
clock_flag=0;
}
}
void main()
{
Init_system();
DS1302_Init();
Timer0Init();
temp=read_temp();
while(1)
{
LED();
Key_Down();
Time_Clock();
DS1302_read();
Time_display();
}
}
|