#include <REG52.H>

#define uchar unsigned char

//在lcd上显示时间日期

#define uint unsigned int uint g=0,c=0,d,h=0;

sbit rs=P2^0;

sbit rw=P2^1;

sbit e=P2^2;

sbit move=P2^4;

sbit add=P2^5;

sbit rf=P2^3;

uchar table1[]= { "2013/01/01" };
uchar table[]= {"00/00/00"};
//延时
void delay(int n)
{  
uint a,b;
 for(a=0;a<n;a++)    
for(b=0;b<120;b++);
}
//在lcd上写指令
void write_order(uint c)
{   
rs=0;  
rw=0;  
P0=c;
 e=0;  
delay(50);  
e=1;  
delay(50);

}
//在lcd上写数据
void write_data(uchar d )
{  
rs=1;
 rw=0;  
P0=d;  
e=0;  
delay(50);  
e=1;  
delay(50);
}
//初始化lcd void init_lcd()
{  
write_order(0X38);  
write_order(0X0c);  
write_order(0x06);  
write_order(0x80);
}
//定时器初始化
void init_time()
{  TMOD=0x01;
 TH0=(65535-50000)/256;  
TL0=(65535-50000)%256;  
EA=1;
 ET0=1;    
TR0=1;
}
void init_time0()
{  
 EX0=1;//开外部中断0  
IT0=1;

}
//在lcd上显示时间
void show()
{     
uint f; 
 while(1)  
 {  
 init_lcd();   
 for(f=0;f<=7;f++)    
write_data(table[f]);        
 }
}
void main()
{   
 init_time();  
init_time0();  
init_lcd();  
show();

}
//定时器
void timer() interrupt 1
{  TH0=(65535-50000)/256;
 TL0=(65535-50000)%256;  
g++;  
 if(g==20)  
  {     g=0;    
 table[7]=table[7]+1;   
  if(table[7]>'9')     
{    
 table[7]='0';     
table[6]=table[6]+1;  
   }    
 if(table[6]=='6')    
 {     table[6]='0';     table[4]=table[4]+1;     }  
  if(table[4]>'9')     

{     table[4]='0';     

table[3]=table[3]+1;    

 }   
 if(table[3]=='6')   

  {     table[3]='0';   

  table[1]=table[1]+1;  

   }   
 if(table[1]>'9')    

 {     table[1]='0';   

  table[0]=table[0]+1;     }    
if(table[0]=='2')     
if(table[1]=='4')    

 {       

 table[0]='0' ;    

 table[1]='0' ;   

  table[2]='/' ;    

 table[3]='0' ;   

  table[4]='0' ;  

   table[5]='/' ;

    table[6]='0' ;

    table[7]='0' ;   

  }  

  }

     }

void time0()   interrupt 0

{    
  while(1)
 {   
 init_lcd(); 
 if(move==0)
 c++;
 if(c==2||c==5)
 c++;
 if(add==0)  
table[c]=table[c]+1;  
if(table[c]>'9')   
table[c]='0';     
write_order(0x80+c);  
write_data(' ');  
write_order(0x80+c);  
write_data(table[c]);  
delay(20);    
if(rf==0)
 break;  
if(c==7)  
c=0; }
init_lcd();
c=0; 
}