0% found this document useful (0 votes)
6 views

8051 Microcontroller

The 8051 microcontroller, introduced by Intel in 1981, is a widely used 8-bit microcontroller known for its applications in embedded systems, automotive, medical devices, and robotics. It features a Harvard architecture with integrated CPU, memory, and I/O ports, and has limitations in memory, processing power, and peripheral support compared to modern microcontrollers. Its pin diagram outlines various functionalities for interfacing, programming, and debugging, making it a foundational component in many electronic applications.

Uploaded by

SARDAR PATEL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

8051 Microcontroller

The 8051 microcontroller, introduced by Intel in 1981, is a widely used 8-bit microcontroller known for its applications in embedded systems, automotive, medical devices, and robotics. It features a Harvard architecture with integrated CPU, memory, and I/O ports, and has limitations in memory, processing power, and peripheral support compared to modern microcontrollers. Its pin diagram outlines various functionalities for interfacing, programming, and debugging, making it a foundational component in many electronic applications.

Uploaded by

SARDAR PATEL
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

8051 Microcontroller

8051 is one of the first and most popular microcontrollers also known as MCS-51. Intel
introduced it in the year 1981. Initially, it came out as an N-type metal-oxide-
semiconductor (NMOS) based microcontroller, but later versions were based on
complementary metal-oxide-semiconductor (CMOS) technology. These
microcontrollers were named 80C51, where C in the name tells that it is based on
CMOS technology. It is an 8-bit microcontroller which means the data bus is 8-bit.
Therefore, it can process 8 bits at a time. It is used in a wide variety of embedded
systems like robotics, remote controls, the automotive industry, telecom applications,
power tools, etc.

It is referred to as a System on a Chip (SoC) microcontroller because it is a chip


circuit/integrated circuit that holds many components of a computer together on a
single chip. These components include a CPU, memory, input-output ports (I/O ports),
timers, and secondary storage. Features – There are some key features of 8051 that
work as a foundation for students to learn microcontrollers.

8051 μc family member –

8051 μc have some family members 8052 microcontroller & 8031


microcontroller. 8052μc has 8K bytes of on-chip program ROM instead of 4K bytes,
and 128 bytes of RAM. and 8031μc has 0K bytes of on-chip program ROM, and 128
bytes of RAM.

The Key features of the 8051 Microcontroller –


• 4 KB on-chip ROM (Program memory).

• 128 bytes on-chip RAM (Data memory).

• The 8-bit data bus (bidirectional).

• 16-bit address bus (unidirectional).

• Two 16-bit timers.

• Instruction cycle of 1 microsecond with 12 MHz crystal.

• Four 8-bit input/output ports.

• 128 user-defined flags.

• Four register banks of 8 bit each.

• 16-byte bit-addressable RAM.

• The general-purpose registers are 32 each is 8-bit.

• 8051 has two external and three internal interrupts.

• 8051 microcontroller specifies some special function features like UARTs, ADC,
Op-amp, etc.

• It has a 16-bit program counter and data pointer.

Block Diagram of 8051 μc –


Application of 8051 Microcontroller –

1. Automation: The 8051 microcontroller is widely used in automotive


applications.
They are widely used in hybrid vehicles to control engine options. In addition,
functions such as cruise control and anti-brake mechanism have been further
enhanced thanks to the integration of a microcontroller.

2. Medical Devices: Convenient medical devices such as blood glucose and blood
pressure monitors contain microcontrollers that display measurements.

3. Energy management: Competent measurement systems support energy


consumption calculations in home and industrial environments. These
measuring systems are prepared by integrating a microcontroller.

4. Touch Screen: Many microcontroller vendors incorporate touch functionality


into their designs. Portable devices such as media players, and gaming devices.

Uses of 8051 Microcontroller :

Here are some of the most common uses of the 8051 microcontroller:

1. Embedded Systems: The 8051 microcontroller is commonly used in embedded


systems, such as home automation systems, security systems, and industrial
control systems. Its low cost, small size, and ease of programming make it an
ideal choice for these applications.

2. Automotive Systems: The 8051 microcontroller is used in automotive systems,


such as engine control units, anti-lock braking systems, and airbag systems, to
control various functions and ensure safe and efficient operation.

3. Robotics: The 8051 microcontroller is used in robotics applications to control


the movement and operation of robots. It is commonly used to control the
motors, sensors, and other peripherals of the robot.

4. Consumer Electronics: The 8051 microcontroller is used in a variety of


consumer electronics products, such as digital cameras, gaming systems, and
audio players. It is commonly used to control the user interface, display, and
other peripherals of these devices.

5. Communication Systems: The 8051 microcontroller is used in communication


systems, such as modems, routers, and switches, to control the data transfer
and communication protocols.
6. Medical Devices: The 8051 microcontroller is used in medical devices, such as
insulin pumps, heart monitors, and blood glucose meters, to control various
functions and provide accurate and reliable results.

7. Industrial Control Systems: The 8051 microcontroller is used in industrial


control systems, such as process control systems and manufacturing
equipment, to control and monitor various processes and operations.

