Timer/Counters
The 8051 and AT89C2051 contain two timer/counters known as timer/counter 0 and timer/counter 1 (larger members of the 8051 family contain more timers/ counters). These timer/counters can be operated in several different modes depending upon the programming of two registers TCON and TMOD, as shown in Tables 1.2 and 1.3. These registers should be programmed before using any timer or counter facilities of the microcontroller.
For example, bit 4 of TCON is the counter 0 run control bit and setting this bit starts counter 0. TCON register is at address 88 (hex) and bits in this register can be accessed either by making reference to the address or by using compiler reserved names (e.g. TR0).
TMOD is the timer/counter mode control register. This register sets the operating modes of the two timer/counters as shown in Table 1.3. There are three operating modes, known as modes 0, 1, and 2. TMOD is not bit addressable and should be loaded by specifying all the 8 bits. For example, loading hexadecimal byte 01 into TMOD sets timer 0 into mode 1 which is a 16-bit timer and is turned on and off by bit TR0 of TCON. Also, timer 1 is set into mode 0 which is a 13-bit timer and is turned on and off by bit TR1 of TCON.