|
#include <reg51.h>
unsigned char code changled[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x27,0x7f,0x6f};
unsigned char led[6];
unsigned char guandeng[3];
unsigned char kaideng[3];
unsigned char present_time[3];
unsigned char xiao[3];
unsigned char flash=0;
unsigned char timemeasure=0;
unsigned char flash_cs=0;
unsigned char tiaozheng=0;
unsigned int enabletime=0;
bit enablebit=0;
sbit dadeng=P1^4;
sbit xiaodeng=P1^5;
sbit P1_0=P1^0;
sbit P1_1=P1^1;
sbit P1_2=P1^2;
sbit P1_3=P1^3;
sbit P3_3=P3^3;
sbit P3_6=P3^6;
sbit P3_7=P3^7;
void change_data(unsigned char i)
{
unsigned char x,change;
if(i==1)
{
x=present_time[0];
change=x/100;
x=present_time[0];
led[0]=x/10-change*10;
x=present_time[0];
led[1]=(unsigned char)(x-change*100-led[0]*10);
x=present_time[1];
change=x/100;
x=present_time[1];
led[2]=x/10-change*10;
x=present_time[1];
led[3]=(unsigned char)(x-change*100-led[2]*10);
x=present_time[2];
change=x/100;
x=present_time[2];
led[4]=x/10-change*10;
x=present_time[2];
led[5]=(unsigned char)(x-change*100-led[4]*10);
}
if(i==2)
{
x=kaideng[0];
change=x/100;
x=kaideng[0];
led[0]=x/10-change*10;
x=kaideng[0];
led[1]=(unsigned char)(x-change*100-led[0]*10);
x=kaideng[1];
change=x/100;
x=kaideng[1];
led[2]=x/10-change*10;
x=kaideng[1];
led[3]=(unsigned char)(x-change*100-led[2]*10);
x=kaideng[2];
change=x/100;
x=kaideng[2];
led[4]=x/10-change*10;
x=kaideng[2];
led[5]=(unsigned char)(x-change*100-led[4]*10);
}
if(i==3)
{
x=guandeng[0];
change=x/100;
x=guandeng[0];
led[0]=x/10-change*10;
x=guandeng[0];
led[1]=(unsigned char)(x-change*100-led[0]*10);
x=guandeng[1];
change=x/100;
x=guandeng[1];
led[2]=x/10-change*10;
x=guandeng[1];
led[3]=(unsigned char)(x-change*100-led[2]*10);
x=guandeng[2];
change=x/100;
x=guandeng[2];
led[4]=x/10-change*10;
x=guandeng[2];
led[5]=(unsigned char)(x-change*100-led[4]*10);
}
}
void change_deng(unsigned i)
{
if(i==0)
{
dadeng=1;
xiaodeng=0;
}
if(i==1)
{
dadeng=1;
xiaodeng=1;
}
if(i==2)
{
dadeng=0;
xiaodeng=1;
}
if(i==3)
{
dadeng=0;
xiaodeng=0;
}
}
void init(void)
{
guandeng[0]=6;
guandeng[1]=0;
guandeng[2]=0;
kaideng[0]=18;
kaideng[1]=0;
kaideng[2]=0;
present_time[0]=12;
present_time[1]=00;
present_time[2]=00;
xiao[0]=23;
xiao[1]=00;
xiao[2]=00;
}
T0_in() interrupt 1 using 3
{
unsigned char bb;
flash++;
enabletime++;
if(flash==15)
{
flash=0;
if(flash_cs==0)
{
P2=254;
}
if(flash_cs==1)
{
P2=253;
}
if(flash_cs==2)
{
P2=251;
}
if(flash_cs==3)
{
P2=247;
}
if(flash_cs==4)
{
P2=239;
}
if(flash_cs==5)
{
P2=223;
}
bb=led[flash_cs];
P0=changled[bb];
if(flash_cs!=5)
{
flash_cs++;
}
else
{
flash_cs=0;
}
}
if(enabletime==555)
{
enabletime=0;
enablebit=1;
}
}
T1_in() interrupt 3 using 3
{
TH1=(65535-40000)/256;
TL1=(65536-40000)%256;
timemeasure++;
if(timemeasure==10)
{
timemeasure=0;
if(present_time[2]<59)
{
present_time[2]=present_time[2]+1;
}
else
{
present_time[2]=0;
if(present_time[1]<59)
present_time[1]=present_time[1]+1;
else
{
present_time[1]=0;
if(present_time[0]<23)
present_time[0]=present_time[0]+1;
else
present_time[0]=0;
}
}
if(tiaozheng<=3)
{
change_data(1);
}
if(present_time[0]==guandeng[0])
if(present_time[1]==guandeng[1])
if(present_time[2]==guandeng[2])
{
xiaodeng=0;
dadeng=0;
}
if(present_time[0]==kaideng[0])
if(present_time[1]==kaideng[1])
if(present_time[2]==kaideng[2])
{
xiaodeng=1;
dadeng=1;
}
if(present_time[0]==xiao[0])
if(present_time[1]==xiao[1])
if(present_time[2]==xiao[2])
{
xiaodeng=1;
dadeng=0;
}
}
}
main()
{
unsigned char dengstate=0;
P3=0x00;
P1=0x00;
TF0=1;
ET0=1;
TMOD=0x12;
TH0=0x00;
TL0=0x00;
TR0=1;
TF1=1;
ET1=1;
TR1=1;
EA=1;
init();
change_data(1);
init();
for(;;)
{
if(P1_3==1)
if(enablebit==1)
{
enablebit=0;
enabletime=0;
change_deng(dengstate);
if(dengstate<3)
{
dengstate++;
}
else
{
dengstate=0;
}
}
if(P1_0==1)
if(enablebit==1)
{
enablebit=0;
enabletime=0;
tiaozheng++;
if(tiaozheng>0)
if(tiaozheng<=3)
{
change_data(3);
}
if(tiaozheng==10)
{
tiaozheng=0;
P3=0;
}
if(tiaozheng==1||tiaozheng==4||tiaozheng==7)
P3=1;
if(tiaozheng==2||tiaozheng==5||tiaozheng==8)
P3=2;
if(tiaozheng==3||tiaozheng==6||tiaozheng==9)
P3=4;
}
if(tiaozheng==1||tiaozheng==2||tiaozheng==3)
P3_3=1;
if(tiaozheng==4||tiaozheng==5||tiaozheng==6)
P3_6=1;
if(tiaozheng==7||tiaozheng==8||tiaozheng==9)
P3_7=1;
if(P1_2==1)
if(enablebit==1)
{
enablebit=0;
enabletime=0;
if(tiaozheng==1)
{
if(present_time[0]<23)
present_time[0]=present_time[0]+1;
else
present_time[0]=0;
change_data(1);
}
if(tiaozheng==2)
{
if(present_time[1]<59)
present_time[1]=present_time[1]+1;
else
present_time[1]=0;
change_data(1);
}
if(tiaozheng==3)
{
if(present_time[2]<59)
present_time[2]=present_time[2]+1;
else
present_time[2]=0;
change_data(1);
}
if(tiaozheng==4)
{
if(kaideng[0]<23)
kaideng[0]=kaideng[0]+1;
else
kaideng[0]=0;
change_data(2);
}
if(tiaozheng==5)
{
if(kaideng[1]<59)
kaideng[1]=kaideng[1]+1;
else
kaideng[1]=0;
change_data(2);
}
if(tiaozheng==6)
{
if(kaideng[2]<59)
kaideng[2]=kaideng[2]+1;
else
kaideng[2]=0;
change_data(2);
}
if(tiaozheng==7)
{
if(guandeng[0]<23)
guandeng[0]=guandeng[0]+1;
else
guandeng[0]=0;
change_data(3);
}
if(tiaozheng==8)
{
if(guandeng[1]<59)
guandeng[1]=guandeng[1]+1;
else
guandeng[1]=0;
change_data(3);
}
if(tiaozheng==9)
{
if(guandeng[2]<59)
guandeng[2]=guandeng[2]+1;
else
guandeng[2]=0;
change_data(3);
}
}
if(P1_1==1)
if(enablebit==1)
{
enablebit=0;
enabletime=0;
if(tiaozheng==1)
{
if(present_time[0]>=1)
present_time[0]=present_time[0]-1;
else
present_time[0]=23;
change_data(1);
}
if(tiaozheng==2)
{
if(present_time[1]>=1)
present_time[1]=present_time[1]-1;
else
present_time[1]=59;
change_data(1);
}
if(tiaozheng==3)
{
if(present_time[2]>=1)
present_time[2]=present_time[2]-1;
else
present_time[2]=59;
change_data(1);
}
if(tiaozheng==4)
{
if(kaideng[0]>=1)
kaideng[0]=kaideng[0]-1;
else
kaideng[0]=23;
change_data(2);
}
if(tiaozheng==5)
{
if(kaideng[1]>=1)
kaideng[1]=kaideng[1]-1;
else
kaideng[1]=59;
change_data(2);
}
if(tiaozheng==6)
{
if(kaideng[2]>=1)
kaideng[2]=kaideng[2]-1;
else
kaideng[2]=59;
change_data(2);
}
if(tiaozheng==7)
{
if(guandeng[0]>=1)
guandeng[0]=guandeng[0]-1;
else
guandeng[0]=23;
change_data(3);
}
if(tiaozheng==8)
{
if(guandeng[1]>=1)
guandeng[1]=guandeng[1]-1;
else
guandeng[1]=59;
change_data(3);
}
if(tiaozheng==9)
{
if(guandeng[2]>=1)
guandeng[2]=guandeng[2]-1;
else
guandeng[2]=59;
change_data(3);
}
}
}
}
|
|