Issues in 8051 Microcontroller :

Here are some of the common issues in the 8051 microcontroller:

1. Limited Memory: The 8051 microcontroller has limited program memory and
data memory. The program memory is typically 4 KB or 8 KB, and the data
memory is typically 128 bytes or 256 bytes. This limitation can be an issue when
developing complex applications that require more memory.

2. Limited Processing Power: The 8051 microcontroller has limited processing


power compared to modern microcontrollers. Its clock speed is typically
between 12 MHz and 24 MHz, and its instruction set is limited. This limitation
can be an issue when developing complex applications that require high
processing power.

3. Limited Peripheral Support: The 8051 microcontroller has limited support for
peripherals compared to modern microcontrollers. It has a limited number of
input/output pins, and its communication interfaces are limited. This limitation
can be an issue when developing applications that require a large number of
peripherals.

4. Limited Development Tools: The development tools for the 8051


microcontrollers are limited compared to modern microcontrollers. The
available compilers, debuggers, and simulators are not as advanced as those
available for modern microcontrollers. This limitation can be an issue when
developing complex applications that require advanced development tools.

5. Limited Security Features: The 8051 microcontrollers have limited security


features compared to modern microcontrollers. It does not have hardware
security features, such as memory protection and encryption, which can be an
issue in applications that require high security.

Pin diagram of 8051 Microcontroller


The 8051 microcontroller is a popular 8-bit microcontroller widely used in embedded
systems. It is a single-chip microcontroller with a Harvard architecture that includes a
CPU, RAM, ROM, and several peripherals. The 8051 microcontroller has a 40-pin dual
in-line package (DIP) that provides various inputs and outputs for communication with
external devices.

8051 microcontroller is a 40 pin Dual Inline Package (DIP). These 40 pins serve
different functions like read, write, I/O operations, interrupts etc. 8051 has four I/O
ports wherein each port has 8 pins which can be configured as input or output
depending upon the logic state of the pins. Therefore, 32 out of these 40 pins are
dedicated to I/O ports. The rest of the pins are dedicated to VCC, GND, XTAL1, XTAL2,
RST, ALE, EA’ and PSEN’. Pin diagram of 8051 microprocessor is as given below:
Description of the Pins:

• Pin 1 to Pin 8 (Port 1) – Pin 1 to Pin 8 are assigned to Port 1 for simple I/O
operations. They can be configured as input or output pins depending on the
logic control i.e. if logic zero (0) is applied to the I/O port it will act as an output
pin and if logic one (1) is applied the pin will act as an input pin. These pins are
also referred to as P1.0 to P1.7 (where P1 indicates that it is a pin in port 1 and
the number after ‘.’ tells the pin number i.e. 0 indicates first pin of the port. So,
P1.0 means first pin of port 1, P1.1 means second pin of the port 1 and so on).
These pins are bidirectional pins.

• Pin 9 (RST) – Reset pin. It is an active-high, input pin. Therefore, if the RST pin
is high for a minimum of 2 machine cycles, the microcontroller will reset i.e. it
will close and terminate all activities. It is often referred as “power-on-reset” pin
because it is used to reset the microcontroller to its initial values when power is
on (high).

• Pin 10 to Pin 17 (Port 3) – Pin 10 to pin 17 are port 3 pins which are also
referred to as P3.0 to P3.7. These pins are similar to port 1 and can be used as
universal input or output pins. These pins are bidirectional pins. These pins also
have some additional functions which are as follows:

• P3.0 (RXD): 10th pin is RXD (serial data receive pin) which is for serial
input. Through this input signal microcontroller receives data for serial
communication.

• P3.1 (TXD): 11th pin is TXD (serial data transmit pin) which is serial
output pin. Through this output signal microcontroller transmits data for
serial communication.

• P3.2 and P3.3 (INT0′, INT1′): 12th and 13th pins are for External
Hardware Interrupt 0 and Interrupt 1 respectively. When this interrupt is
activated (i.e. when it is low), 8051 gets interrupted in whatever it is doing
and jumps to the vector value of the interrupt (0003H for INT0 and
0013H for INT1) and starts performing Interrupt Service Routine (ISR)
from that vector location.

• P3.4 and P3.5 (T0 and T1): 14th and 15th pin are for Timer 0 and Timer
1 external input. They can be connected with 16-bit timer/counter.

• P3.6 (WR’): 16th pin is for external memory write i.e. writing data to the
external memory.

• P3.7 (RD’): 17th pin is for external memory read i.e. reading data from
external memory.
• Pin 18 and Pin 19 (XTAL2 And XTAL1) – These pins are connected to an
external oscillator which is generally a quartz crystal oscillator. They are used to
provide an external clock frequency of 4MHz to 30MHz.

• Pin 20 (GND) – This pin is connected to the ground. It has to be provided with
0V power supply. Hence it is connected to the negative terminal of the power
supply.

• Pin 21 to Pin 28 (Port 2) – Pin 21 to pin 28 are port 2 pins also referred to as
P2.0 to P2.7. When additional external memory is interfaced with the 8051
microcontroller, pins of port 2 act as higher-order address bytes. These pins are
bidirectional.

