可以设置hou_num,min_num,sec_num的值来设置起始时间
-
#include<reg52.h>
-
-
#define uchar unsigned char
-
#define uint unsigned int
-
-
sbit dula=P2^6;
-
sbit wela=P2^7;
-
-
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
-
-
uchar code table_dp[]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef,0xf7,0xfc,0xb9,0xde,0xf9,0xf1};
-
-
void display(uchar,uchar,uchar,uchar,uchar,uchar);
-
void delayms(uint);
-
-
uchar num1,num2,sec_num,min_num,hou_num,sec_shi,sec_ge,min_shi,min_ge,hou_shi,hou_ge;
-
-
int main()
-
{
-
TMOD=0x11;
-
TH0=(65535-45872)/256;
-
TL0=(65535-45872)%256;
-
TH1=(65535-45872)/256;
-
TL1=(65535-45872)%256;
-
-
EA=1;
-
ET0=1;
-
ET1=1;
-
TR0=1;
-
TR1=1;
-
-
P1=0x00;
-
while(1)
-
{
-
display(sec_shi,sec_ge,min_shi,min_ge,hou_shi,hou_ge);
-
}
-
-
return 0;
-
}
-
-
void display(uchar sec_shi,uchar sec_ge,uchar min_shi,uchar min_ge,uchar hou_shi,uchar hou_ge)
-
{
-
//second
-
dula=1;
-
P0=table[sec_shi];
-
dula=0;
-
P0=0xff;
-
-
wela=1;
-
P0=0xef;
-
wela=0;
-
delayms(1);
-
-
dula=1;
-
P0=table[sec_ge];
-
dula=0;
-
P0=0xff;
-
-
wela=1;
-
P0=0xdf;
-
wela=0;
-
delayms(1);
-
-
//minute
-
dula=1;
-
P0=table[min_shi];
-
dula=0;
-
P0=0xff;
-
-
wela=1;
-
P0=0xfb;
-
wela=0;
-
delayms(1);
-
-
dula=1;
-
P0=table_dp[min_ge];
-
dula=0;
-
P0=0xff;
-
-
wela=1;
-
P0=0xf7;
-
wela=0;
-
delayms(1);
-
-
//hour
-
dula=1;
-
P0=table[hou_shi];
-
dula=0;
-
P0=0xff;
-
-
wela=1;
-
P0=0xfe;
-
wela=0;
-
delayms(1);
-
-
dula=1;
-
P0=table_dp[hou_ge];
-
dula=0;
-
P0=0xff;
-
-
wela=1;
-
P0=0xfd;
-
wela=0;
-
delayms(1);
-
}
-
-
void delayms(uint xms)
-
{
-
uint i,j;
-
for(i=xms;i>0;i--)
-
for(j=112;j>0;j--);
-
}
-
-
void T0_time() interrupt 1
-
{
-
TH0=(65535-45872)/256;
-
TL0=(65535-45872)%256;
-
num1++;
-
if(num1>=10)
-
{
-
num1=0;
-
P1=~P1;
-
}
-
}
-
-
void T1_time() interrupt 3
-
{
-
TH1=(65535-45872)/256;
-
TL1=(65535-45872)%256;
-
num2++;
-
if(num2>=20)
-
{
-
num2=0;
-
sec_num++;
-
if(sec_num==60)
-
{
-
sec_num=0;
-
min_num++;
-
if(min_num==60)
-
{
-
min_num=0;
-
hou_num++;
-
if(hou_num==24)
-
{
-
hou_num=0;
-
}
-
}
-
}
-
-
sec_shi=sec_num/10;
-
sec_ge=sec_num%10;
-
-
min_shi=min_num/10;
-
min_ge=min_num%10;
-
-
hou_shi=hou_num/10;
-
hou_ge=hou_num%10;
-
}
-
}
阅读(1542) | 评论(0) | 转发(0) |