0% found this document useful (0 votes)
43 views76 pages

Week 5 - Lec - 8051 - Part2 2

The document discusses various aspects of the 8051 peripheral including: - Timers which are 16-bit registers that can be used as timers or counters, with various modes setting their functionality. - The serial port which is used to transfer data one bit at a time for long distance communication versus parallel transmission. - Interrupts which allow peripheral functions to signal the CPU to pause current code and service the interrupt request.

Uploaded by

basit qureshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views76 pages

Week 5 - Lec - 8051 - Part2 2

The document discusses various aspects of the 8051 peripheral including: - Timers which are 16-bit registers that can be used as timers or counters, with various modes setting their functionality. - The serial port which is used to transfer data one bit at a time for long distance communication versus parallel transmission. - Interrupts which allow peripheral functions to signal the CPU to pause current code and service the interrupt request.

Uploaded by

basit qureshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 76

8051 Peripheral Overview

• Timers
• Serial Port
• Interrupts
8051 Timers
• The 8051 has two counters/timers which can be used either as timer
to generate a time delay or as counter to count events happening
outside the microcontroller.
• The 8051 has two timers:
• Timer0
• Timer1

• They can be used either as timers or as counters. Both timers are 16 bits
wide. Since the 8051 has an 8-bit architecture, each 16-bit is accessed as
two separate registers of low byte and high byte.
Timers
• Timer0 registers is a 16 bits register and accessed as
• Low byte
• High byte.
• The low byte is referred as a TL0 and the high byte is referred as TH0. These
registers can be accessed like any other registers.
Timers
•  Timer1 registers is also a 16 bits register and is split into two bytes,
referred to as TL1 and TH1.
Timers
• TMOD (timer mode) Register: 
• This is an 8-bit register which is used by both timers 0 and 1 to set the various
timer modes.
• In this TMOD register, lower 4 bits are set aside for timer0 and the upper 4
bits are set aside for timer1. In each case, the lower 2 bits are used to set the
timer mode and upper 2 bits to specify the operation.
• GATE=1  hardware way of starting and stopping the timer by an
external source .
• GATE=0  then we do no need external hardware to start and stop
the timers.
• C/T bit  When set, counter operation (input from Tx input pin).
When cleared, timer operation (input from internal clock).
M1 M0 Mode
0 0 0
0 1 1
1 0 2
1 1 3
Timers
Mode-1
• It is a 16-bit timer
• It allows values from 0000 to FFFFH to be loaded into the timer’s registers TL and TH.
• After TH and TL are loaded with a 16-bit initial value, the timer must be started. 
• We can do it by “SETB TR0” for timer 0 and “SETB TR1” for timer 1.
• After the timer is started. It starts count up until it reaches its limit of FFFFH.
• When it rolls over from FFFF to 0000H, it sets high a flag bit called TF (timer flag).
• When this timer flag is raised, one option would be stop the timer with the
instructions “CLR TR0“ or CLR TR1 for timer 0 and timer 1 respectively.
• Again, it must be noted that each timer flag TF0 for timer 0 and TF1 for timer1. After
the timer reaches its limit and rolls over, in order to repeat the process the registers
TH and TL must be reloaded with the original value and TF must be reset to 0.
Mode: 0
• Mode0- Mode 0 is exactly same like mode 1 except that:
• It is a 13-bit timer instead of 16-bit.
• The 13-bit counter can hold values between 0000 to 1FFFH in TH-TL.
Therefore, when the timer reaches its maximum of 1FFFH, it rolls over to
0000, and TF is raised.
Mode 2:
• An 8-bit auto-reload mode
• When a timer is in mode 2, THx holds the "reload value" and TLx is
the timer itself. Thus, TLx starts counting up. When TLx reaches 255
and is subsequently incremented, instead of resetting to 0 (as in the
case of modes 0 and 1), it will be reset to the value stored in THx.
Mode 3
• Timer mode "3" is a split-timer mode.
• When Timer 0 is placed in mode 3, it essentially becomes two
separate 8-bit timers. That is to say, Timer 0 is TL0 and Timer 1 is TH0.
Both timers count from 0 to 255 and overflow back to 0. All the bits
that are related to Timer 1 will now be tied to TH0.
Programming Timers
• Example: Indicate which mode and which timer are selected for each
of the following.
• (a) MOV TMOD, #01H (b) MOV TMOD, #20H (c) MOV TMOD, #12H
Programming Timers
• Find the timer’s clock frequency and its period for various 8051-based
system, with the crystal frequency 11.0592 MHz when C/T bit of
TMOD is 0.
8051 Serial Port
• Basics of Serial Communication
• Computers transfer data in two ways:
• Parallel: Often 8 or more lines (wire conductors) are used to transfer data to a
device that is only a few feet away.
• Serial: To transfer to a device located many meters away, the serial method is
used. The data is sent one bit at a time.
Calculation of Baud Rate
• The crystal frequency Fosc is divided by 12 internally which is used to
execute instructions also known as Machine Clock, Mosc. The timer
again divides the Mosc by 32 and uses it as the timer frequency,
say Tosc.
8051 Software Overview

1. Addressing Modes
2. Instruction Set
3. Programming
8051 Addressing Modes

You might also like