中级会员
- 积分
- 374
- 威望
- 244
- 贡献
- 84
- 兑换币
- 10
- 注册时间
- 2011-1-8
- 在线时间
- 23 小时
|
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uint flag=0;
int count=0;
int qq=0;
uchar num,num1;tt,s,ms,ns,shi,ge;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void delay(uint z);
void display(uchar,uchar,uchar,uchar,uchar);
void main()
{
num=0;
tt=0;
TMOD=0x11;//设置定时器0为工作方式1
TH0=(65536-917)/256;
TL0=(65536-917)%256;
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
EA=1;//开总中断
ET0=1;//开定时器0中断
EX1=1;//开外部中断 1
IT1=1;//跳变触发
ET1=1;
TR0=1;//启动定时器0
TR1=1;
while(1)
{
display(shi,ge,s,ms,ns);
}
}
void display(uchar shi,uchar ge,uchar s,uchar ms,uchar ns)
{
dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(2);
dula=1;
P0=table[ge]|0x80;
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(2);
dula=1;
P0=table[s];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(2);
dula=1;
P0=table[ms];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(2);
dula=1;
P0=table[ns];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(2);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void time0() interrupt 1
{
if(flag)
{
TH0=(65536-917)/256;
TL0=(65536-917)%256;
tt++;
if(tt==1000)
tt=0;
s=tt/100;
ms=tt/100%10;
ns=tt%10;
}
}
void time1() interrupt 3
{
if(flag)
{
TH1=(65536-45872)/256;
TL1=(65536-45872)%256;
num1++;
if(num1==20)
{
num1=0;
num++;
if(num==60)
num=0;
shi=num/10;
ge=num%10;
qq++;
}
}
}
void waibu() interrupt 2
{
if(count==0)
{
flag=~flag;
count=1;
}
if(qq>4)
{
flag=0;
}
} |
|