哪个大神能给解释一下这个定时器为什么这样写: if(s0>50&&s1>50)
{
t0=s0;
t1=s1;
}
else
{
t0=s0*100+(TL0-0x9c);
t1=s1*100+(TL1-0x9c);
}
源程序为:#include"reg51.h"
#include"LCM1602_b.c"
sbit P32=P3^2;
unsigned char fen[1]="/";
unsigned char io;
unsigned int s0=0,s1=0,t0,t1;
void timer0(void) interrupt 1 //定时器0服务程序
{
s0++;
}
void timer1(void)interrupt 3 //定时器1服务程序
{
s1++;
}
void main(void)
{
unsigned char word[]="dd1/";
lcd1602_init();
TMOD=0xa2; //定时器模式,1为2方式,但GATE为1
EA=1;
P32=0; //p32,int0口先给低电平
ET0=1;
TH0=0x9c;
TL0=0x9c;
ET1=1;
TH1=0x9c;
TL1=0x9c;
display_5numbers(0,t0);
display_chars(5,fen,1);
display_5numbers(6,t1);
display_chars(11,word,4);
display_a_number(15,io);
while(1)
{
while(P32==0); //这两次是为了去除半沿
while(P32==1);
TR0=1; //开始计时
TR1=1;
while(P32==0);
TR0=0; //T0停
while(P32==1);
TR1=0; //T1停
if(s0>50&&s1>50)
{
t0=s0;
t1=s1;
}
else
{
t0=s0*100+(TL0-0x9c);
t1=s1*100+(TL1-0x9c);
}
io=(t1/t0);
display_5numbers(0,t0); // 显示
display_chars(5,fen,1);
display_5numbers(6,t1);
display_chars(11,word,4);
display_a_number(15,io);
delay(300);
t0=0,t1=0,s0=0,s1=0; //清值
TL0=0x9c;
TL0=0x9c;
}
}
|