//选择计数器0, 先低后高读/写入,模式3,二进制数计数
asm mov al, 00110110B //36H
asm out 43H, al //选择模式
asm mov ax, wTimer
asm out 40H, Al //写入低字节
asm mov al, ah
asm out 40H, Al //写入高字节
return;
}
//中断0x1C需要修改
void far interrupt NewInt1C()
{
//在中断函数里面不要执行浮点运算,否则需要保护数学协处理器FCU,指令是FSave,FWait和frstor
asm mov ax, seg wGlobal_SystemCounter
asm mov ds, ax
Name readtimer - read the complemented value of timer 0
Usage unsigned readtimer (void);
Prototype in local
Description Obtain the complement of the value in timer 0. The
complement is used so that the timer will appear to
count up rather than down. The value returned will
range from 0 to 0xffff.
Return value The complement of the value in timer 0.
Name timer_init - initialize multiplier for delay function
Usage void timer_init (void);
Prototype in local
Description Determine the multiplier required to convert milliseconds
to an equivalent interval timer value. Interval timer 0
is normally programmed in mode 3 (square wave), where
the timer is decremented by two every 840 nanoseconds;
in this case the multiplier is 2386. However, some
programs and device drivers reprogram the timer in mode 2,
where the timer is decremented by one every 840 ns; in this
case the multiplier is halved, i.e. 1193.
When the timer is in mode 3, it will never have an odd value.
In mode 2, the timer can have both odd and even values.
Therefore, if we read the timer 100 times and never
see an odd value, it's a pretty safe assumption that
it's in mode 3. This is the method used in timer_init.