• Pin 29 (PSEN) – PSEN stands for Program Store Enable. It is output, active-low
pin. This is used to read external memory. In 8031 based system where, external
ROM holds the program code, this pin is connected to the OE pin of the ROM.

• Pin 30 (ALE/ PROG) – ALE stands for Address Latch Enable. It is input, active-
high pin. This pin is used to distinguish between memory chips when multiple
memory chips are used. It is also used to de-multiplex the multiplexed address
and data signals available at port 0. During flash programming i.e. Programming
of EPROM, this pin acts as program pulse input (PROG).

• Pin 31 (EA/ VPP) – EA stands for External Access input. It is used to


enable/disable external memory interfacing. In 8051, EA is connected to Vcc as
it comes with on-chip ROM to store programs. For other family members such
as 8031 and 8032 in which there is no on-chip ROM, the EA pin is connected to
the GND.

• Pin 32 to Pin 39 (Port 0) – Pin 32 to pin 39 are port 0 pins also referred to as
P0.0 to P0.7. They are bidirectional input/output pins. They don’t have any
internal pull-ups. Hence, 10 K? pull-up registers are used as external pull-ups.
Port 0 is also designated as AD0-AD7 because 8051 multiplexes address and
data through port 0 to save pins.

• Pin 40 (VCC) – This pin provides power supply voltage i.e. +5 Volts to the
circuit.

The pin diagram of the 8051 microcontroller is as follows:

1. VCC: This pin is connected to the power supply and provides a voltage of +5V
to the microcontroller.

2. GND: This pin is connected to the ground and serves as the reference voltage
for the microcontroller.
3. XTAL1 and XTAL2: These pins are used for connecting an external crystal
oscillator that provides the clock signal for the microcontroller.

4. Reset: This pin is used for resetting the microcontroller. A high pulse on this
pin resets the microcontroller to its initial state.

5. Port 1: This is an 8-bit bidirectional input/output port that can be used for
interfacing with external devices.

6. Port 2: This is an 8-bit bidirectional input/output port that can be used for
interfacing with external devices.

7. Port 3: This is an 8-bit bidirectional input/output port that can be used for
interfacing with external devices.

8. Port 4: This is an 8-bit bidirectional input/output port that can be used for
interfacing with external devices.

9. INT0: This is an external interrupt 0 input pin.

10. INT1: This is an external interrupt 1 input pin.

11. T0: This is an external timer 0 input pin.

12. T1: This is an external timer 1 input pin.

13. WR: This is the write signal for external memory.

14. RD: This is the read signal for external memory.

15. ALE: This is the address latch enable signal that is used to latch the address
for external memory.

16. PSEN: This is the program store enable signal that is used for accessing the
program memory.

17. 17-24. Address bus: These pins are used for transmitting the address
information to the external memory.

18. 25-32. Data bus: These pins are used for transmitting the data between the
microcontroller and external memory.

19. RST: This is the output signal that indicates the microcontroller is being reset.

20. EA: This is the external access enable signal that is used for selecting the
program memory.

21. VPP: This pin is used for programming the microcontroller.

22. 36-39. XTAL: These pins are used for connecting an external crystal oscillator.
23. P1.0 (AD0) – P1.7 (AD7): These pins are used for interfacing with external
analog devices.

Uses of pin diagram of the 8051 microcontroller:

The pin diagram of the 8051 microcontroller is used for various purposes in embedded
systems. Some of the main uses of the pin diagram are:

1. Interfacing with external devices: The 8051 microcontroller has several


input/output pins that can be used for interfacing with external devices such as
sensors, actuators, displays, and communication modules. The pin diagram
provides the information about the location of these pins, their functionalities,
and their electrical characteristics.

2. Programming the microcontroller: The 8051 microcontroller can be


programmed using various programming languages such as Assembly, C, and
BASIC. The pin diagram provides the information about the pins that are used
for programming the microcontroller, such as the PSEN pin and the ALE pin.

3. Debugging and testing: The pin diagram provides access to the internal
signals of the microcontroller, such as the address and data buses, which can
be used for debugging and testing the microcontroller. Special hardware tools
such as logic analyzers and oscilloscopes can be connected to the pins to
monitor the signals and diagnose any issues in the system.

4. Expansion and customization: The pin diagram provides the flexibility to


expand and customize the functionality of the microcontroller by connecting
external devices and peripherals. For example, additional memory can be added
by connecting external RAM or ROM chips to the address and data buses.

Issues in pin diagram of the 8051 microcontroller :

1. Power supply voltage: The 8051 microcontroller requires a stable power


supply voltage of 5V. If the voltage is not stable or drops below the required
level, it can cause the microcontroller to malfunction.

2. Input/output current: Each pin of the 8051 microcontroller has a maximum


current rating, and exceeding this rating can cause damage to the
microcontroller or other components connected to it. It is important to ensure
that the input/output current is within the specified limits.

3. Input/output voltage: The 8051 microcontroller has specific voltage


