# TMOD value for timer 1 in mode 0 in 8051 microcontroller

What will be result of this statement:

MOV TMOD,#00H


Will it set it to timer 0 in mode 0 or to timer 1 in mode 0?

Other statements like:

MOV TMOD,#01H ;----- sets timer 0 mode 1
MOV TMOD,#10H ;----- sets timer 1 mode 1


didn't create any ambiguity.

Actually, all of those statements modify BOTH timers:

MOV TMOD,#00H ; set timer 0 mode 0 AND timer1 mode 0
MOV TMOD,#01H ; set timer 0 mode 1 AND timer1 mode 0
MOV TMOD,#10H ; set timer 0 mode 0 AND timer1 mode 1


If you want to modify only one of the timers, you must do a read-modify-write, preserving the bits on the timer you're not changing.

For example, if you want to force Timer0 to mode 0 without changing anything else, you might do:

ANL TMOD,#FCh ; binary 11111100 -- bit mask with two LSBs cleared

• And can you tell the command for setting timer 1 in mode 0 specifically? – Shyam Mittal Mar 2 at 12:49
• You can't work it out from the information given so far? Look again at the definition of the TMOD register. – Dave Tweed Mar 2 at 12:52
• I got that. Thanks Dave. – Shyam Mittal Mar 3 at 21:49