HERE: JNB TF0,HERE // Loops here until TF0 is set (ie until roll over) MOV TL0,#018H // LOads TL0 register with 18H MOV TH0,#0FCH // Loads TH0 register with FCH DELAY: MOV TMOD,#00000001B // Sets Timer 0 to MODE1 (16 bit timer). Here Timer 0 of 8051 is used and it is operating in MODE1 (16 bit timer). Also you can put this in a loop for creating longer time delays (multiples of 1mS). The program shown below can be used for generating 1mS delay and it is written as a subroutine so that you can call it anywhere in the program. Therefore TH=FC and TL=18 Program for generating 1mS delay using 8051 timer. Let the required delay be 1000uS (ie 1mS).Ħ4536 is considered in decimal and converting it t0 hexadecimal gives FC18 Then, THTL = Hexadecimal equivalent of (65536-X) where (65536-X) is considered in decimal.Let TH be the value value that has to be loaded to TH registed and TL be the value that has to be loaded to TL register.
Delay using timer is the most accurate and surely the best method.Ī timer can be generalized as a multi-bit counter which increments/decrements itself on receiving a clock signal and produces an interrupt signal up on roll over.
How to build a rentive on delay timer siemens step 7 software#
Generating delay using pure software loops have been already discussed here but such delays are poor in accuracy and cannot be used in sensitive applications. TIM_SOD.The 8051 microcontroller has two independent 16 bit up counting timers named Timer 0 and Timer 1 and this article is about generating time delays using the 8051 timers. (*This part runs once when we need start timer*) IF ABS_INT(IN:=timclock-TIM_SOD.CLK)>=100 (*timclock -mSec counter*) IF (TIM_SOD.Count)>0 (*number of seconds left*) We also have built our own timer structure with using milliseconds counter provided by PLC, so we could make arrays of timer (Schneider Electric) when we need and exceed PLC limitation.