为什么数码管计时器的时间总是比计算出来的要慢呢?求高人指点,谢谢

#include<reg51.h>
#define LED P0 //接4位LED数码管
#define PSCAN P1 //接74HC138作为扫描码转换

#define count_M0 250 //250us秒的定时
#define TH_M0 (256-count_M0)/256
//#define TL_M0 (256-count_M0)%256
unsigned int count_T0=0;

#define count_M1 250 //250us的定时
#define TH_M1 (256-count_M1)/256
//#define TL_M1 (256-count_M1)%256
unsigned int count_T1=0;

unsigned int seconds=0;
unsigned char scan=0;

unsigned char code TAB[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

unsigned int DISPLAY[]={0,0,0,0};
void inter(void);

void inter(void)
{
IE=0x8a; //ea es et1 ex1 et0 ex0
TMOD=0x22; //定时器1在方式2,定时0在方式2.
TH0=TH_M0;TL0=TH0;
TH1=TH_M1;TL1=TH1;
TR1=1;
TR0=1;
seconds=DISPLAY[0]*1000+DISPLAY[1]*100+DISPLAY[2]*10+DISPLAY[3];
}

void play(void)interrupt 1
{
TH0=TH_M0;TL0=TH0;
if(++count_T0==326) //250us*400=100ms
{
count_T0=0;
seconds++;
if(seconds==5000) seconds=0;
DISPLAY[3]=seconds%10; //个
DISPLAY[2]=seconds/10%10; //十
DISPLAY[1]=seconds/100%10; //百
DISPLAY[0]=seconds/1000%10; //千
}
}

void scan_dis(void)interrupt 3
{
TH1=TH_M1;TL1=TH1;
if(++count_T1==5) //250*5us改变一次
{ count_T1=0;
scan++;
if(scan>3) scan=0;
PSCAN=scan;
LED=TAB[DISPLAY[PSCAN]];
}

}

main()
{ inter();
while(1)
{
}

}

第1个回答  2012-06-02
你确定你的时控器和你的参数盒(控制器)时间一致 复位看看