#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula="P2"^6;
sbit wela="P2"^7;
uchar code table[]={ 0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xbf};
uint num1,num2,num3,num4,num5,num6,num7,num8,t;
uint second,minute,hour;
void delay(uint z);
void main()
{
num3=10;
num6=10;
t="0";
second="0";
minute="0";
hour="0";
TMOD="0X01";
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA="1";
ET0=1;
TR0=1;
while(1)
{
P0=0X00;
wela="1";
P0=0X80;
wela="0";
P0=0xff;
dula="1";
P0=table[num1];
dula="0";
delay(1);
P0=0X00;
wela="1";
P0=0X40;
wela="0";
P0=0xff;
dula="1";
P0=table[num2];
dula="0"; delay(1);
P0=0X00;
wela="1";
P0=0X20;
wela="0";
P0=0xff;
dula="1";
P0=table[num3];
dula="0"; delay(1);
P0=0X00;
wela="1";
P0=0X10;
wela="0";
P0=0xff;
dula="1";
P0=table[num4];
dula="0"; delay(1);
P0=0X00;
wela="1";
P0=0X08;
wela="0";
P0=0xff;
dula="1";
P0=table[num5];
dula="0"; delay(1);
P0=0X00;
wela="1";
P0=0X04;
wela="0";
P0=0xff;
dula="1";
P0=table[num6];
dula="0"; delay(1);
P0=0X00;
wela="1";
P0=0X02;
wela="0";
P0=0xff;
dula="1";
P0=table[num7];
dula="0"; delay(1);
P0=0X00;
wela="1";
P0=0X01;
wela="0";
P0=0xff;
dula="1";
P0=table[num8];
dula="0"; delay(1);
num1=second%10;
num2=second/10;
num4=minute%10;
num5=minute/10;
num7=hour%10;
num8=hour/10;
if(t==20)
{
t="0";
second="second"+1;
if(second==60)
{ second="0";minute++;}
if(minute==60)
{ minute="0";hour++; }
if(hour==24)
hour="0";
}
}
}
void delay(uint z)
{
uint i,j;
for(i=110;i>0;i--)
for(j=z;j>0;j--) ;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t++;
}
用户518079 2010-7-26 20:52