#include
#define uchar unsigned char
#define uint unsigned int
#define delay_time 3/*???*/
uchar k,dat[]={0,0,0,0,0,0,0,0};
uint tcount,t,u;
uchar dat1[]={0,0,0,0,0,0,2,1};
uchar dat2[]={0,0,0,0,0,0,0,0};
uchar alarms[]={0,0,0,0,0,0,0,0};
uchar dis_bit[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
unsigned char code SEG7[11]={0xC0,/*0*/ 0xF9,/*1*/ 0xA4,/*2*/ 0xB0,/*3*/ 0x99,/*4*/ 0x92,/*5*/ 0x82,/*6*/ 0xF8,/*7*/ 0x80,/*8*/ 0x90,/*9*/ 0xBF,/*-*/
};/*??????*/
***it miaobiao1=P1^0;
***it tminute=P1^1;
***it thour=P1^2;
***it miaobiao2=P1^3;
***it alarm=P1^4;
***it P0_0=P0^0;
***it P1_5=P1^5;
***it P1_6=P1^6;
***it P1_7=P1^7;/*????*/
uchar ms=0;
uchar flag=0;
uchar sec=0;
uchar minit=0;
struct time{uchar second;uchar minute;uchar hour;}time1;
uchar n,i;
void delay(n)
{while(n--)
{
for(i=120;i>0;i--);
}
}
/*?????*/
void modify(void)
{
EA=0;
if(thour==0)
{
if(flag==0)
{
dat1[6]++;delay(280);
if(dat1[6]>9)
{
dat1[6]=0;
dat1[7]++;
}
else if((dat1[7]>1)&&(dat1[6]>3))
{dat1[7]=0; dat1[6]=0; }
}
if(flag==1)
{
alarms[6]++;delay(300);
if(alarms[6]>9)
{
alarms[6]=0;alarms[7]++;
if(alarms[7]>2)
{
alarms[7]=0;
}
}
dat[6]=alarms[6];
dat[7]=alarms[7];
}
}
if(tminute==0)
{
if(flag==0)
{
dat1[3]++;delay(280);
if(dat[3]>=9)
{dat1[4]++;dat1[3]=0;
if(dat1[4]>5)
{
dat1[4]=0;
}
}
}
if(flag==1)
{
alarms[3]++; delay(300);
if(alarms[3]>9)
{
alarms[4]++;alarms[3]=0;
if(alarms[4]>5)
{
alarms[4]=0;
}
}
dat[3]=alarms[3];
dat[4]=alarms[4];
}
}
if(miaobiao1==0)
{TR0=0;ET0=0;TR1=1;ET1=1;
}
if(miaobiao2==0)
{
TR0=1;ET0=1;TR1=0;ET1=0;
dat2[0]=0;
dat2[1]=0;
dat2[3]=0;
dat2[4]=0;
dat2[6]=0;
dat2[7]=0;
ms=0;
sec=0;
minit=0;
};
if(P1_5==0)
{
TR0=0;ET0=0;TR1=0;ET1=0;
};
if(alarm==0)
{
TR0=0;ET0=0;TR1=0;ET1=0;flag=1;
dat[0]=0;
dat[1]=0;
dat[2]=10;
dat[3]=0;
dat[4]=0;
dat[5]=10;
dat[6]=0;
dat[7]=0;
};
EA=1;
}
void init(void)
{
TMOD = 0x11;
TH0 = 0xDB;
TL0 =0xFF;
TH1=0xDB;
TL1=0xFF;
ET0 = 1; //10ms
ET1=1;
// TR1=1;
TR0=1;
tcount=0;
ms=0;
sec=0;
minit=0;
EA = 1;
}
void test(void){
for(k=0;k<8;k++)
{
P3=dis_bit[k];
P2=SEG7[dat[k]]; delay(1);
P3=0X00;
};
}
void main()
{init();
delay(10);
while(1)
{
modify();
test();
};
}
Void diplay() interrupt 1
{
ET0=0;
TR0=0;
TH0 = 0xDB;
TL0 = 0xff;
TR0=1;
tcount++;
if(tcount==100)
{
time1.second++;
tcount=0;
dat1[0]=(time1.second)%10;
dat1[1]=(time1.second)/10;
}
if(time1.second==60)
{ dat1[0]=0; dat1[1]=0;
time1.second=0;
time1.minute++;
dat1[3]=(time1.minute)%10;
dat1[4]=(time1.minute)/10;
}
if(time1.minute==60)
{
time1.minute=0;
time1.hour++;
dat1[6]=time1.hour%10;
dat1[7]=time1.hour/10;
}
if(time1.hour>23)
{
time1.hour=0;
}
dat[5]=10;
dat[2]=10;
dat[0]=dat1[0];
dat[1]=dat1[1];
dat[3]=dat1[3];
dat[4]=dat1[4];
dat[6]=dat1[6];
dat[7]=dat1[7];
flag=0;
P0=0x01;
if((alarms[7]==dat1[7])&&(alarms[6]==dat1[6])&&(alarms[4]==dat1[4])&&(alarms[3]==dat1[3])&&(dat1[1]<1))
{ P0=0x00;
}
ET0=1;
}
void time_2(void)interrupt 3
{
EA=0;
TR0=0;
TH1=0xDB;
TL1=0xFF;
TR1=1;
ms++;
dat2[0]=ms%10;
dat2[1]=ms/10;
if(ms>=100)
{
ms=0;
sec++;
dat2[3]=sec%10;
dat2[4]=sec/10;
if(sec>=60)
{
sec=0;
minit++;
dat2[6]=minit%10;
dat2[7]=minit/10;
}
}
dat[5]=10;
dat[2]=10;
dat[0]=dat2[0];
dat[1]=dat2[1];
dat[3]=dat2[3];
dat[4]=dat2[4];
dat[6]=dat2[6];
dat[7]=dat2[7];
EA=1;
|