Share this

Analysis of the types and working principles of microcontroller timers and counters

2026-04-06 03:29:29 · · #1

Introduction: In the 51 microcontroller, timers are divided into software timers, non-programmable hardware timers, and programmable timers.

I. What is a timer/counter? In the 51 microcontroller, a timer/counter is used to implement timing functions and also has counting functions to count external signals.

II. What types of timers/counters are there? In the 51 microcontroller, timers are divided into software timers, non-programmable hardware timers, and programmable timers.

Software timing: The CPU needs a fixed amount of time to execute each instruction. Therefore, a delay can be achieved by executing a no-instruction. The cost of doing this is that it consumes CPU time, so it is rarely done.

Non-programmable hardware timers: The timing function is accomplished by circuits and hardware. Generally, a base circuit is used, with external timing components (resistors and capacitors). The timing value is modified by changing the resistance value of the resistor and the capacitance value of the capacitor. Once the value is determined, the timing cannot be modified by software. The advantage of this approach is that it does not require CPU time.

Programmable timers: Timer values ​​and ranges are determined by software. Programmable timers are powerful and highly flexible. This article explains timers in detail.

III. Internal Structure and Working Principle of Timers The 8051 microcontroller has two timers: Timer 0 (T0) and Timer 1 (T1).

Timer 0 (T0) and Timer 1 (T1) are two 16-bit adders.

Timer 0 consists of two 8-bit counters, TH0 and TH1, and Timer 1 is the same.

The timer also contains the following registers:

8-bit Mode Register (TMOD)

8-bit control register (TCON)

Select Timer Mode Register (C/T)

Boot Mode Register (GATE)

Operating mode and start signal register (TR0 or TR1)

IV. Timer Operating Mode

The timer's operation mode is primarily controlled by THOD. The lower 4 bits are the timer 0 operation mode control bits, and the higher 4 bits are the timer 1 operation mode control bits. Both are M1M0.

Operating Mode M1M0 Function 0001 3-bit counter 1011 6-bit counter 210 8-bit counter, initial value auto-load 311T0 Divided into two 8-bit counters, T1 stops working V. Using Timers

timer_count.c

#include

unsignedchari;

sbitLED0=P1^0;

voidmain(void)

{

TMOD=0x01;

TH0=0;

TL0=0;

ET0=1;

TR0=1;

EA=1;

while (1);

}

voidt0_delay(void)interrupt1

{

i++;

TR0=0;

TH0=0;

TL0=0;

if (i == 20)

{

i=0;

LED0 = ~LED0;

}

TR0=1;

}

a

Read next

CATDOLL Oksana Hard Silicone Head

The head made from hard silicone does not have a usable oral cavity. You can choose the skin tone, eye color, and wig, ...

Articles 2026-02-22