requirements for its input/output pins. If the voltage is too high or too low, it
can cause the microcontroller to malfunction or even damage it.
4. Interference: External interference such as electromagnetic interference (EMI)
and radio frequency interference (RFI) can affect the performance of the 8051
microcontroller, particularly if the pins are not properly shielded.

5. Pin conflicts: When using multiple peripherals or devices with the 8051
microcontroller, there can be conflicts between the pins used by different
devices. Careful planning and circuit design is required to avoid pin conflicts
and ensure proper functionality of all devices.

Comparison between Microcontroller and Microprocessor

Microcontroller Microprocessor

A microcontroller is a specialized The microprocessor is designed to be


form of a microprocessor general-purpose.
It is cost-effective. It is a silicon chip
It is self-sufficient. It is a dependent unit
The microcontroller is used to The Microprocessor is
perform a particular task. used to perform a certain task.
Its power consumption is low. Its power consumption is high.
It contains CPU, RAM, ROM, It requires a combination of timers,
Registers, Timer and input/output controllers
ports. memory chips.
Its size is smaller. Its size is larger.
It is a chip which is called single chip It is a general-purpose device which is
computer. called a CPU.
Microcontroller have no advantage of It has advantages of versatility such that
designing RAM, ROM, I/O port. designer can decide the amount of RAM,
ROM, I/O port as needed.

Its microprocessor’s processing Its processing power is higher.


power is lower than microprocessor.

It uses Harvard Architecture. It uses Von Neumann Architecture.


Its system cost is low. Its system cost is high.
Each instruction needs an internal Each instruction needs an external
operation. operation.
For Example- Television. For Example- Personal Computers.

Feature Microcontroller (µC) Microprocessor (µP)


Purpose Designed for specific Designed for general-
embedded system purpose computing
applications applications
Architecture Single-chip computer CPU with minimal on-
system with on-board board memory,
memory, peripherals, and peripherals, and I/O
I/O interfaces interfaces

Integration level Highly integrated Less integrated


System architecture Single-chip system CPU + support chips
Processing power Lower power Higher power
Instruction set Fixed instruction set More flexible
On-board memory On-chip memory No on-board memory
Input/Output (I/O) More I/O ports Fewer I/O ports
Peripheral devices On-board peripherals External peripherals
Cost Lower cost Higher cost
Power consumption Lower power Higher power
Applications Embedded systems General-purpose
Development Integrated development Standard development
environment (IDE) provided tools and languages such
by manufacturers, with as C, C++, and assembly
specialized programming
languages and tools
Clock speed Lower clock speed, typically Higher clock speed,
less than 100 MHz typically greater than 1
GHz

Input output ports of 8051

8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input
or output. Hence, total 32 input/output pins allow the microcontroller to be connected
with the peripheral devices.

• Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output
as per the logic state.

o Input/Output (I/O) pin − All the circuits within the microcontroller must
be connected to one of its pins except P0 port because it does not have
pull-up resistors built-in.

o Input pin − Logic 1 is applied to a bit of the P register. The output FE


transistor is turned off and the other pin remains connected to the power
supply voltage over a pull-up resistor of high resistance.

• Port 0 − The P0 (zero) port is characterized by two functions −


o When the external memory is used then the lower address byte
(addresses A0A7) is applied on it, else all bits of this port are configured
as input/output.

o When P0 port is configured as an output then other ports consisting of


pins with built-in pull-up resistor connected by its end to 5V power
supply, the pins of this port have this resistor left out.

Input Configuration

If any pin of this port is configured as an input, then it acts as if its “floats”, i.e. the input
has unlimited input resistance and in-determined potential.

Output Configuration

When the pin is configured as an output, then it acts as an “open drain”. By applying
logic 0 to a port bit, the appropriate pin will be connected to ground (0V), and applying
logic 1, the external output will keep on “floating”.

In order to apply logic 1 (5V) on this output pin, it is necessary to build an external
pullup resistor.

Port 1

P1 is a true I/O port as it doesn’t have any alternative functions as in P0, but this port
can be configured as general I/O only. It has a built-in pull-up resistor and is
completely compatible with TTL circuits.

Port 2

P2 is similar to P0 when the external memory is used. Pins of this port occupy addresses
intended for the external memory chip. This port can be used for higher address byte
with addresses A8-A15. When no memory is added then this port can be used as a
general input/output port similar to Port 1.

Port 3

In this port, functions are similar to other ports except that the logic 1 must be applied
to appropriate bit of the P3 register.

Pins Current Limitations

• When pins are configured as an output (i.e. logic 0), then the single port pins
can receive a current of 10mA.

• When these pins are configured as inputs (i.e. logic 1), then built-in pull-up
resistors provide very weak current, but can activate up to 4 TTL inputs of LS
series.
• If all 8 bits of a port are active, then the total current must be limited to 15mA
(port P0: 26mA).

• If all ports (32 bits) are active, then the total maximum current must be limited
to 71mA.

counter & timers

In Intel 8051, there are two 16-bit timer registers. These registers are known as Timer0
andTimer1. The timer registers can be used in two modes. These modes are Timer
mode and the Counter mode. The only difference between these two modes is the
source for incrementing the timer registers.

