Information on 8253/8254 Programming

The IBM XT used an Intel 8253 to perform timing, sound generation, and memory refresh logic, the AT improved upon this by using the upwardly compatible 8254. The HCMOS version is called the 82C54. You can download a datasheet for the 82C54 from Intel.

The Intel 82C54 is a high-performance, CHMOS version of the industry standard 8254 counter/timer. It provides three independent 16-bit counters. All operating modes are software programmable. The 82C54 is pin compatible with the HMOS 8254, and is a superset of the 8253. Six programmable modes allow the 82C54 to be used as an event counter, elapsed time indicator, programmable one-shot, and in many other applications.

In the PC's architecture the 8254 is located at hardware I/O address 40H through 43H. The following C/Assembler code reads the 16 bit count maintained by channel 0 of the PC's 8254. Each count represent a time interval of 0.41905 uSec.

   unsigned int read_8254_count (void)
   {
     asm {
        pushf             // save current inetrrupt status
        cli               // no ints while we read the 8254
        mov  al,0         // command to latch counter for counter 0
        out  0x43,al      // tell the 8254 to latch the count
        db   0x24, 0xf0   // jmp $+2, this slow I/O on fast processors
        in   al,0x40      // read LSB of 8254's count
        mov  ah,al        // temp save
        db   0x24, 0xf0   // jmp $+2
        in   al,0x40      // read MSB of count
        xchg al,ah        // get right order of MSB/LSB
        popf              // return saved interrupt status
     }
     return _AX;
  }