89C52的一个秒表程序。用C编的。显示出错了。定时器没有起到作用。。求助
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit led1=P1^7;
uchar led_discode[11]={0xc0,0xf9,0xa4,0xb0,0x99,
0x92,0x82,0xf8,0x80,0x90,0xff};
uint num,k1num,number;
// uchar qian_bit,bai_bit,shi_bit,ge_bit;
sbit k1=P1^0;
void delay_ms(unsigned int ms) //1ms延时
{
uchar a;
while(ms--)
for(a=123;a>0;a--);
}
void nint() //初始化
{
TMOD = 0x01;
TH0 =(65536-10000)/256;
TL0 =(65536-10000)%256;
EA = 1;
ET0 = 1;
// TR0 = 1;
// P0=0xff;
// P3=0x00;
}
void led_display(uchar number )
{
qian_bit=number/1000;
P0=led_discode[qian_bit]; //显示千位
P3=0Xe0;
delay_ms(1);
P3=0Xff;
bai_bit=(number%1000)/100;
P0=led_discode[bai_bit]; //显示百位
P3=0Xd0;
delay_ms(1);
P3=0Xff;
shi_bit=(number%100)/10;
P0=led_discode[shi_bit]; //显示十位
P3=0X7f;
delay_ms(1);
P3=0Xff;
ge_bit =(number%10);
P0=led_discode[ge_bit]; //显示个位
P3=0Xbf;
delay_ms(1);
P3=0Xff;
}
void keyscan()
{
if(k1==0)
{
delay_ms(1);
if(k1==0)
{
k1num++;
while(!k1num);
if(k1num==1)
{
TR0 = 1;
}
if(k1num==2)
{
TR0=0;
// led1 = 0;
// led_display(number);
}
}
}
}
void main()
{
nint();
while(1)
{
uint i;
for(i=0;i<30;i++)
{
keyscan();
led_display(number);
}
}
}
void Timer0Interrupt(void) interrupt 1
{
TH0 =(65536-10000)/256;
TL0 =(65536-10000)%256;
num++;
//led1 = 0;
if(num==1)
{
num=0;
ge_bit++;
if(ge_bit==10)
{
ge_bit=0;
shi_bit++;
if(shi_bit==10)
{
shi_bit=0;
bai_bit++;
if(bai_bit==10)
{
bai_bit=0;
qian_bit++;
if(qian_bit==6)
{
qian_bit=0;
}
// qian_bit=number/1000;
// led_display(qian_bit);
}
// bai_bit=(number%1000)/100;
// led_display(bai_bit);
}
// shi_bit=(number%100)/10;
// led_display(shi_bit);
}
// ge_bit =(number%10);
// led_display(ge_bit);
}
}