0% found this document useful (0 votes)
4 views23 pages

rgasc's Network security, Microprocessor and microcontrollers 1

The document provides an overview of the Intel 8051 microcontroller, detailing its architecture, memory organization, instruction set, and various applications in embedded systems. It distinguishes between microcontrollers and microprocessors, categorizes types of microcontrollers, and outlines the internal components and functions of the 8051. Additionally, it discusses the special function registers, pins, and signals associated with the 8051 microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views23 pages

rgasc's Network security, Microprocessor and microcontrollers 1

The document provides an overview of the Intel 8051 microcontroller, detailing its architecture, memory organization, instruction set, and various applications in embedded systems. It distinguishes between microcontrollers and microprocessors, categorizes types of microcontrollers, and outlines the internal components and functions of the 8051. Additionally, it discusses the special function registers, pins, and signals associated with the 8051 microcontroller.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

MODULE – V

Microcontroller: Intel 8051 Microcontroller: Introduction – Architecture – Memory


Organization – Special Function Registers – Pins and Signals – Timing and control – Port
Operation – Memory and I/O interfacing – Interrupts – Instruction Set and Programming.

Introduction :
A microcontroller (MCU) is a small computer on a single integrated circuit that is
designed to control specific tasks within electronic systems.
It combines the functions of a central processing unit (CPU), memory, and
input/output interfaces, all on a single chip.
Microcontrollers are widely used in embedded systems, such as home appliances,
automotive systems, medical devices, and industrial control systems. They are also used in
consumer electronics products, such as gaming systems, digital cameras, and audio players.
A typical microcontroller consists of a processor core, volatile and non-volatile
memory, input/output peripherals, and various communication interfaces.
The processor core is responsible for executing instructions and controlling the other
components of the microcontroller.
The memory is used to store data and program code, while the input/output
peripherals are used to interact with the external environment.

Microcontrollers are programmable, which means that they can be customized to


perform specific tasks. The programming languages used to write code for microcontrollers
vary depending on the manufacturer and the type of microcontroller. Some of the commonly
used programming languages include C, C++, and assembly language.
A microcontroller is a self-contained desktop that can be utilized in an embedded
system. A few microcontrollers may run at clock rate rates and use four-bit expressions.
Because many of the devices they control are battery-operated, microcontrollers must often
be low-power.
Microcontrollers are found in a wide range of products, including consumer
electronics, automobile engines, computer peripherals, and test and measurement equipment.
These are also well-suited to long-term battery usage. The vast majority of microcontrollers
in use today are embedded in other devices.
The microcontroller used in Embedded System. for example:
• Security Systems
• Laser Printers
• Automation System
• Robotics

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Difference between Microprocessor and Microcontroller
The following table highlights the differences between a microprocessor and a
microcontroller −

Microcontroller Microprocessor

Microcontrollers are used to execute a


Microprocessors are used for big applications.
single task within an application.

Its designing and hardware cost is low. Its designing and hardware cost is high.

Easy to replace. Not so easy to replace.

It is built with CMOS technology, which Its power consumption is high because it has to
requires less power to operate. control the entire system.

It consists of CPU, RAM, ROM, I/O It doesn’t consist of RAM, ROM, I/O ports. It uses
ports. its pins to interface to peripheral devices.

Types of Microcontrollers
Microcontrollers are divided into various categories based on memory, architecture, bits and
instruction sets. Following is the list of their types −
Bit
Based on bit configuration, the microcontroller is further divided into three categories.
 8-bit microcontroller − This type of microcontroller is used to execute arithmetic
and logical operations like addition, subtraction, multiplication division, etc. For
example, Intel 8031 and 8051 are 8 bits microcontroller.
 16-bit microcontroller − This type of microcontroller is used to perform arithmetic
and logical operations where higher accuracy and performance is required. For
example, Intel 8096 is a 16-bit microcontroller.
 32-bit microcontroller − This type of microcontroller is generally used in
automatically controlled appliances like automatic operational machines, medical
appliances, etc.
Memory
Based on the memory configuration, the microcontroller is further divided into two
categories.
 External memory microcontroller − This type of microcontroller is designed in
