Unit IV Embedded System and Microcontroller
Unit IV Embedded System and Microcontroller
Embedded systems may also function within a larger system. The systems can be programmable or have a fixed functionality. Industrial
machines, consumer electronics, agricultural and processing industry devices, automobiles, medical equipment, cameras, digital watches,
household appliances, airplanes, vending machines and toys, as well as mobile devices, are possible locations for an embedded system..
Examples of embedded systems
Embedded systems are used in a wide range of technologies across an array of industries. Some examples include:
Automobiles. Modern cars commonly consist of many computers (sometimes as many as 100), or embedded systems, designed to
perform different tasks within the vehicle. Some of these systems perform basic utility functions and others provide entertainment or
user-facing functions. Some embedded systems in consumer vehicles include cruise control, backup sensors, suspension control,
navigation systems and airbag systems.
Mobile phones. These consist of many embedded systems, including GUI software and hardware, operating systems (OSes), cameras,
microphones, and USB (Universal Serial Bus) I/O (input/output) modules.
Industrial machines. They can contain embedded systems, like sensors, and can be embedded systems themselves. Industrial
machines often have embedded automation systems that perform specific monitoring and control functions.
Medical equipment. These may contain embedded systems like sensors and control mechanisms. Medical equipment, such as
industrial machines, also must be very user-friendly so that human health isn't jeopardized by preventable machine mistakes. This
means they'll often include a more complex OS and GUI designed for an appropriate UI.
Embedded systems always function as part of a complete device -- that's what's meant by the term embedded. They are low-
cost, low-power-consuming, small computers that are embedded in other mechanical or electrical systems. Generally, they
comprise a processor, power supply, and memory and communication ports. Embedded systems use the communication ports
to transmit data between the processor and peripheral devices -- often, other embedded systems -- using a communication
protocol. The processor interprets this data with the help of minimal software stored on the memory. The software is usually
Often, embedded systems are used in real-time operating environments and use a real-time operating system (RTOS) to
communicate with the hardware. Near-real-time approaches are suitable at higher levels of chip capability, defined by
designers who have increasingly decided the systems are generally fast enough and the tasks tolerant of slight variations in
reaction. In these instances, stripped-down versions of the Linux operating system are commonly deployed, although other
OSes have been pared down to run on embedded systems, including Embedded Java and Windows IoT (formerly Windows
Embedded).
can be embedded in a larger system to perform a specific function, as they are built for specialized tasks within the system, not
various tasks;
can be either microprocessor-based or microcontroller-based -- both are integrated circuits that give the system compute power;
are often used for sensing and real-time computing in internet of things (IoT) devices, which are devices that are internet-connected
and do not require a user to operate;
can vary in complexity and in function, which affects the type of software, firmware and hardware they use; and
are often required to perform their function under a time constraint to keep the larger system functioning properly.
Hardware. The hardware of embedded systems is based around microprocessors and microcontrollers. Microprocessors are very
similar to microcontrollers and, typically, refer to a CPU (central processing unit) that is integrated with other basic computing
components such as memory chips and digital signal processors (DSPs). Microcontrollers have those components built into one chip.
Software and firmware. Software for embedded systems can vary in complexity. However, industrial-grade microcontrollers and
embedded IoT systems usually run very simple software that requires little memory.
Real-time operating system. These are not always included in embedded systems, especially smaller-scale systems. RTOSes define
how the system works by supervising the software and setting rules during program execution.
In terms of hardware, a basic embedded system would consist of the following elements:
Analog-to-digital (A-D) converters change an analog electrical signal into a digital one.
Digital-to-analog (D-A) converters change the digital data from the processor into analog data.
Actuators compare actual output to memory-stored output and choose the correct one.
The sensor reads external inputs, the converters make that input readable to the processor, and the processor turns that information into
useful output for the embedded system.
A diagram of the basic structure and flow of information in embedded systems.
Mobile embedded systems are small-sized systems that are designed to be portable. Digital cameras are an example of this.
Networked embedded systems are connected to a network to provide output to other systems. Examples include home security
systems and point of sale (POS) systems.
Standalone embedded systems are not reliant on a host system. Like any embedded system, they perform a specialized task.
However, they do not necessarily belong to a host system, unlike other embedded systems. A calculator or MP3 player is an example
of this.
Real-time embedded systems give the required output in a defined time interval. They are often used in medical, industrial and
military sectors because they are responsible for time-critical tasks. A traffic control system is an example of this.
Medium-scale embedded systems use a larger microcontroller (16-32 bit) and often link microcontrollers together.
Sophisticated-scale embedded systems often use several algorithms that result in software and hardware complexities and may
require more complex software, a configurable processor and/or a programmable logic array.
There are several common embedded system software architectures, which become necessary as embedded systems grow and become more
complex in scale. These include:
Simple control loops call subroutines, which manage a specific part of the hardware or embedded programming.
Interrupt controlled systems have two loops: a main one and a secondary one. Interruptions in the loops trigger tasks.
Cooperative multitasking is essentially a simple control loop located in an application programming interface (API).
Preemptive multitasking or multithreading is often used with an RTOS and features synchronization and task switching strategies
A single processor system contains only one processor. So only one process can be executed at a time and then
the process is selected from the ready queue. Most general purpose computers contain the single processor
systems as they are commonly in use.
A single processor system can be further described using the diagram below −
As in the above diagram, there are multiple applications that need to be executed. However, the system
contains a single processor and only one process can be executed at a time.
There are many differences between single processor and multiprocessor systems.Some of these are illustrated
as follows −
Single processor system contains only one processor while multiprocessor systems may contain two or
more processors.
Single processor systems use different controllers for completing special tasks such as DMA (Direct
Memory Access) Controller. On the other hand, multiprocessor systems have many processors that can
perform different tasks. This can be done in symmetric or asymmetric multiprocessing.
Single processor systems can be more expensive than multiprocessor systems. If n processor
multiprocessor system is available, it is cheaper than n different single processor systems because the
memory, peripherals etc. are shared.
It is easier to design a single processor system as compared to a multiprocessor system. This is
because all the processors in the multiprocessor system need to be synchronized and this can be quite
complicated.
Throughput of a multiprocessor system is more than a single processor system. However, if the
throughput of n single processor systems is T then the throughput of n processor multiprocessor system
will be less than T.
Single processor systems are less reliable than multiprocessor systems because if the processor fails
for some reason then system cannot work. In multiprocessor systems, even if one processor fails than
the rest of the processors can pick up the slack. At most the throughput of the system decreases a
little.
Most modern personal computers are single processor systems while multiprocessors are used in niche
systems only.
8051MicrocontrollerPinDiagramandPin Description
By
Dr. Rakesh singh Rajput
8051 microcontroller was designed by Intel in 1981. It is an 8-bit microcontroller. It is built with 40 pins DIP (dual inline
package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit timers. It consists of are four parallel 8-bit ports, which
are programmable as well as addressable as per the requirement. An on-chip crystal oscillator is integrated in the microcontroller
having crystal frequency of 12 MHz.
Architectureof8051Microcontroller
In the following diagram, the system bus connects all the support devices to the CPU. The system bus consists of an 8-bit data
bus, a 16-bit address bus and bus control signals. All other devices like program memory, ports, data memory, serial interface,
interrupt control, timers, and the CPU are all interfaced together through the system bus.
Thepindiagramof8051microcontrollerlooksasfollows–
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.
Pin20−Thispinprovidesthepowersupplytothecircuit.
Pins21to28−ThesepinsareknownasPort2.ItservesasI/Oport.Higher order address bus signals are also multiplexed using
this port.
Pin29−ThisisPSENpinwhichstandsforProgramStoreEnable.Itis used to read a signal from the external program
memory.
Pin30−ThisisEApinwhichstandsforExternalAccessinput.Itisusedto 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.
Pin40−This pin is used to provide power supply to the circuit.
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.
Port0−TheP0(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.
Port1
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.
Port2
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 addressbytewithaddressesA8-
A15.Whennomemoryisaddedthenthisportcan be used as a general input/output port similar to Port 1.
Port3
In this port, functions are similar to other ports except that the logic 1 must be applied to appropriate bit of the P3
register.
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.
Interrupts are the events that temporarily suspend the main program, pass the control to the external sources and
execute their task. It then passes the control to the main program where it had left off.
8051 has 5 interrupt signals, i.e. INT0, TFO, INT1, TF1, RI/TI. Each interrupt can be enabled or disabled by
setting bits of the IE register and the whole interrupt system can be disabled by clearing the EA bit of the same
register.
This register is responsible for enabling and disabling the interrupt. EA register is set to one for enabling interrupts
and set to 0 for disabling the interrupts. Its bit sequence and their meanings are shown in the following figure.
It disables all interrupts. When EA = 0 no interrupt will be
EA IE.7 acknowledged and EA = 1 enables the interrupt individually.
IP (Interrupt Priority)Register
We can change the priority levels of the interrupts by changing the corresponding bit in the Interrupt Priority (IP)
register as shown in the following figure.
A low priority interrupt can only be interrupted by the high priority interrupt, but not interrupted by another
low priority interrupt.
If two interrupts of different priority levels are received simultaneously, the request of higher priority level
is served.
If the requests of the same priority levels are received simultaneously, then the internal polling sequence
determines which request is to be serviced.
Types of Registers
The 8051 microcontroller contains mainly two types of registers:
The general-purpose memory is called as the RAM of the 8051 microcontrollers, which is divided into 3
areas such as banks, bit-addressable area, and scratch-pad area. The banks contain different general-
purpose registers such as R0-R7, and all such registers are byte-addressable registers that store or
remove only 1-byte of data.
SW (Program Status Word) Register
The PSW register is a bit and byte-addressable register. This register reflects the status of the
operation that is carried out in the controller. The PSW register determines bank selection by an RS1
and RS0, as shown below. The physical address of the PSW starts from D0h and the individual bits are
Carry Flag (C): The Address of the Carry flag is D7. This carry flag is affected when the bit is
Auxillary Flag(AC): The address of the auxiliary carry is D5. This auxiliary carry is affected when a bit
Parity Flag (P): The address of the parity flag is D0. While performing arithmetic operations, if the
The RS1 and RS0, the bits in the PSW register, are used to select different memory locations (bank0 to
The following example demonstrates the addition of two numbers and then the storage of final value in
Org 0000h
MOV PSW,#00h
MOV A, 15
ADD A, 20
MOV 00h, A
END
END
END
Special function registers are upper RAM in the 8051 microcontrollers. These registers contain all
peripherally related registers like P0, P1, P2, P3, timers or counters, serial port, and interrupts-related
registers. The SFR memory address starts from 80h to FFh. The SFR register is implemented by bit-
The accumulator, B register, Po, P1, P2, P3, IE registers are bit-addressable register remaining all are
byte-addressable registers.
Accumulator
The accumulator which is also known as ACC or A is a bit as well as a byte-addressable register by an
address of the accumulator. If you want to use a bit-addressable register, you can use a single bit (E0)
of the register and you can use an 8-bit of the accumulator as a byte-addressable register. The
Org 0000h
END
B-Register
The B-register is a bit and byte-addressable register. You can access 1-bit or all 8-bits by a physical
address F0h. Suppose to access a bit 1, we have to use f1. The B register is only used for multiplication
Org 0000h
MOV A, #09h
MOV B, #03h
END
Org 0000h
MOV A, #09h
MOV B, #03h
END
Port Registers
The 8051 microcontroller consists of 4-input and output ports (P0, P1, P2, and P3) or 32-I/O pins. Each
pin is designed with a transistor and P registers. The pin configuration is very important for a
microcontroller that depends on the logic states of the registers. The pin configuration as the input
given by 1 or output 0 depends on the logic states. If logic 1 is applied to the bit of the P register, the
output transistor switches off the appropriate pin that acts as an input pin.
Assembly program to toggle LEDs of Port0
ORG 0000h
ACALL DEL1
ACALL DEL1
SJMP RETURN
RET
END
2.Branch Instructions
There are two kinds of branch instructions:
Unconditional jump instructions: upon their execution a jump to a new location from where the
program continues execution is executed.
Conditional jump instructions: a jump to a new program location is executed only if a specified
condition is met. Otherwise, the program normally proceeds with the next instruction
3. Data Transfer Instructions
Data transfer instructions move the content of one register to another. The register the content of
which is moved remains unchanged. If they have the suffix “X” (MOVX), the data is exchanged with
external memory.
4. Logic Instructions
Logic instructions perform logic operations upon corresponding bits of two registers. After execution,
the result is stored in the first operand.
Bit-oriented Instructions
Similar to logic instructions, bit-oriented instructions perform logic operations. The difference is that
these are performed upon single bits.
5. ARITHMETIC INSTRUCTIONS
ADD A,Rn
Adds the register to the accumulator
ADD A,direct
Adds the direct byte to the accumulator
ADD A,@Ri
Adds the indirect RAM to the accumulator
ADD A,#data
Adds the immediate data to the accumulator
ADDC A,Rn
Adds the register to the accumulator with a carry flag
ADDC A,direct
Adds the direct byte to the accumulator with a carry flag
ADDC A,@Ri
Adds the indirect RAM to the accumulator with a carry flag
ADDC A,#data
Adds the immediate data to the accumulator with a carry flag
SUBB A,Rn
Subtracts the register from the accumulator with a borrow
SUBB A,direct
Subtracts the direct byte from the accumulator with a borrow
SUBB A,@Ri
Subtracts the indirect RAM from the accumulator with a borrow
SUBB A,#data
Subtracts the immediate data from the accumulator with a borrow
INC A
Increments the accumulator by 1
INC Rn
Increments the register by 1
INC Rx
Increments the direct byte by 1
INC @Ri
Increments the indirect RAM by 1
DEC A
Decrements the accumulator by 1
DEC Rn
Decrements the register by 1
DEC Rx
Decrements the direct byte by 1
DEC @Ri
Decrements the indirect RAM by 1
INC DPTR
Increments the Data Pointer by 1
MUL AB
Multiplies A and B
DIV AB
Divides A by B
DA A
Decimal adjustment of the accumulator according to BCD code
BRANCH INSTRUCTIONS
ACALL addr11
Absolute subroutine call
LCALL addr16
Long subroutine call
RET
Returns from subroutine
RETI
Returns from interrupt subroutine
AJMP addr11
Absolute jump
LJMP addr16
Long jump
SJMP rel
Short jump (from –128 to +127 locations relative to the following instruction)
JC rel
Jump if carry flag is set. Short jump.
JNC rel
Jump if carry flag is not set. Short jump.
JB bit,rel
Jump if direct bit is set. Short jump.
JBC bit,rel
Jump if direct bit is set and clears bit. Short jump.
JMP @A+DPTR
Jump indirect relative to the DPTR
JZ rel
Jump if the accumulator is zero. Short jump.
JNZ rel
Jump if the accumulator is not zero. Short jump.
CJNE A,direct,rel
Compares direct byte to the accumulator and jumps if not equal. Short jump.
CJNE A,#data,rel
Compares immediate data to the accumulator and jumps if not equal. Short jump.
CJNE Rn,#data,rel
Compares immediate data to the register and jumps if not equal. Short jump.
CJNE @Ri,#data,rel
Compares immediate data to indirect register and jumps if not equal. Short jump.
DJNZ Rn,rel
Decrements register and jumps if not 0. Short jump.
DJNZ Rx,rel
Decrements direct byte and jump if not 0. Short jump.
NOP
No operation
MOVX A,@Ri
Moves the external RAM (8-bit address) to the accumulator
MOVX A,@DPTR
Moves the external RAM (16-bit address) to the accumulator
MOVX @Ri,A
Moves the accumulator to the external RAM (8-bit address
MOVX @DPTR,A
Moves the accumulator to the external RAM (16-bit address)
PUSH direct
Pushes the direct byte onto the stack
POP direct
Pops the direct byte from the stack
XCH A,Rn
Exchanges the register with the accumulator
XCH A,direct
Exchanges the direct byte with the accumulator
XCH A,@Ri
Exchanges the indirect RAM with the accumulator
XCHD A,@Ri
Exchanges the low-order nibble indirect RAM with the accumulator
RETI
Returns from interrupt subroutine
LOGIC INSTRUCTIONS
ANL A,Rn
AND register to accumulator
ANL A,direct
AND direct byte to accumulator
ANL A,@Ri
AND indirect RAM to accumulator
ANL A,#data
AND immediate data to accumulator
ANL direct,A
AND accumulator to direct byte
ANL direct,#data
AND immediate data to direct register
ORL A,Rn
OR register to accumulator
ORL A,direct
OR direct byte to accumulator
ORL A,@Ri
OR indirect RAM to accumulator
ORL direct,A
OR accumulator to direct byte
ORL direct,#data
OR immediate data to direct byte
XRL A,Rn
Exclusive OR register to accumulator
XRL A,direct
Exclusive OR direct byte to accumulator
XRL A,@Ri
Exclusive OR indirect RAM to accumulator
XRL A,#data
Exclusive OR immediate data to accumulator
XRL direct,A
Exclusive OR accumulator to direct byte
XORL direct,#data
Exclusive OR immediate data to direct byte
CLR A
Clears the accumulator
CPL A
Complements the accumulator (1=0, 0=1)
SWAP A
Swaps nibbles within the accumulator
RL A
Rotates bits in the accumulator left
RLC A
Rotates bits in the accumulator left through carry
RR A
Rotates bits in the accumulator right
RRC A
Rotates bits in the accumulator right through carry
CJNE @Ri,#data,rel
Compares immediate data to indirect register and jumps if not equal. Short jump.
BIT-ORIENTED INSTRUCTIONS
CLR C
Clears the carry flag
CLR bit
Clears the direct bit
SETB C
Sets the carry flag
SETB bit
Sets the direct bit
CPL C
Complements the carry flag
CPL bit
Complements the direct bit
ANL C,bit
AND direct bit to the carry flag
ANL C,/bit
AND complements of direct bit to the carry flag
ORL C,bit
OR direct bit to the carry flag
ORL C,/bit
OR complements of direct bit to the carry flag
MOV C,bit
Moves the direct bit to the carry flag
MOV bit,C
Moves the carry flag to the direct bit
A - accumulator;
Rn - is one of working registers (R0-R7) in the currently active RAM memory bank;
Direct - is any 8-bit address register of RAM. It can be any general-purpose register or a SFR (I/O
port, control register etc.);
addr11 - is an 11-bit address. May be within the same 2KB page of program memory as the first
byte of the following instruction;
rel - is the address of a close memory location (from -128 to +127 relative to the first byte of the
following instruction). On the basis of it, assembler computes the value to add or subtract from the
number currently stored in the program counter;
Immediate addressing mode allows the programmer to directly specify a constant or immediate value as the operand for an
instruction.
The value is encoded within the instruction itself, providing a quick and convenient way to work with constants.
For example, the instruction “MOV A, #25H” copies the immediate value 25H into the accumulator register A.
Register Addressing Mode: In register addressing mode, the operand for an instruction is located in one of the
eight general-purpose registers: R0 to R7. These registers are directly accessible and offer fast data manipulation.
For example, the instruction “MOV A, R2” copies the value stored in register R2 to the accumulator A.
Direct addressing mode allows accessing data from the internal RAM of the 8051 microcontroller.
The operand specifies a memory location directly, allowing efficient access to variables and data arrays.
For example, the instruction “MOV A, 30H” copies the value stored at memory address 30H to the accumulator A.
3. Indirect Addressing Mode:
Indirect addressing mode enables accessing memory locations indirectly through a register pair.
The 8051 microcontroller supports two register pairs for indirect addressing: DPTR (Data Pointer) and the combination of R0
and R1.
This mode is useful for accessing large data arrays or performing table lookups.
For example, the instruction “MOVX A, @R0” copies the value stored at the memory address pointed to by register R0 to
the accumulator A.
4. Indexed Addressing Mode:
Indexed addressing mode, also known as relative addressing mode, allows accessing memory locations by adding an offset to
a base address.
The offset is usually stored in one of the registers, enabling efficient access to data structures with fixed offsets.
For example, the instruction “MOV A, @R0+5” copies the value stored at the memory address pointed to by register R0
plus an offset of 5 to the accumulator A.
5. Bit Addressing Mode: Bit addressing mode is specifically designed to manipulate individual bits within the
Special Function Registers (SFRs) of the 8051 microcontroller.
SFRs are a set of memory-mapped hardware registers used for controlling various on-chip peripherals. This mode allows
reading or modifying specific bits within these registers.
For example, the instruction “SETB P1.2” sets bit 2 of Port 1.
6. Absolute Addressing Mode: Absolute addressing mode is a specialized mode used for accessing specific
memory locations in the external RAM or code memory space.
It requires a 16-bit address to identify the memory location, allowing direct access to external memory and code memory.
Instructions using this mode are typically prefixed with ‘@’ to indicate absolute addressing.
For example, the instruction “MOVX A, @DPTR” copies the value stored at the memory address pointed to by the data
pointer DPTR to the accumulator A.
Addressing modes in the 8051 microcontroller play a vital role in efficient memory management and data manipulation.
By understanding and utilizing the various addressing modes available, programmers can optimize their code and maximize the
capabilities of the microcontroller. Whether it’s immediate addressing, register addressing, direct addressing, indirect