#include <reg52.h>
#include <function.h> //详见第六章第8讲
u8 T0RH,T0RL,T1RH,T1RL;
void
TIM0_Init(u32 us,
int
trim)
{
u32 tmp;
tmp = 11059200 / 12;
tmp = ( tmp * (us/100) )/10000;
tmp = 65536 - tmp;
tmp = tmp+trim;
T0RH = (unsigned
char
)(tmp>>8);
T0RL = (unsigned
char
)tmp;
TMOD &= 0xF0;
TMOD |= 0x01;
TH0 = T0RH;
TL0 = T0RL;
ET0 = 1;
TR0 = 1;
}
void
TIM1_Init(u32 us,
int
trim)
{
u32 tmp;
tmp = 11059200 / 12;
tmp = ( tmp * (us/100) )/10000;
tmp = 65536 - tmp;
tmp = tmp+trim;
T1RH = (unsigned
char
)(tmp>>8);
T1RL = (unsigned
char
)tmp;
TMOD&=0x0F;
TMOD|=0x10;
TH1 = T1RH;
TL1 = T1RL;
ET1 = 1;
TR1 = 1;
}