such a way that they do not have a program memory on the chip. Hence, it is named
as external memory microcontroller. For example: Intel 8031 microcontroller.
 Embedded memory microcontroller − This type of microcontroller is designed in
such a way that the microcontroller has all programs and data memory, counters and
timers, interrupts, I/O ports are embedded on the chip. For example: Intel 8051
microcontroller.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Instruction Set
Based on the instruction set configuration, the microcontroller is further divided into two
categories.
 CISC − CISC stands for complex instruction set computer. It allows the user to insert
a single instruction as an alternative to many simple instructions.
 RISC − RISC stands for Reduced Instruction Set Computers. It reduces the
operational time by shortening the clock cycle per instruction.

Applications of Microcontrollers
Microcontrollers are widely used in various different devices such as −
 Light sensing and controlling devices like LED.
 Temperature sensing and controlling devices like microwave oven, chimneys.
 Fire detection and safety devices like Fire alarm.
 Measuring devices like Volt Meter.

Intel 8051 Microcontroller Architecture:

Basic components present internally inside 8051 Microcontroller architecture are:

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
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 interrupt in 8051 Microcontroller:

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

https://www.javatpoint.com/embedded-system-8051-microcontroller-architecture

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 is 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.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
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.

8051 Memory Organization:


The 8051 microcontroller's memory is divided into Program Memory and Data
Memory. Program Memory (ROM) is used for permanent saving program being executed,
while Data Memory (RAM) is used for temporarily storing and keeping intermediate results
and variables.

Program Memory (ROM):

Program Memory (ROM) is used for permanent saving program (CODE) being
executed. The memory is read only. Depending on the settings made in compiler, program
memory may also used to store a constant variables.

The 8051 executes programs stored in program memory only. code memory type
specifier is used to refer to program memory. 8051 memory organization allows external
program memory to be added. How does the microcontroller handle external memory
depends on the pin EA logical state.

Internal Data Memory:

Up to 256 bytes of internal data memory are available depending on the 8051
derivative. Locations available to the user occupy addressing space from 0 to 7Fh, i.e. first
128 registers and this part of RAM is divided in several blocks.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
The first 128 bytes of internal data memory are both directly and indirectly
addressable. The upper 128 bytes of data memory (from 0x80 to 0xFF) can be addressed only
indirectly. Since internal data memory is used for CALL stack also and there is only 256
bytes spitted over few different memory areas fine utilizing of this memory is crucial for fast
and compact code.

Memory block in the range of 20h to 2Fh is bit-addressable, which means that each
bit being there has its own address from 0 to 7Fh. Since there are 16 such registers, this block
contains in total of 128 bits with separate addresses ( Bit 0 of byte 20h has the bit address 0,
and bit 7 of byte 2Fh has the bit address 7Fh).

External Data Memory:

Access to external memory is slower than access to internal data memory. There may
be up to 64K Bytes of external data memory. Several 8051 devices provide on-chip XRAM
space that is accessed with the same instructions as the traditional external data space.

This XRAM space is typically enabled via proper setting of SFR register and overlaps
the external memory space. Setting of that register must be manually done in code, before
any access to external memory or XRAM space is made.

Types of Memory:

The 8051 has three very general types of memory. To effectively program the 8051 it
is necessary to have a basic understanding of these memory types. The memory types are
illustrated in the following graphic.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
They are: On-Chip Memory, External Code Memory, and External RAM.

On-Chip Memory refers to any memory (Code, RAM, or other) that physically exists
on the microcontroller itself.

On-chip memory can be of several types, but we'll get into that shortly. External
Code Memory is code (or program) memory that resides off-chip. This is often in the form of
an external EPROM.

External RAM is RAM memory that resides off-chip. This is often in the form of
standard static RAM or flash RAM.

Code Memory:

Code memory is the memory that holds the actual 8051 program that is to be run.
This memory is limited to 64K and comes in many shapes and sizes: Code memory may be
found on-chip, either burned into the microcontroller as ROM or EPROM.

Code may also be stored completely off-chip in an external ROM or, more
commonly, an external EPROM. Flash RAM is also another popular method of storing a
program. Various combinations of these memory types may also be used--that is to say, it is
possible to have 4K of code memory on-chip and 64k of code memory off-chip in an
EPROM.