Timer Mode

In the timer mode, the internal machine cycles are counted. So, this register is
incremented in each machine cycle. So, when the clock frequency is 12MHz, then the
timer register is incremented in each millisecond. In this mode it ignores the external
timer input pin.

Counter Mode

In the counter mode, the external events are counted. In this mode, the timer register
is incremented for each 1 to 0 transition of the external input pin. This type of
transitions is treated as events. The external input pins are sampled once in each
machine cycle, and to determine the 1or 0 transitions, another machine cycle will be
needed. So, in this mode, at least two machine cycles are needed. When the frequency
is12MHz, then the maximum count frequency will be 12MHz/24 = 500KHz. So, for
event counting the time duration is 2 µs.

There are four different modes of the Timer or Counter. The Mode 0 to Mode 2 is for
both of the Timer/Counter. Mode 3 has a different meaning for each timer register.
There is a register called TMOD. This register can be programmed to configure these
timers or counters.

The Serial port is used for serial communication in mode 1 and 3. Timer1 is used for
generating the baud rate. So only Timer0 is available for timer or counter operations.

TMOD Register

TMOD (Timer Mode) is an SFR. The address of this register is 89H. This is not bit-
addressable.

Timer Timer1 Mode Timer0 Mode


Bit Details Gate (G) C/T M1 M0 Gate (G) C/T M1 M0

Now, let us see the circuit that controls the running of the timers.

In the following table, we will see the bit details and their different operations for high
or low value.

Bit High Value (1) Low Value (0)


Details

C/T Configure for the Counter Configure for the Timer operations
operations

Gate (G) Timer0 or Timer1 will be in Run Timer0 or Timer1 will be in Run
Mode when TRX bit of TCON register Mode when TRX bit of TCON
is high. register is high and INT0 or INT1 is
high.

Bit 00 01 10 11
Details

M1 M0 This is for Mode This is Mode 1. This is Mode 3 This is Mode 3


0. (8-bit (16-bit (8-bit auto (The function
timer/counter, timer/counter) reload- depends on
with 5-bit pre- timer/counter) Timer0 or
scaler) Timer1)
The Gate bit will be high when the timer or counter is in mode 0 to 2.

Examples

To configure the Timer0 as 16-bit event counter and Timer1 as 8-bit auto reload
counter, we can use the bit pattern 0 0 1 0 0 1 0 1. It is equivalent to 25H. If we want
to program the TMOD register with this bit pattern, we can use this instruction:

MOVTMOD, #25H

The above instruction is executed, then the timer/counter will be controlled by the
software. To configure the system as hardware-controlled mode, then the gate bits will
be 1. So, the bit patterns will be 1 0 1 0 1 1 0 1 = ADH

we can use this instruction:

MOVTMOD, #0ADH

Mode 0 of Timer/Counter

The Mode 0 operation is the 8-bit timer or counter with a 5-bit pre-scaler. So, it is a
13-bit timer/counter. It uses 5 bits of TL0 or TL1 and all of the 8-bits of TH0 or TH1.

In this example the Timer1is selected, in this case, every 32 (25) events for counter
operations or 32 machine cycles for timer operation, the TH1 register will be
incremented by 1. When the TH1overflows from FFH to 00H, then the TF1 of TCON
register will be high, and it stops the timer/counter. So, for an example, we can say
that if the TH1 is holding F0H, and it is in timer mode, then TF1will be high after 10H *
32 = 512 machine cycles.

MOVTMOD, #00H

MOVTH1, #0F0H

MOVIE, #88H

SETB TR1
In the above program, the Timer1 is configured as timer mode 0. In this case Gate = 0.
Then the TH1 will be loaded with F0H, then enable the Timer1 interrupt. At last, set the
TR1 of TCON register, and start the timer.

Mode 1 of Timer/Counter

The Mode 1 operation is the 16-bit timer or counter. In the following diagram, we are
using Mode 1 for Timer0.

In this case every event for counter operations or machine cycles for timer operation,
the TH0– TL0 register-pair will be incremented by 1. When the register pair overflows
from FFFFH to 0000H, then the TF0 of TCON register will be high, and it stops the
timer/counter. So, for an example, we can say that if the TH0 – TL0 register pair is
holding FFF0H, and it is in timer mode, then TF0 will be high after 10H = 16 machine
cycles. When the clock frequency is 12MHz, then the following instructions generate
an interrupt 16 µs after Timer0 starts running.

MOVTMOD, #01H

MOVTL0, #0F0H

MOVTH0, #0FFH

MOVIE, #82H

SETB TR0

In the above program, the Timer0 is configured as timer mode 1. In this case Gate = 0.
Then the TL0 will be loaded with F0H and TH0 is loaded with FFH, then enable the
Timer0 interrupt. At last, set the TR0 of TCON register, and start the timer.

Mode 2 of Timer/Counter

