8051 Microcontroller Timers and Counters YASH PAL, April 13, 2026April 13, 2026 8051 Microcontroller Timers and Counters – Many microcontroller systems require the counting of external events. It can be achieved by two 16-bit up counters, named T0 and T1. These two counters are available to the programmer. Each counter may be programmed to count internal clock pulses, acting as a timer, or programmed to count external pulses as a counter. The counters are divided into two 8-bit registers: Timer low (TL0 and TL1) and Timer high (TH0 and TH1). There are two registers to control all counter actions.Timer Mode Control Register (TMOD)Timer/Counter Control Register (TCON)The bit definitions of the two special function registers TCON and TMOD are shown in the tables below.The Timer Control Special Function Register (TCON)76543210TF1TR1TR0TF0TR0IE1 IE0IT0BitSymbolFunction7TF1Timer 1 Overflow flag. Set when the timer rolls from all 1s to 0. Cleared when the processor vectors to execute the interrupt service routine located at program address 001Bh.6TR1Timer 1 run control bit. Set to 1 by the program to enable the timer to count; cleared to 0 by the program to halt the timer. Does not reset the timer.5TF0Timer 0 Overflow flag. Set when the timer rolls from all 1s to 0. Cleared when the processor vectors to execute an interrupt4TR0Timer 0 run control bit. Set to 1 by the program to enable the timer to count; cleared to 0 by the program to halt the timer. Does not reset the timer.3IE1External interrupt 1 Edge flag. Set to 1 when a high-to-low edge signal is received on port 3, pin 3.3 (INT1). Cleared when the processor vectors to the interrupt service routine located at program address 0013h. Not related to timer operations.2IT1External interrupt 1 signal type control bit. Set to 1 by the program to enable external interrupt 1 to be triggered by a falling edge signal. Set to 0 by the program to enable a low-level signal on external interrupt 1 to generate an interrupt.1IE0External interrupt 0 Edge flag. Set to 1 when a high-to-low edge signal is received on port 3 pin 3.2 (INT0). Cleared when the processor vectors to the interrupt service routine located at program address 0003h. Not related to timer operations.0IT0External interrupt 0 signal type control bit. Set to 1 by the program to enable external interrupt 0 to be triggered by a falling edge signal. Set to 0 by the program to enable a low-level signal on external interrupt 0 to generate an interrupt. Bit addressable as TCON.0 to TCON.7.TCON SFRThe Timer Mode Control (TMOD) Special Function RegisterTimer control mode control special function registerBitSymbolFunction7/3GateOR gate enables the bit that controls the RUN/STOP of timer 1/0. Set to 1 by the program to enable the timer to run if bit TR 1/0 in TCON is set and the signal on the external interrupt INT1/0 pin is high. Cleared to 0 by the program to enable the timer to run if bit TR1/0 in TCOn is set.6/2C / TSet to 1 by program to make timer 1/0 act as a counter by counting pulses from external input pins 3.5 (T1) or 3.4 (T0). Cleared to 0 by the program to make the timer act as a timer by counting internal frequency.5/1M1Timer/counter operating mode select bit 1. Set/cleared by program to select mode.4/0M0Timer/counter operating mode select bit 0. Set/cleared by program to selectM1 M0 Mode0 0 00 1 11 0 21 1 3TMOD is not bit addressableTMOD SFRTimer Control LogicIf a counter is designed and programmed to be a timer, it will count the internal clock frequency of the 8051 microcontroller divided by 1210. The resultant timer clock is gated to the timer by means of the circuit shown in the figure below. The C/T bit in the TMOD register must be set to low (0) for timer operation. In other words, the counter is configured as a timer.Timer counter control logic of the 8051 microcontrollerModes of OperationsEach counter/timer may operate in one of the four possible modes, by substituting the proper values of M1 and M0 for the corresponding timer.Mode0 (M1 M0 = 00) – In this mode, 8 bits of TH0/TH1 and 5 bits of TL0/TL1 are used. The 13-bit counter can hold the values between 0000H and 1FFFH. Therefore, the maximum count of the counter is 1FFFH; after that, it resets to 000H.Timer mode 0Mode1 (M1 M0 = 01) – This mode of timer/counter is similar to mode 0, with the difference that it uses the full counter of 16 bits, 0000H to FFFFH.Timer mode 1Mode2 (M1 M0 = 10) – In this mode, TL0/TL1 is used as an 8-bit counter, and TH0/TH1 hold a value that is loaded to TL0/TL1 every time TL0/TL1 overflows from FFH to 00H. The timer flag (TF0/TF1) is also set when TL0/TL1 overflows.Timer mode 2Mode3 (M1 M0 = 11) – Timer 0 and timer 1 may be programmed to work independently in any of the mode 0, mode 1, or mode 2. In mode 3, the timers do not operate independently.timer mode 3CountersThe only difference between counting and timing is the source of clock pulses to the counters. When used as a timer, the clock pulses are sourced from the oscillator through the divide-by-12 circuit. When using a counter, pin T0 supplies pulses to counter 0 and pin T1 to counter. The C/T bit in TMOD must be set to 1 to select the counter. engineering subjects Microprocessor microprocessor