TMOD and TCON register in 8051 Microcontroller
The Timer Mode (TMOD) and Timer Control (TCON) registers are used to configure and control the operation of the timers in the 8051 microcontroller. Let's break down the functions and format structure of these registers.
8051 Intel Microcontroller has Two 16-bit timers/counters, Timer 0 and Timer 1. TMOD and TCON registers are used for setting and using these timers/counters.
Both can be configured to operate either as timers or as event counters. In the case of timers, register is incremented once every machine cycle. Hence timer is considered as counter which counts machine cycles. One machine cycle has about 12 oscillator periods. The count rate is about (1/12)th of Oscillator frequency.
In the case of Counter, register is incremented in response to a 1-0 transition to its corresponding external input pin. In this function, the external input is sampled during S5-P2 of the every machine cycle.
Format of TMOD register in 8051
The TMOD register is used to set the mode of operation for Timer 0 and Timer 1. It is an 8-bit register where the lower nibble (bits 0-3) is used for Timer 0, and the upper nibble (bits 4-7) is used for Timer 1. Each nibble can be further broken down into mode control bits and gate control bits as described below. TMOD is not bit addressable.
GATE- When GATE=1 and TRx(in TCON) is set, Timer/Counter-x will run while INT-x pin is
set high(Hardware Control). When GATE=0, Timer/Counter-x will run only
while TRx=1(software control).
C/(T)- Set 0 for timer operation and Set 1 for counter operation
M1- Mode Selector bit
M0- Mode Selector bit
M1 | M0 | Operating Mode |
---|---|---|
0 | 0 | 13 bit timer |
0 | 1 | 16 bit timer/counter |
1 | 0 | 8 bit auto-reload timer/counter |
1 | 1 | TL0 is an 8 bit timer/counter controlled by standard timer 0 control bits, TH0 is an 8 bit timer controlled by timer 1 control bits. |
Bit structure of TCON register in 8051
The TCON register is used to control the timers and external interrupts. It is also an 8-bit register with specific bits allocated to Timer 0, Timer 1 and the external interrupts. Here is the bit structure of the TCON register. TCON register is bit addressable.
• TF1-TCON.7-Timer1 overflow flag
• TR1-TCON.6-Timer1 run control bit
• TF0-TCON.5-Timer0 overflow flag
• TR0-TCON.4-Timer0 run control bit
• IE1-TCON.3-External interrupt 1 edge flag
• IT1-TCON.2-Interrupt 1 type control bit
• IE0-TCON.1-External interrupt 0 edge flag
• IT0-TCON.0-Interrupt 0 type control bit
SUMMARY
➨TMOD Register: Configures the mode (operation mode, counter/timer selection, and gate control) for Timer 0 and Timer 1.
➨TCON Register: Controls the start/stop of the timers and the detection of external interrupts, and holds
the overflow flags for the timers.
➨Understanding these registers is crucial for effectively programming the 8051's timers and handling interrupts.
8051 Microcontroller Related Posts
What is microcontroller
8051 Microcontroller Architecture
Microcontroller hardware Interfacing
Microcontroller Interrupts
Microcontroller Cross Compiler
Microcontroller Serial Communication