The Mode 2 operation is the 8-bit auto reload timer or counter. In the following
diagram, we are using Mode 2 for Timer1.
In this case every event for counter operations or machine cycles for timer operation,
the TL1register will be incremented by 1. When the register pair overflows from FFH
to 00H, then the TF1 of TCON register will be high, also theTL1 will be reloaded with
the content of TH1 and starts the operation again.

So, for an example, we can say that if the TH1 and TL1 register both are holding F0H
and it is in timer mode, then TF1 will be high after 10H= 16 machine cycles. When the
clock frequency is 12MHz this happens after 16 µs, then the following instructions
generate an interrupt once every 16 µs after Timer1 starts running.

MOVTMOD, #20H

MOVTL1, #0F0H

MOVTH1, #0F0H

MOVIE, #88H

SETBTR1

In the above program, the Timer1 is configured as timer mode 2. In this case Gate = 0.
Then the TL1 and TH1 are loaded with F0H. then enable the Timer1 interrupt. At last,
set the TR1 of TCON register, and start the timer.

Timer1 in mode 2 generates the desired baud rate when the serial port is working on
Mode 1 or 3.

Mode 3 of Timer/Counter

Mode 3 is different for Timer0 and Timer1. When the Timer0 is working in mode 3, the
TL0 will be used as an 8-bit timer/counter. It will be controlled by the standard Timer0
control bits, T0 and INT0 inputs. The TH0 is used as an 8-bit timer but not the counter.
This is controlled by Timer1 Control bit TR1. When the TH0 overflows from FFH to 00H,
then TF1 is set to 1. In the following diagram, we can Timer0 in Mode 3.
When the Timer1 is working in Mode 3, it simply holds the count but does not run.
When Timer0 is in mode 3, the Timer1 is configured in one of the modes 0, 1 and 2. In
this case, the Timer1 cannot interrupt the microcontroller. When the TF1 is used by
TH0 timer, the Timer1 is used as Baud Rate Generator.

The meaning of gate bit in Timer0 and Timer1 for mode 3 is as follows

It controls the running of 8-bit timer/counter TL0 as like Mode 0, 1, or 2. The running
of TH0 is controlled by TR1 bit only. So, the gate bit in this mode for Timer0 has no
specific role.

The mode 3 is present for applications requiring an extra 8-bit timer/counter. In Mode
3 of Timer0, the 8051 has three timers. One 8-bit timer by TH0, another8-bit
timer/counter by TL0, and one 16-bit timer/counter by Timer1.

If the Timer0 is in mode3, and Timer1 is working on either 0, 1 or 2, then the gun
control of the Timer1 is activated when the gate bit is low or INT1 is high. The run
control is deactivated when the gate is high and INT1 is low.

8051 Microcontroller Architecture


Basic components present internally inside 8051 Microcontroller architecture are:

CPU (Central Processing Unit): CPU act as a mind of any processing machine. It
synchronizes and manages all processes that are carried out in microcontroller. User
has no power to control the functioning of CPU. It interprets the program stored in
ROM and carries out from storage and then performs it projected duty. CPU manage
the different types of registers available in 8051 microcontroller.

Interrupts: Interrupts is a sub-routine call that given by the microcontroller when


some other program with high priority is request for acquiring the system buses the n
interrupts occur in current running program.

Interrupts provide a method to postpone or delay the current process, performs a sub-
routine task and then restart the standard program again.

Types of interrupts in 8051 Microcontroller:

Let's see the five sources of interrupts in 8051 Microcontroller:

o Timer 0 overflow interrupt - TF0


o Timer 1 overflow interrupt - TF1
o External hardware interrupt - INT0
o External hardware interrupt - INT1
o Serial communication interrupt - RI/TI
Memory: For operation Micro-controller required a program. This program guides the
microcontroller to perform the specific tasks. This program installed in microcontroller
required some on chip memory for the storage of the program.

Microcontroller also required memory for storage of data and operands for the short
duration. In microcontroller 8051 there is code or program memory of 4 KB that is it
has 4 KB ROM and it also comprise of data memory (RAM) of 128 bytes.

Bus: Bus is a group of wires which uses as a communication canal or acts as means of
data transfer. The different bus configuration includes 8, 16 or more cables. Therefore,
a bus can bear 8 bits, 16 bits all together.

Types of buses in 8051 Microcontroller:

Let's see the two types of bus used in 8051 microcontroller:

o Address Bus: 8051 microcontrollers are consisting of 16-bit address bus. It is


generally be used for transferring the data from Central Processing Unit to
Memory.
o Data bus: 8051 microcontroller is consisting of 8 bits data bus. It is generally
be used for transferring the data from one peripherals position to other
peripherals.

Oscillator: As the microcontroller is digital circuit therefore it needs timer for their
operation. To perform timer operation inside microcontroller it required externally
connected or on-chip oscillator. Microcontroller is used inside an embedded system
for managing the function of devices. Therefore, 8051 uses the two 16-bit counters
and timers. For the operation of this timers and counters the oscillator is used inside
microcontroller.

Addressing modes of 8051

There are different addressing modes of the 8051 microcontrollers. In 8051 there are
1-byte, 2-byte instructions and very few 3-byte instructions are present. The opcodes
are 8-bit long. As the opcodes are 8-bit data, there are 256 possibilities. Among 256,
255 opcodes are implemented.

