Electronic Circuits and Diagram-Electronics Projects and Design
Electronic Circuits and Diagram-Electronics Projects and Design
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
Home
Forums
Datasheets
Lab Manual
Testing Components
Buy Project Kits
555 Timer
Circuit
IC Timer
CMOS Timer
Rs.699
Rs.299
Rs.98
Rs.525
Rs.530
Rs.699
While designing delay programs in 8051, calculating the initial value that has to be loaded inot 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 uS the timer has to make X increments.
2^16 = 65536 is the maximim number of counts possible for a 16 bit timer.
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.
Then, THTL = Hexadecimal equivalent of (65536-X) where (65536-X) is considered in decimal.
Example.
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
1/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
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. Also you can put
this in a loop for creating longer time delays (multiples of 1mS). Here Timer 0 of 8051 is used and it is operating in MODE1 (16 bit timer).
DELAY: MOV TMOD,#00000001B // Sets Timer 0
MOV TH0,#0FCH // Loads TH0 register
MOV TL0,#018H // LOads TL0 register
SETB TR0 // Starts the Timer 0
HERE: JNB TF0,HERE // Loops here until TF0
CLR TR0 // Stops Timer 0
CLR TF0 // Clears TF0 flag
RET
The above delay routine can be looped twice in order to get a 2mS delay and it is shown in the program below.
MAIN: MOV R6,#2D
LOOP: ACALL DELAY
DJNZ R6,LOOP
SJMP MAIN
DELAY: MOV TMOD,#00000001B
MOV TH0,#0FCH
MOV TL0,#018H
SETB TR0
HERE: JNB TF0,HERE
CLR TR0
CLR TF0
RET
Once timer flag (TF) is set, the programmer must clear it before it can be set again.
The timer does not stop after the timer flag is set. The programmer must clear the TR bit in order to stop the timer.
Once the timer overflows, the programmer must reload the initial start values to the TH and TL registers to begin counting up from.
We can configure the desired timer to create an interrupt when the TF flag is set.
If interrupt is not used, then we have to check the timer flag (TF) is set using some conditional branching instruction.
Maximum delay possible using a single 8051 timer is 65536S and minimum is 1S provided that you are using a 12MHz crystal for clocking the
microcontroller.
Square wave generation using 8051 timer.
Square waves of any frequency (limited by the controller specifications) can be generated using the 8051 timer. The technique is very simple. Write up a delay
subroutine with delay equal to half the time period of the square wave. Make any port pin high and call the delay subroutine. After the delay subroutine is finished,
make the corresponding port pin low and call the delay subroutine gain. After the subroutine is finished , repeat the cycle again. The result will be a square wave of
the desired frequency at the selected port pin. The circuit diagram is shown below and it can be used for any square wave, but the program has to be accordingly.
Programs for different square waves are shown below the circuit diagram.
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
2/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
SJMP MAIN
DELAY: MOV TH0,#0FEH
MOV TL0,#00CH
SETB TR0
HERE: JNB TF0,HERE
CLR TR0
CLR TF0
SETB P1.0
RET
END
Rs.355
Rs.899
Rs.191
Rs.98
Rs.699
Rs.690
Rs.299
Rs.265
Rs.525
Rs.699
We recommend:
Sense of Time tester circuit.
What is C++ ? An Introduction to programming with C++
Hi Fi Amplifier circuit
Bridge Amplifier using TDA 4935
Ultrasonic switch
Search
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
3/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
Custom Search
Posted in 8051
Tags: delay using 8051 timer, square wave generation using 8051 timer
Leave a Reply
Name (required)
Mail (will not be published) (required)
Website
Submit Comment
4/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
example: for a robot based on servo motor can be controlled by these square waves by varying the ON-OFF time.
Reply
Subscribe
Latest Articles
8051 Timers and Counters
We are on all Social Media Youtube Facebook Twitter Linkedin and Slideshare
Water level controller using arduino
Tachometer using arduino
Interfacing LCD to arduino
Motor speed control using arduino
Digital code lock using arduino
Interfacing hex keypad to arduino
Digital thermometer using arduino
Temperature logger using arduino
Rs.299
Rs.540
Rs.690
Rs.699
Rs.699
Rs.690
Categories
101-Announcements
555 Timer IC
8051
8051 projects
Amplifier Circuits
Arduino
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
5/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
Audio Circuits
Automotive Circuits
AVR
Basic Electricity
Basic Electronics
Battery Circuits
C plus plus
C Programming
Cable TV Circuits
Camera Technology
Clipping and Clamping Circuits
Clocking & Timer Circuits
Conversion Circuits
Counter Circuits
Counters
Digital Electronics
Education & Training
Electronic Components
Electronic Keys & Locks
Electronics Books
Electronics Jobs
Embedded Systems
Equipment Reviews
Events
Fan Circuits
Filter Circuits
Fire Alarm
Fun & Game Circuits
Gadget Reviews
Ham Radio Circuits
High Voltage Circuits
History
Home Circuits
Industrial Circuits
Instruments
Integrated Circuits
Inverters
Lab Manuals
LED related
Light Related
Lighting Circuits
MATLAB
Microcontrollers
Mobile Phone Related
Motor Related
Nanotechnology
Oscillators
Peripheral Interface Controller (PIC)
Power Controller Circuits
Power Electronics
Power Supplies
Project Ideas
Projects
Proximity Detectors
Radio Circuits
Radio Transmitters
Raspberry Pi
Relays
Remote Circuits
Reviews
Robotics
RTOS
Security & Saftey
Sensor Circuits
Signal Conditioners
Signal Generators
Speed Controller Circuits
State space analysis
Switching Circuits
Tech News
Telephone Related
Television Related
Temperature Related
Test & Measurement Circuits
Testing Components
Three phase circuits
Timer Circuits
Tone generator circuits
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
6/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
Like Us on Facebook
Circuitstoday.com
Like
Recent Comments
siddarth on Characteristics of a UJT
aaron on Low cost AM radio
Soudip Sinha Roy on Cable TV amplifier
rodel on Diac Applications
Mukesh Biswas on Mains Operated LED Circuit
chippa srinivas on Battery charger circuit using SCR.
chitturi vinay babu on Automatic cooler fan for amplifiers
raj on High & Low voltage cut-off with delay& alarm
vasudha divedi on Medium power FM transmitter circuit
aonebasha@gmail.com on 100 Watt sub woofer amplifier.
vasudha divedi on Medium power FM transmitter circuit
John Debris on The Best & Free Android Applications for the Electronics & Electrical Engineers
yasa on Half Adder and Full Adder
vasanth on Hartley Oscillator
Isep stars on Instrumentation amplifier
Pages
About
Advertise With Us
Authors
Buy Project Kits
Datasheets
Electronic Circuit Symbols
Lab Manuals
Electronic Circuits Lab
Microcontroller lab
Microprocessor Lab
Privacy Policy
Project Contests
Resistor Color Code Calculator
Sitemap
Testing Components
Popular Tags
555 IC
circuits hobby projects Home Circuits IC Integrated Circuits Most Popular Circuits Nanotechnology NE555 timer
Oscillators PIC Power Supplies Radio Circuits SCR Simple Electronics Projects Tech
Most Discussed
150 Watt amplifier circuit
100 Watt sub woofer amplifier.
Mains Operated LED Circuit
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
7/8
10/30/2014
Delay using 8051 timer. 1mS delay using 8051 timer, generating square wave using 8051 timer
file:///C:/Users/PTOFFICE/Desktop/Delay%20using%208051%20timer.%201mS%20delay%20using%208051%20timer,%20generating%20square%2
8/8