本帖最后由 gonggu8181 于 2013-9-16 23:14 编辑
- #define u8 unsigned char
- #define u16 unsigned int
- u8 i;
- void IntToStr(unsigned int t, unsigned char *str, unsigned char n)
- {
- unsigned char a[5]; char i, j;
- a[0]=(t/10000)%10;
- a[1]=(t/1000)%10;
- a[2]=(t/100)%10;
- a[3]=(t/10)%10;
- a[4]=(t/1)%10;
- for(i=0; i<5; i++)
- a=a+'0';
- for(i=0; a=='0' && i<=3; i++);
- for(j=5-n; j<i; j++)
- { *str=' '; str++; }
- for(; i<5; i++)
- { *str=a; str++; }
- *str='\0';
- }
- //count interrupt
- void t0(void) interrupt 1
- {
- T0count++;
- TH0=0;TL0=0;
- }
- //time interrupt
- void t1(void) interrupt 3
- {
- TH1=0x5d;TL1=0x3d; //重装值
- timecount++;
- if(timecount==40) //1S
- {
- TR0=0; //停止计数
- x=T0count<<16+TH0<<8+TL0; //取计数值
- IntToStr(x, &TempBuffer[0], 5); //
- while(TempBuffer != '\0')
- {
- write_date(TempBuffer);
- i++;
- delay(200);
- }
- write_com(0x80+0x48);
- timecount=0;T0count=0;i = 0;
- TH0=0;TL0=0;
- TR1=1; //开始计时
- TR0=1; //开始计数
- }
- }
- int main(void)
- {
- init();
- while(1);
- }
|