The clock frequency is12MHz, so 64 instruction types are executed in just 1 µs, and
rest are just 2 µs. The Multiplication and Division operations take 4 µsto to execute.

In 8051 There are six types of addressing modes


• Immediate Addressing Mode

• Register Addressing Mode

• Direct Addressing Mode

• Register Indirect Addressing Mode

• Indexed Addressing Mode

• Implied Addressing Mode

Immediate addressing mode

In this Immediate Addressing Mode, the data is provided in the instruction itself. The
data is provided immediately after the opcode. These are some examples of Immediate
Addressing Mode.

MOVA, #0AFH;

MOVR3, #45H;

MOVDPTR, #FE00H;

In these instructions, the # symbol is used for immediate data. In the last instruction,
there is DPTR. The DPTR stands for Data Pointer. Using this, it points the external data
memory location. In the first instruction, the immediate data is AFH, but one 0 is added
at the beginning. So, when the data is starting with A to F, the data should be preceded
by 0.

Register addressing mode

In the register addressing mode the source or destination data should be present in a
register (R0 to R7). These are some examples of Register Addressing Mode.

MOVA, R5;

MOVR2, #45H;

MOVR0, A;

In 8051, there is no instruction like MOVR5, R7. But we can get the same result by
using this instruction MOV R5, 07H, or by using MOV 05H, R7. But these two
instructions will work when the selected register bank is RB0. To use another register
bank and to get the same effect, we have to add the starting address of that register
bank with the register number. For an example, if the RB2 is selected, and we want to
access R5, then the address will be (10H + 05H = 15H), so the instruction will look like
this MOV 15H, R7. Here 10H is the starting address of Register Bank 2.

Direct Addressing Mode


In the Direct Addressing Mode, the source or destination address is specified by using
8-bit data in the instruction. Only the internal data memory can be used in this mode.
Here some of the examples of direct Addressing Mode.

MOV80H, R6;

MOVR2, 45H;

MOVR0, 05H;

The first instruction will send the content of registerR6 to port P0 (Address of Port 0 is
80H). The second one is forgetting content from 45H to R2. The third one is used to
get data from Register R5 (When register bank RB0 is selected) to register R5.

Register indirect addressing Mode

In this mode, the source or destination address is given in the register. By using register
indirect addressing mode, the internal or external addresses can be accessed. The R0
and R1 are used for 8-bit addresses, and DPTR is used for 16-bit addresses, no other
registers can be used for addressing purposes. Let us see some examples of this mode.

MOV0E5H, @R0;

MOV@R1, 80H

In the instructions, the @ symbol is used for register indirect addressing. In the first
instruction, it is showing that theR0 register is used. If the content of R0 is 40H, then
that instruction will take the data which is located at location 40H of the internal RAM.
In the second one, if the content of R1 is 30H, then it indicates that the content of port
P0 will be stored at location 30H in the internal RAM.

MOVXA, @R1;

MOV@DPTR, A;

In these two instructions, the X in MOVX indicates the external data memory. The
external data memory can only be accessed in register indirect mode. In the first
instruction if the R0 is holding 40H, then A will get the content of external RAM
location40H. And in the second one, the content of A is overwritten in the location
pointed by DPTR.

Indexed addressing mode

In the indexed addressing mode, the source memory can only be accessed from
program memory only. The destination operand is always the register A. These are
some examples of Indexed addressing mode.

MOVCA, @A+PC;
MOVCA, @A+DPTR;

The C in MOVC instruction refers to code byte. For the first instruction, let us consider
A holds 30H. And the PC value is1125H. The contents of program memory location
1155H (30H + 1125H) are moved to register A.

Implied Addressing Mode

In the implied addressing mode, there will be a single operand. These types of
instruction can work on specific registers only. These types of instructions are also
known as register specific instruction. Here are some examples of Implied Addressing
Mode.

RLA;

SWAPA;

These are 1- byte instruction. The first one is used to rotate the A register content to
the Left. The second one is used to swap the nibbles in A.

Types of Instructions in 8051 Microcontroller Instruction Set

Before seeing the types of instructions, let us see the structure of the 8051
Microcontroller Instruction. An 8051 Instruction consists of an Opcode (short of
Operation – Code) followed by Operand(s) of size Zero Byte, One Byte or Two Bytes.

The Op-Code part of the instruction contains the Mnemonic, which specifies the type
of operation to be performed. All Mnemonics or the Opcode part of the instruction
are of One Byte size.

Coming to the Operand part of the instruction, it defines the data being processed by
the instructions. The operand can be any of the following:

• No Operand

• Data value

• I/O Port

• Memory Location

• CPU register

There can multiple operands and the format of instruction is as follows:

MNEMONIC DESTINATION OPERAND, SOURCE OPERAND

A simple instruction consists of just the opcode. Other instructions may include one or
more operands. Instruction can be one-byte instruction, which contains only opcode,
or two-byte instructions, where the second byte is the operand or three byte
instructions, where the operand makes up the second and third byte.

