|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula=P2^7;
sbit wela=P2^6;
sbit led1=P1^0;
uchar code table[]={
0x5f,0x41,0x9b,0xcb,
0xc5,0xce,0xde,0x47,
0xdf,0xcf,0xd7,0xdc,
0x1e,0xd9,0x9e,0x96};
void delayms(uint);
void display(uchar,uchar,uchar,uchar);
uchar fen,miao,num1,num2,fshi,fge,mshi,mge,dian;
void main()
{
TMOD=0x11;
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
while(1)
{
display(fshi,fge,mshi,mge);
}
}
void display(uchar fshi,uchar fge,uchar mshi,uchar mge)
{
dula=1;
P0=table[fshi];
dula=0;
P0=0xff;
wela=1;
if(fen>9)
P0=0xf7;
else
P0=0xff;
wela=0;
delayms(5);
dula=1;
if(dian==1)
P0=table[fge]+0x20;
else
P0=table[fge];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delayms(5);
dula=1;
P0=table[mshi];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delayms(5);
dula=1;
P0=table[mge];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delayms(5);
}
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void T0_time() interrupt 1
{
TH0=(65536-45872)/256;
TL0=(65536-45872)%256;
num1++;
if(num1==4)
{
num1=0;
led1=~led1;
}
}
void T1_time() interrupt 3
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
num2++;
if(num2==1)
{
num2=0;
miao++;
if(miao==60)
{miao=0;
fen++;}
if(fen==24)
fen=0;
mshi=miao/10;
mge=miao%10;
fshi=fen/10;
fge=fen%10;
dian=miao%2;
}
} |
|