External RAM:

External RAM is any random access memory which is found off-chip. Since the
memory is off-chip it is not as flexible in terms of accessing, and is also slower.

For example, to increment an Internal RAM location by 1 requires only 1 instruction


and 1 instruction cycle. To increment a 1-byte value stored in External RAM requires 4
instructions and 7 instruction cycles. In this case, external memory is 7 times slower!

On-Chip Memory:

As mentioned at the beginning of this chapter, the 8051 includes a certain amount of
on-chip memory. On-chip memory is really one of two types: Internal RAM and Special
Function Register (SFR) memory.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Special Function Register (SFR) Memory:

The 8051 Microcontroller Special Function Registers are used to program and control
different hardware peripherals like Timers, Serial Port, I/O Ports etc. In fact, by manipulating
the 8051 Microcontroller Special Function Registers (SFRs), you can assess or change the
operating mode of the 8051 Microcontroller.

The 8051 Microcontroller Special Function Registers act as a control table that
monitor and control the operation of the 8051 Microcontroller. If you observe in Internal
RAM Structure, the Address Space from 80H to FFH is allocated to SFRs.

Out of these 128 Memory Locations (80H to FFH), there are only 21 locations that are
actually assigned to SFRs. Each SFR has one Byte Address and also a unique name which
specifies its purpose.

Since the SFRs are a part of the Internal RAM Structure, you can access SFRs as if
you access the Internal RAM. The main difference is the address space: first 128 Bytes (00H
to 7FH) is for regular Internal RAM and next 128 Bytes (80H to FFH) is for SFRs.

Categories of 8051 Microcontroller Special Function Registers

All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their
functions and Internal RAM Address is given in the following table.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
There are many ways to categorize these 21 Special Function Registers but I find the
following way as an appropriate one. The 21 Special Function Registers of 8051
Microcontroller are categorized in to seven groups. They are:

Math or CPU Registers: A and B

Status Register: PSW (Program Status Word)

Pointer Registers: DPTR (Data Pointer – DPL, DPH) and SP (Stack Pointer)

I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3)

Peripheral Control Registers: PCON, SCON, TCON, TMOD, IE and IP

Peripheral Data Registers: TL0, TH0, TL1, TH1 and SBUF

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Pins and Signals:
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 :

 Pins 1 to 8 − These pins are known as Port 1. This port doesn’t serve any other
functions. It is internally pulled up, bi-directional I/O port.
 Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial
values.
 Pins 10 to 17 − These pins are known as Port 3. This port serves some functions like
interrupts, timer input, control signals, serial communication signals RxD and TxD,
etc.
 Pins 18 & 19 − These pins are used for interfacing an external crystal to get the
system clock.
 Pin 20 − This pin provides the power supply to the circuit.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
 Pins 21 to 28 − These pins are known as Port 2. It serves as I/O port. Higher order
address bus signals are also multiplexed using this port.
 Pin 29 − This is PSEN pin which stands for Program Store Enable. It is used to read a
signal from the external program memory.
 Pin 30 − This is EA pin which stands for External Access input. It is used to
enable/disable the external memory interfacing.
 Pin 31 − This is ALE pin which stands for Address Latch Enable. It is used to
demultiplex the address-data signal of port.
 Pins 32 to 39 − These pins are known as Port 0. It serves as I/O port. Lower order
address and data bus signals are multiplexed using this port.
 Pin 40 − This pin is used to provide power supply to the circuit.

Timer and Control:


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.

There are four different modes of the Timer or Counter. The Mode 0 to Mode 2 are
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.

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

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
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 Timer0 or Timer1 will be in


RunMode when TRX bit of RunMode when TRX bit of TCON
TCON register 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 This is Mode 3 This is Mode 3


