## Saturday, April 30, 2016

### 8051 Timer Delay Calculation

While designing delay programs in 8051, calculating the initial value that has to be loaded in to TH and TL registers forms a very important thing. Let us see how it is done.
• Assume the processor is clocked by a 12MHz crystal.
• That means, the timer clock input will be 12MHz/12 = 1MHz
• That means, the time taken for the timer to make one increment = 1/1MHz = 1uS
• For a time delay of “X” µs the timer has to make “X” increments.
• 2^16 = 65536 is the maximum number of counts possible for a 16 bit timer.
• Let YY be the value that has to be loaded to TH register and XX be the value that has to be loaded to TL register.
• Then, YYXX = Hexadecimal equivalent of (65536-X) where (65536-X) is considered in decimal.
Example:
Let the required delay be 1000uS (ie; 1mS).
That means X = 1000
65536 – X = 65536 – 1000 = 64536.
64536 is considered in decimal and converting it t0 hexadecimal gives FC18
That means YYXX = FC18
Therefore TH=FC and TL=18

Related topics:
8051 Crystal and Baudrate   |   8051 Serial Baudrate Calculation   |   8051 Serial Port   |   8051 Serial Port Programming   |   8051 Timer Programming   |   8051 Timers   |   8051 Software Development Tools   |   8051 Development Boards and Evaluation Kits   |   8051 Features   |   8051 History   |   8051 Enhanced Version 8052

List of topics: 8051