Specifications
8.8.6 Programming the LDT/PIT
The following code fragments illustrate how the system software, by using the on-board
hardware, can create accurate time delays and measure elapsed times, accurate to 1µs,
irrespective of the CPU’s operating frequency.
The LDT and PIT control registers and operational modes are defined thus:
#define TIMER_BYTE_0 (0x0218U)
#define TIMER_BYTE_1 (0x0219U)
#define TIMER_BYTE_2 (0x021AU)
#define TIMER_BYTE_3 (0x021BU)
#define CONTROL_STATUS (0x021CU)
#define INTERRUPT_MASK (0x10U)
#define INTERRUPT_ENABLE (0x10U)
#define INTERRUPT_DISABLE (0x00U)
#define INTERRUPT_SET (0x10U)
#define INTERRUPT_RESET (0x00U)
#define TIMER_ROLLOVER (0x10U)
#define MODE_MASK (0x0EU)
#define MODE_PIT_10000Hz (0x0EU)
#define MODE_PIT_5000Hz (0x0CU)
#define MODE_PIT_2000Hz (0x0AU)
#define MODE_PIT_1000Hz (0x08U)
#define MODE_PIT_500Hz (0x06U)
#define MODE_PIT_200Hz (0x04U)
#define MODE_PIT_100Hz (0x02U)
#define MODE_LDT (0x00U)
#define MODE_RUN_MASK (0x01U)
#define MODE_RUN_GO (0x01U)
#define MODE_RUN_STOP (0x00U)
The following code fragment illustrates how a simple delay of 10ms is implemented.
outbyte (CONTROL_STATUS, MODE_RUN_STOP);
outbyte (TIMER_BYTE_0, 0);
outbyte (TIMER_BYTE_1, 0);
outbyte (TIMER_BYTE_2, 0);
outbyte (TIMER_BYTE_3, 0);
outbyte (CONTROL_STATUS, MODE_PIT_100Hz | MODE_RUN_GO);
/* wait until the PIT rolls over ... */
while (inbyte (CONTROL_STATUS) & TIMER_ROLLOVER) == 0)
; /* do nothing ... */
/* reset the PIT "rollover" flag ... */
outbyte (CONTROL_STATUS, MODE_RUN_STOP);
VP 110/01x 8-17
Additional Local I/O Functions