#include <stc15.h>    	            //包含支持IAP15W4K58S4单片机的头文件
#include <intrins.h>
#include <gpio.h>					 //I/O初始化文件
#define uchar unsigned char
#define uint  unsigned int
#include <display.h>
uint counter=0;
uchar cnt=0;
uchar temp1,temp2;
void T0_T1_ini(void)
{
	TMOD=0x40;
	TH0=(65536-50000)/256;
	TL0=(65536-50000)%256;
	TH1=0x00;			
	TL1=0x00;
	TR0=1;
	TR1=1;
}
/*---------  主函数----------------*/
void main(void)
{
	gpio();				
 	T0_T1_ini();
	ET0=1;
	EA=1;
 	while(1)
	{
		Dis_buf[0]= counter%10;
		Dis_buf[1]= counter/10%10;
		Dis_buf[2]= counter/100%10;
		Dis_buf[3]= counter/1000%10;
		Dis_buf[4]= counter/10000%10;
		display();     
	}
}
void T0_ISR() interrupt 1      //T0中断服务函数
{
   	TF0=0;
	cnt++;
	if(cnt==20)    //1秒到了，清50ms计数变量，读T1值
	{
		cnt=0;
		temp1=TL1;
		temp2=TH1;			       //读取计数值 
		TR1=0;	
		TL1=0;
		TH1=0;
		TR1=1;		
	  	counter=(temp2<<8)+temp1;	  //高、低8位计数值合并在counter变量中
	}
}
