#include
#include
#define uchar unsigned char //界说一下方便使用
#define uint unsigned int
unsigned char code tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
char DAT[4]={0};
uint count;
char flag;
uint t=0;
uint x ;
//unchar num;
//uchar temp;
void DELAY_MS (unsigned int a)//延时程序
{
unsigned int i;
while( –a != 0)
{
for(i = 0; i < 125; i++);
}
}
//简化显现函数
void disp(int x)
{
int i,temp = 0x01;
DAT[0]=x/1000;
DAT[1]=x/100%10;
DAT[2]=x/10%10;
DAT[3]=x%10;
for(i=0;i<4;i++)
{
P1 = ~temp;
P0 = tab[DAT[i]];
DELAY_MS(4);
temp = temp<<1; //左移位
}
}
void irtime()
{
/*TMOD = 0X51;//设守时器1并用工作方法1
TH0 = (65536-50000)/256;//高位赋初值
TL0 = (65536-50000)%256;//低位赋初值
EA = 1;//敞开总中止开关
ET0 = 1;//发动守时中止
TR0 = 1;//敞开守时器
EX0 = 1;//翻开外部中止
IT0 = 1;//挑选外部中止方法1*/
TMOD=0x51; //T1计数器,T0守时器,方法1
TL0=(65536-10000)%256;
TH0=(65536-10000)/256;
TL1=0;
TH1=0;
TR0=1;
TR1=1;
ET0=1;
EA=1;
}
main()
{
irtime();
while(1)
{
disp(t/3);
}
}
void timer0() interrupt 1
{ x++;
if(x==100)
{
x = 0;
t = TH1*256+TL1;
TL1=0;
TH1=0;
}
TL0=(65536-10000)%256;
TH0=(65536-10000)/256;
}