Professional Documents
Culture Documents
Hammad Khan Lab0006
Hammad Khan Lab0006
Submitted To:
Engr. Mariam Sabir
Lab Engineer
____________
EXPERIMENT NO 6
Objective: To get familiarized with timer T0 and time T1. And Getting introduced to interrupt
handling, Generating a square wave using timers and interrupts
LAB ASSESSMENT:
Ability to Conduct
Experiment
Ability to assimilate the
results
Effective use of lab
equipment and follows
the lab safety rules
Data presentation
Experimental results
Conclusion
Equipment:
Hardware:
1. 89c51 microcontroller
2. LEDs
Software:
1. Keil u-vision
2. Smart-pro 5000u
Discussion:
TIMERS: The 8051 comes equipped with two timers, both of which may be controlled, set, read,
and configured individually. The 8051 timers have three general functions:
1) Keeping time and/or calculating the amount of time between events
2) Counting the events themselves, or 3) Generating baud rates for
the serial port
Timer SFRs:
As mentioned before, the 8051 has two timers which each function essentially the same way. One
timer is TIMER0 and the other is TIMER1. The two timers share two SFRs (TMOD and TCON)
which control the timers, and each timer also has two SFRs dedicated solely to itself (TH0/TL0
and TH1/TL1).
We have given SFRs names to make it easier to refer to them, but in reality an SFR has a numeric
address. It is often useful to know the numeric address that corresponds to an SFR name. The SFRs
relating to timers are:
When you enter the name of an SFR into an assembler, it internally converts it to a number.
For example, the command:
MOV TH0,#25h
moves the value 25h into the TH0 SFR. However, since TH0 is the same as SFR address
8Ch this command is equivalent to:
MOV 8Ch,#25h
The TMOD SFR
Let’s first talk about our first control SFR: TMOD (Timer Mode). The TMOD SFR is used to
control the mode of operation of both timers. Each bit of the SFR gives the microcontroller specific
information concerning how to run a timer. The high four bits (bits 4 through 7) relate to Timer 1
whereas the low four bits (bits 0 through 3) perform the exact same functions, but for timer 0. The
individual bits of TMOD have the following functions: TMOD (89h) SFR
Proteus Circuit
Task#02
Generate a square wave with frequency 1kHz and 50%duty cycle by using Timer 0 in mode
1. (In Assembly Language)
Program Code
ORG 00H
MOV TMOD ,#00000001B MAIN:
SETB P1.0
LCALL DELAY
CLR P1.0
LCALL DELAY
SJMP MAIN DELAY:
MOV TH0 ,#0FCH
MOV TL0 ,#18H
CLR TF0
SETB TR0 HERE:
JNB TF0,HERE
CLR TR0
CLR TF0
RET
END
Proteus Circuit
Task#03
Generate a square wave with frequency 50Hz with 70%duty cycle by using Timer 1 in
mode 1. (In Assembly Language)
Code
ORG 00H
MOV TMOD ,#00010000B MAIN:
SETB P1.0
LCALL DELAY1
CLR P1.0
LCALL DELAY2
SJMP MAIN DELAY1:
MOV TH1 ,#0CDH
MOV TL1 ,#99H
CLR TF1
SETB TR1 HERE1:
JNB TF1,HERE1
CLR TR1
CLR TF1
DELAY2:
MOV TH1 ,#0EAH
MOV TL1 ,#66H
CLR TF1
SETB TR1 HERE2:
JNB TF1,HERE2
CLR TR1
CLR TF1
RET
END
Proteus Circuit
Learning Outcomes:
In this lab, we learnt about timers in 8051 microcontroller. The 8051 comes equipped with two
timers, both of which may be controlled, set, read, and configured individually. The 8051 timers
have three general functions:
• Keeping time and/or calculating the amount of time between events
• Counting the events themselves, or
• Generating baud rates for the serial port we also learnt about timers SFR’s such as
TMOD and TCON and how we can use them in micro controller and get desired results and
waveforms with certain delays.