#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code dis_7[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};
uchar data timedata[6]={0x06,0x05,0x07,0x05,0x02,0x01};
uchar data weisao[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
uchar data BUFFER[1]={0};
uchar s1num=-1;
char c=0;
bit flag=0;
char j=128;
uchar FlagFlashDN,Tick0FlashDN,FlagDNONOFF,ComSelect,Cursor,
Tick0ScanDN;
sbit key1=P3^6;
sbit key2=P3^7;
void keyscan();
void Scan_DN(void);
void display();
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void init()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
EA=1;
ET0=1;
TR0=1;
ET1=1;
TR1=1;
}
void main()
{ init();
while(1)
{
if(s1num==0)
FlagFlashDN=0;
else
FlagFlashDN=1;
keyscan();
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
BUFFER[0]=BUFFER[0]+1;
if(BUFFER[0]==20) //1秒时间到加1
{
BUFFER[0]=0;//时间到附0
timedata[0]++; //秒个位加1
if(timedata[0]>=10) //秒个位到10则进秒十位
{
timedata[0]=0;timedata[1]++;
if(timedata[1]>=6) //秒十位到6则进分个位
{
timedata[1]=0;timedata[2]++;
if(timedata[2]>=10) //分个位位到10则进分十位
{
timedata[2]=0;timedata[3]++;
if(timedata[3]>=6) //分十位到6则进小时个位
{
timedata[3]=0;timedata[4]++;
if(timedata[4]>=10) //小时个位到10则进小时十位
{
timedata[4]=0;timedata[5]++;
}
if(timedata[5]==2) //当小时为24时下一个变0
{
if (timedata[4]==4)
{
timedata[4]=0;timedata[5]=0;
}
}
}
}
}
}
}
}
void keyscan()
{
if(key1==0)
{
delayms(10);
if(key1==0)
{
s1num++;
while(!key1);
if(s1num==6)
{
TR0=1;
s1num=-1;
}
}
}
if(s1num==0)
{
TR0=0;
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(timedata[s1num]<9) // 秒个位时加到10时返回0
{
timedata[s1num]=timedata[s1num]+1;
}
else
{
timedata[s1num]=0;
}
while(!key2);
}
}
}
if(s1num==1)
{
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(timedata[s1num]<5) // 秒个位时加到10时返回0
{
timedata[s1num]=timedata[s1num]+1;
}
else
{
timedata[s1num]=0;
}
while(!key2);
}
}
}
if(s1num==2)
{
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(timedata[s1num]<9)
{
timedata[s1num]=timedata[s1num]+1;
}
else
{
timedata[s1num]=0;
}
while(!key2);
}
}
}
if(s1num==3)
{
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(timedata[s1num]<5)
{
timedata[s1num]=timedata[s1num]+1;
}
else
{
timedata[s1num]=0;
}
while(!key2);
}
}
}
if(s1num==4)
{
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(timedata[s1num]<4)
{
timedata[s1num]=timedata[s1num]+1;
}
else
{
timedata[s1num]=0;
}
while(!key2);
}
}
}
if(s1num==5)
{
if(key2==0)
{
delayms(10);
if(key2==0)
{
if(timedata[s1num]<2)
{
timedata[s1num]=timedata[s1num]+1;
}
else
{
timedata[s1num]=0;
}
while(!key2);
}
}
}
}
void timer1() interrupt 3
{
TH1=(65536-1000)/256;
TL1=(65536-1000)%256;
if(s1num==-1)
FlagFlashDN=0;
else
FlagFlashDN=1;
if(FlagFlashDN==1)
{
if(++Tick0FlashDN>7)
{
Tick0FlashDN=0;
FlagDNONOFF=~FlagDNONOFF;
}
}
else
FlagDNONOFF=0;
Scan_DN();
}
void Scan_DN(void)
{
uchar temp;
if(++Tick0ScanDN>4)
{
Tick0ScanDN=0;
P2=0x00;
if(++ComSelect>5)
ComSelect=0;
switch(ComSelect)
{
case 0:
temp=dis_7[timedata[0]];
if((s1num==0)&& (FlagDNONOFF==1))
temp=0xff;
break;
case 1:
temp=dis_7[timedata[1]];
if((s1num==1)&& (FlagDNONOFF==1))
temp=0xff;
break;
case 2:
temp=dis_7[timedata[2]];
if((s1num==2)&& (FlagDNONOFF==1))
temp=0xff;
break;
case 3:
temp=dis_7[timedata[3]];
if((s1num==3)&& (FlagDNONOFF==1))
temp=0xff;
break;
case 4:
temp=dis_7[timedata[4]];
if((s1num==4)&& (FlagDNONOFF==1) )
temp=0xff;
break;
case 5:
temp=dis_7[timedata[5]];
if((s1num==5)&& (FlagDNONOFF==1) )
temp=0xff;
break;
}
P0=temp;
switch(ComSelect)
{
case 0:
P2=0x01;
break;
case 1:
P2=0x02;
break;
case 2:
P2=0x04;
break;
case 3:
P2=0x08;
break;
case 4:
P2=0x10;
break;
case 5:
P2=0x20;
break;
}
}
}
那个高手帮我指导一下,谢谢! |