Based on the operation they perform, all the instructions in the 8051 Microcontroller
Instruction Set are divided into five groups. They are:

• Data Transfer Instructions

• Arithmetic Instructions

• Logical Instructions

• Boolean or Bit Manipulation Instructions

• Program Branching Instructions

We will now see about these instructions briefly.

Data Transfer Instructions

The Data Transfer Instructions are associated with transfer of data between registers
or external program memory or external data memory. The Mnemonics associated
with Data Transfer are given below.

• MOV

• MOVC

• MOVX

• PUSH

• POP

• XCH

• XCHD
Mnemonic Description

MOV Move Data

MOVC Move Code

MOVX Move External Data

PUSH Move Data to Stack

POP Copy Data from Stack

XCH Exchange Data between two Registers

XCHD Exchange Lower Order Data between two Registers


The following table lists out all the possible data transfer instructions along with other
details like addressing mode, size occupied and number machine cycles it takes.

Arithmetic Instructions

Using Arithmetic Instructions, you can perform addition, subtraction, multiplication


and division. The arithmetic instructions also include increment by one, decrement by
one and a special instruction called Decimal Adjust Accumulator.

The Mnemonics associated with the Arithmetic Instructions of the 8051


Microcontroller Instruction Set are:

• ADD

• ADDC

• SUBB

• INC

• DEC
• MUL

• DIV

• DA A

Mnemonic Description

ADD Addition without Carry

ADDC Addition with Carry

SUBB Subtract with Carry

INC Increment by 1

DEC Decrement by 1

MUL Multiply

DIV Divide

DA A Decimal Adjust the Accumulator (A Register)

The arithmetic instructions have no knowledge about the data format i.e., signed,
unsigned, ASCII, BCD, etc. Also, the operations performed by the arithmetic
instructions affect flags like carry, overflow, zero, etc. in the PSW Register.

All the possible Mnemonics associated with Arithmetic Instructions are mentioned in
the following table.
Logical Instructions

The next group of instructions are the Logical Instructions, which perform logical
operations like AND, OR, XOR, NOT, Rotate, Clear and Swap. Logical Instruction are
performed on Bytes of data on a bit-by-bit basis.

Mnemonics associated with Logical Instructions are as follows:

• ANL

• ORL

• XRL

• CLR

• CPL

• RL

• RLC
• RR

• RRC

• SWAP

Mnemonic Description

ANL Logical AND

ORL Logical OR

XRL Ex-OR

CLR Clear Register

CPL Complement the Register

RL Rotate a Byte to Left

RLC Rotate a Byte and Carry Bit to Left

RR Rotate a Byte to Right

RRC Rotate a Byte and Carry Bit to Right

SWAP Exchange lower and higher nibbles in a Byte

The following table shows all the possible Mnemonics of the Logical Instructions.
Boolean or Bit Manipulation Instructions

As the name suggests, Boolean or Bit Manipulation Instructions deal with bit variables.
We know that there is a special bit-addressable area in the RAM and some of the
Special Function Registers (SFRs) are also bit addressable.

The Mnemonics corresponding to the Boolean or Bit Manipulation instructions are:

• CLR

• SETB

• MOV

• JC

• JNC

• JB

• JNB

• JBC

• ANL

• ORL

• CPL

Mnemonic Description

CLR Clear a Bit (Reset to 0)

SETB Set a Bit (Set to 1)

MOV Move a Bit

JC Jump if Carry Flag is Set

JNC Jump if Carry Flag is Not Set

JB Jump if specified Bit is Set

JNB Jump if specified Bit is Not Set

JBC Jump if specified Bit is Set and also clear the Bit

ANL Bitwise AND

ORL Bitwise OR

CPL Complement the Bit


These instructions can perform set, clear, and, or, complement etc. at bit level. All the
possible mnemonics of the Boolean Instructions are specified in the following table.

Program Branching Instructions

The last group of instructions in the 8051 Microcontroller Instruction Set are the
Program Branching Instructions. These instructions control the flow of program logic.
The mnemonics of the Program Branching Instructions are as follows.

• LJMP

• AJMP

• SJMP

• JZ

• JNZ

• CJNE

• DJNZ
• NOP

• LCALL

• ACALL

• RET

• RETI

• JMP

Mnemonic Description

LJMP Long Jump (Unconditional)

AJMP Absolute Jump (Unconditional)

SJMP Short Jump (Unconditional)

JZ Jump if A is equal to 0

JNZ Jump if A is not equal to 0

CJNE Compare and Jump if Not Equal

DJNZ Decrement and Jump if Not Zero

NOP No Operation

LCALL Long Call to Subroutine

ACALL Absolute Call to Subroutine (Unconditional)

RET Return from Subroutine

RETI Return from Interrupt

JMP Jump to an Address (Unconditional)

All these instructions, except the NOP (No Operation) affect the Program Counter (PC)
in one way or other. Some of these instructions has decision making capability before
transferring control to other part of the program.

The following table shows all the mnemonics with respect to the program branching
instructions.

You might also like