0. (8-bit 1. (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.

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.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
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.

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.

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.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
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 mode 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 mode3 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, another 8-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.

Port Operation
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.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
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 it “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.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
MEMORY AND I/O INTERFACING

MEMORY INTERFACING

The 8051 microcontroller is a popular microcontroller used in various applications,


ranging from small embedded systems to larger industrial applications. While the 8051 has a
limited amount of internal memory, it is possible to extend the memory capacity by
interfacing it with external memory devices.

External memory interfacing in 8051 microcontroller involves connecting external


memory devices such as RAM and ROM to the microcontroller to provide additional
memory space. This allows the microcontroller to execute larger and more complex
programs, store more data, and perform more complex operations.

External memory interfacing typically involves connecting the memory devices to the
microcontroller through a data bus and an address bus. The data bus is used to transfer data
between the microcontroller and the memory device, while the address bus is used to select a
specific memory location in the memory device.

i. External ROM (program memory) Interfacing:

The above figure shows how to access or interface ROM to 8051.

 port 0 is used as multiplexed data & address lines.


 it gives lower order (A7-A0) 8 bit address in initial T cycle & higher order (A8-A15)
used as data bus.
 8 bit address is latched using external latch & ALE signal from 8051. port 2 provides
higher order (A15-A8) 8 bit address.
 PSEN is used to activate the output enable signal of external ROM/EPROM.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
ii. External RAM (data memory) Interfacing

above figure shows how to connect or interface external RAM(data memory) to 8051.

 port 0 is used as multiplexed data & address lines.


 address lines are decoded using external latch & ALE signal from 8051 to provide
lower order (A7-A0) address lines.
 port 2 gives higher order address lines. RD & WR signals from 8051 selects the
memory read & memory write operations respectively.

8051 Microcontroller Interrupt

The timer and serial interrupts are internally generated by the microcontroller
whereas, the external interrupts are generated by additional peripheral devices or switches
that are connected to the microcontroller externally. There are two types of external
interrupts: edge-triggered and level-triggered. The interrupt service routine is carried out by
the microcontroller as a reaction to an interrupt, enabling memory locations to coincide with
interrupts.

Interrupt structure of 8051 Microcontroller

All of the interrupts are disabled by “RESET” thus software is required to enable all
of these interrupts. If any one of these five interrupts or all five are activated, the relevant
interrupt flags are set. The priority, which is managed by the IP interrupt priority register,
determines which of these interrupts can be set or cleared bit by bit in a specific function
register that is Interrupt Enabled (IE).

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Two SFRs controls the function of interrupts in 8051 microcontrollers.
IE is Responsible for disable/enable the function and IP is Responsible for priority
assignment: The priority list offers 3 levels of interrupt priority: Reset: When a reset request
arrives, everything is stopped and the microcontroller restarts. Reset can be used to disable
the interrupt priority 1. Interrupt priority 0 can be disabled by both Reset and interrupt.
Some of the registers used in this microcontroller are :
 IE (Interrupt Enable) Register
 IP (Interrupt Priority) Register
 TCON (Timer Control) Register

IE (Interrupt Enable) Register


Interrupts can be enabled and disabled using IE Register. It is a register in the 8051
microcontroller that controls interrupt prioritization and triggering. It includes many bits,
such as:

IP (Interrupt Priority) Register

The interrupt priority register, or IP Register, indicates which of the current interrupt
sources is more significant than other. The program’s start typically defines the interrupt

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
priority. An interrupt will be immediately paused and given preference over any other
interrupt if the one with greater priority comes while the other is still in progress.

Whenever two interrupt requests that have different priorities occurs simultaneously,
the higher priority interrupt is handled first. If two interrupt requests with the same priority
level arise one after the other, the subsequent request needs to wait until the entire process is
accomplished.

TCON (Timer Control) Register

The TCON register determines whether the triggering is edge or level trigger. The
INTx pin for a level trigger interrupt needs to remain low until the interrupt begins and needs
to go back to high prior to the interrupt terminating.
An interrupt won’t be produced if the low at the INTx pin rises to a high value before
the ISR begins. Additionally, the interrupt will be created once more if the INTx pin is low
even after the ISR has ended. The level trigger interrupt (low) at the INTx pin must therefore
be four machine cycles long, neither longer nor shorter than this.

Types of 8051 Microcontroller Interrupts

8051 Microcontroller suffers five different types of interrupts that hampers the main
program execution. These five types of interrupts are:
 Timer 0 overflow interrupt- TF0
 Timer 1 overflow interrupt-TF1
 External hardware interrupt- INT0
 External hardware interrupt- INT1
 Serial communication interrupt- RI/TI
External Hardware Interrupt- (INT0 & INT1)
The 8051 microcontrollers are able to respond to external events through its external
interrupts, INT0 and INT1.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
External Interrupt 0 (INT0)
 It is connected to the 8051’s pin PORT3.2.
 An interrupt request is issued when this pin transitions from low to high in response to
an external signal.
 It is possible to program the microcontroller to carry out a particular Interrupt Service
Routine (ISR) in response to this interrupt.
 Set the IE (Interrupt Enable) bit for INT0 in the TCON register and configure the IT0
(Interrupt Type 0) bit in the TCON register corresponding to the desired triggering
condition (edge or level-triggered) in order to enable and configure INT0.
External Interrupt 1 (INT1)
 It is connected to the 8051’s pin PORT3.3
 When that particular pin encounters a low-to-high transitions, INT1, like INT0,
creates an interrupt request.
 By configuring the IT1 (Interrupt Type 1) bit in the TCON register and setting the IE
bit for INT1 in the TCON register, one can enable and configure INT1.
 A specific ISR can be executed by the microcontroller in response to INT1.

Timer Interrupts (Timer0 and Timer1)


Timer 0 and Timer 1 are hardware timers with internal timer interrupts featured in the
8051 microcontrollers. In microcontroller applications, these timers are used to measure time
intervals and generate precise delays. The interrupt system of the microcontroller enables it to
react quickly to outside events. Interrupts for Timer 0 and Timer 1 are produced when their
respective timers exceed their limit. The microcontroller will run the interrupt service routine
(ISR) for that timer if the related interrupt is enabled, and the associated interrupt flag is set
upon overflow.
Timer0 Interrupt
 Since Timer 0 is an 8-bit timer, its count range is 0 to 255.
 There are two modes of operation for it, 13-bit and 16-bit. It employs the TH0 (Timer
0 High) and TL0 (Timer 0 Low) registers in 13-bit mode and only the TH0 register in
16-bit mode.
 It is possible to set timer 0 to interrupt when it approaches zero instead of staying at
its maximum value. The microcontroller can perform a particular interrupt service
routine (ISR) in response to the interrupt request that this overflow generates.
Timer1 Interrupt
 Timer 1 is a 16-bit timer with a counting range of 0 to 65,535.
 It can operate in 16- or 8-bit mode. It employs the TL1 (Timer 1 Low) and TH1
(Timer 1 High) registers in 8-bit mode and only the TH1 register in 16-bit mode.
 Timer 1 can be set up to produce an interrupt when it overflows, just like Timer 0.
This interruption may cause a certain ISR to be executed.

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Serial Communication Interrupts (UART)
UART (Universal Asynchronous Receiver/Transmitter) is a serial communication
protocol used with 8051 microcontrollers. Data is sent over a single cable, bit by bit, in serial
transmission. In this sense, “interrupts” refers to the processes that enable the microcontroller
to react quickly to external events.
Addressing UART communication with the 8051’s interrupts:
 Initialization of UART- Set the data format, baud rate, and enable the UART module
by configuring the UART registers.
 Interrupt Enable– Depending on the operation you wish to interrupt for, enable the
UART’s transmit interrupt (TI) or receive interrupt (RI).
 ISR (interrupt service routine)- To handle the interrupt, write an ISR. The ISR in
UART communication normally verifies whether the transmit buffer is ready (TI) or
whether data has been received (RI).
 Clearing the Flag- To recognize the interrupt and get ready for the next one, in the
ISR, clear the associated interrupt flag (RI or TI).

Instruction Set and Programming:

Instruction Operation Function Syntax Description


set
MOV destination, MOV copies the value of source
MOV
source into destination
Move Code MOVC MOVC moves a byte from Code
MOVC
Byte to A,@A+register Memory into the Accumulator
Accumulator
Move Data MOVX MOVX moves a byte to or from
To/From operand1,operand2 External Memory into or from the
MOVX External Accumulator.
Memory
Data (XRAM)
Transfer Swap SWAP A SWAP swaps bits 0-3 of the
Instructions SWAP Accumulator Accumulator with bits 4-7 of the
Nibbles Accumulator
Exchange Bytes XCH A,register Exchanges the value of the
XCH Accumulator with the value
contained in register
Push Value PUSH PUSH "pushes" the value of the
PUSH
Onto Stack specified iram addr onto the stack
Pop Value From POP POP "pops" the last value placed
POP Stack on the stack into the iram addr
specified

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
Add ADD and ADDC both add the
Accumulator, value operand to the value of the
ADD,
Add Accumulator, leaving the
ADDC
Accumulator resulting value in the
With Carry Accumulator.
SUBB subtract the value of
Subtract from operand from the value of the
SUBB Accumulator Accumulator, leaving the
With Borrow resulting value in the
Arithmetic Accumulator
Instructions Multiply Multiples the unsigned value of the
MUL Accumulator by MUL AB Accumulator by the unsigned value
B of the "B" register
Divide Divides the unsigned value of the
DIV Accumulator by DIV AB Accumulator by the unsigned
B value of the "B" register
Increment INC increments the value of
INC INC register
Register register by 1
Decrement DEC decrements the value of
DEC DEC register
Register register by 1
ORL does a bitwise "OR"
ORL operation between operand1 and
ORL Bitwise OR
operand1,operand2 operand2, leaving the resulting
value in operand1.
ANL does a bitwise "AND"
ANL operand1, operation between operand1 and
ANL Bitwise AND
operand2 operand2, leaving the resulting
value in operand1
XRL does a bitwise
"EXCLUSIVE OR" operation
Bitwise XRL
XRL between operand1 and operand2,
Exclusive OR operand1,operand2
leaving the resulting value in
operand1

Complement CPL complements operand,


CPL CPL operand
Register leaving the result in operand

CLR clears (sets to 0) all the bit(s)


CLR Clear Register CLR register
Logical of the indicated register
Instructions
Shifts the bits of the Accumulator
Rotate
to the left. The left-most bit (bit 7)
RL Accumulator RL A
of the Accumulator is loaded into
Left
bit 0.

Shifts the bits of the Accumulator


Rotate
to the right. The right-most bit (bit
RR Accumulator RR A
0) of the Accumulator is loaded
Right
into bit 7

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.
JMP jumps unconditionally to the
Jump to Data
address represented by the sum of
JMP Pointer + JMP @A+DPTR
the value of DPTR and the value
Accumulator
of the Accumulator
JC will branch to the address
Jump if Carry
JC JC reladdr indicated by reladdr if the Carry
Set
Bit is set
JNC branches to the address
Jump if Carry
JNC JNC reladdr indicated by reladdr if the carry
Not Set
bit is not set.
Decrement and
DJNZ DJNZ decrements the value of
DJNZ Jump if Not
register,reladdr register by 1.
Zero
CJNE compares the value of
Compare and CJNE operand1 and operand2 and
CJNE Jump If Not operand1,operand2, branches to the indicated relative
Equal reladdr address if operand1 and operand2
Branching are not equal
Instructions Jump if JZ branches to the address
JZ Accumulator JNZ reladdr indicated by reladdr if the
Zero Accumulator contains the value 0.
JNZ will branch to the address
Jump if
indicated by reladdr if the
JNZ Accumulator JNZ reladdr
Accumulator contains any value
Not Zero
except 0
Short Jump,
SJMP reladdr,
SJMP, Long Jump and
LJMP code addr jumps unconditionally to the
LJMP and Absolute Jump
and address specified
AJMP Within 2K
AJMP code address
Block
LCALL calls a program
LCALL Long Call LCALL code addr
subroutine
RET is used to return from a
Return From
RET RET subroutine previously called by
Subroutine
LCALL
JB branches to the address
JB Jump if Bit Set JB bit addr, reladdr indicated by reladdr if the bit
indicated by bit addr is set
JNB will branch to the address
Bit-Wise Jump if Bit Not JNB bit
JNB indicated by reladdress if the
Instructions Set addr,reladdr
indicated bit is not set.
JBC will branch to the address
Jump if Bit Set
JBC JB bit addr, reladdr indicated by reladdr if the bit
and Clear Bit
indicated by bit addr is set

C. Maleappane Lawrence Vanangamoudiar, Assistant Professor in Computer Science Department,


Rajiv Gandhi Arts and Science College, Pondicherry.

You might also like