rgasc's Network security, Microprocessor and microcontrollers 1
rgasc's Network security, Microprocessor and microcontrollers 1
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.
Microcontroller Microprocessor
Its designing and hardware cost is low. Its designing and hardware cost is high.
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.
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.
Interrupts provide a method to postpone or delay the current process, performs a sub-routine
task and then restart the standard program again.
https://www.javatpoint.com/embedded-system-8051-microcontroller-architecture
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.
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.
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.
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.
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).
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.
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.
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.
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.
All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their
functions and Internal RAM Address is given in the following table.
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)
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.
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/T Configure for the Counter Configure for the Timer operations
operations
Bit 00 01 10 11
Details
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.
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.
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
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.
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.
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.
MEMORY INTERFACING
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.
above figure shows how to connect or interface external RAM(data memory) to 8051.
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.
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).
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
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.
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.
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.