MP&MC
MP&MC
MICROCONTROLLER
THE 8086 MICROPROCESSORS
• A microprocessor is an electronic component that is used by a
computer to do its work. It is a central processing unit
on a single integrated circuit chip containing millions of
very small components including transistors, resistors,
and diodes that work together.
Evolution of Microprocessor
THE 8086 MICROPROCESSOR
FEATURES OF 8086
• The 8086 is a 16 bit processor.
• The 8086 has a 16 bit Data bus.
• The 8086 has a 20 bit Address bus.
• Direct addressing capability 1 M Byte of Memory (220)
• It provides fourteen 16-bit register.
• 24 Operand addressing modes.
• Four general-purpose 16-bit registers: AX, BX, CX, DX
• Available in 40pin Plastic Package and Lead Chip.
8086 MICROPROCESSOR ARCHITECTURE
The 8086 processor are partitioned logically
into two processing units
• Bus Interface Unit (BIU)
The BIU fetches instructions, reads data from
memory and ports, and writes data to memory
and I/O ports.
• Execution Unit (EU)
EU receives program instruction codes and data
from the BIU, executes these instructions and
stores the results either in the general registers or
output them through the BIU. EU has no
connections to the system buses.
The BIU contains
• Segment registers
• Instruction pointer
• Instruction queue
The EU contains
• ALU
• General purpose registers
• Index registers
• Pointers
• Flag register
General Purpose Registers
All general registers of the 8086 microprocessor can
be used for arithmetic and logic operations.
• Accumulator register (AX)
Accumulator can be used for I/O operations and
string manipulation.
• Base register (BX)
BX register usually contains a data pointer used for
based, based indexed or register indirect
addressing.
General Purpose Registers
• Count register (CX)
Count register can be used as a counter in
string manipulation and shift/rotate
instructions.
• Data register (DX)
Data register can be used as a port number in
I/O operations.
Segment Registers:
Most of the registers contain data/instruction offsets
within 64 KB memory segment. There are four
different 64 KB segments for instructions, stack, data
and extra data.
• Code segment (CS)
The CS register is automatically updated during FAR
JUMP, FAR CALL and FAR RET instructions.
• Stack segment (SS)
SS register can be changed directly using POP
instruction.
Segment Registers:
• Data segment (DS)
DS register can be changed directly using POP
and LDS instructions.
• Extra segment (ES)
ES register can be changed directly using POP
and LES instructions.
Pointer
Registers Stack
Pointer (SP)
It is a 16-bit
register
pointing to
program
stack.
Base Pointer
(BP)
It is a 16-bit register pointing to data in the stack
segment. BP register is usually used for based,
based indexed or register indirect addressing.
Index Registers
Source Index (SI)
It is a 16-bit register. SI is used for indexed, based
indexed and register indirect addressing, as well as a
source data address in string manipulation
instructions.
Destination Index (DI)
It is a 16-bit register. DI is used for indexed, based
indexed and register indirect addressing, as well as a
destination data address in string manipulation
instructions.
Instruction Pointer (IP)
It is a 16-bit register. The operation is same as the
program counter. The IP register is updated by
the BIU to point to the address of the next
instruction. Programs do not have direct access
to the IP, but during execution of a program the IP
can be modified or saved and restored from the
stack.
Flag register
It is a 16-bit register containing nine 1-bit flags:
• Six status or condition flags (OF, SF, ZF, AF, PF, CF)
• Three control flags ( TF, DF, IF)
• Overflow Flag (OF) - set if the result is too large positive number,
or is too small negative number to fit into destination operand.
• Sign Flag (SF) - set if the most significant bit of the result is set.
• Zero Flag (ZF) - set if the result is zero.
• Auxiliary carry Flag (AF) - set if there was a carry from or borrow
to bits 0-3 in the AL register.
• Parity Flag (PF) - set if parity (the number of “1” bits) in the low-
order byte of the result is even.
• Carry Flag (CF) - set if there was a carry from or borrow to the
most significant bit during last result calculation.
• Trap or Single-step Flag (TF) - if set then single-step interrupt will
occur after the next instruction.
• Direction Flag (DF) - if set then string manipulation instructions
will auto-decrement index registers. If cleared then the index
registers will be auto-incremented.
• Interrupt-enable Flag (IF) - setting this bit enables maskable
interrupts.
Instruction Queue
The instruction queue is a First-In-First-out (FIFO)
group of registers where 6 bytes of instruction
code is pre-fetched from memory ahead of time.
It is being done to speed-up program execution
by overlapping instruction fetch and execution.
This mechanism is known as PIPELINING.
ALU
It is a 16 bit register. It can add, subtract,
increment, decrement, complement, shift
numbers and performs AND, OR, XOR operations.
Control unit
The control unit in the EU directs the internal
operations like RD , WR , M/IO
Instruction Set
• Data moving instructions.
• Arithmetic instructions - add, subtract, increment,
decrement, convert byte/word and compare.
• Logic instructions - AND, OR, exclusive OR,
shift/rotate and test.
• String manipulation instructions - load, store,
move, compare and scan for byte/ word.
• Control transfer instructions - conditional,
unconditional, call subroutine and return from
subroutine.
• Input/Output instructions.
• Other instructions - setting/clearing flag bits, stack
operations, software interrupts, etc.
Addressing modes
• Implied - the data value/data address is implicitly associated with the
instruction.
• Register - references the data in a register or in a register pair.
• Immediate - the data is provided in the instruction.
• Direct - the instruction operand specifies the memory address where
data is
located.
• Register indirect - instruction specifies a register containing an address,
where data is located. This addressing mode works with SI, DI, BX and BP
registers.
• Based - 8-bit or 16-bit instruction operand is added to the contents of a
base register (BX or BP), the resulting value is a pointer to location where
data resides.
• Indexed - 8-bit or 16-bit instruction operand is added to the contents of an
index register (SI or DI), the resulting value is a pointer to location where
data resides.
• Based Indexed - the contents of a base register (BX or BP) is added to the
contents of an index register (SI or DI), the resulting value is a pointer to
location where data resides.
• Based Indexed with displacement - 8-bit or 16-bit instruction operand is
added to the contents of a base register (BX or BP) and index register (SI or
DI), the resulting value is a pointer to location where data resides.
Interrupts
Hardware interrupts
Maskable and non-
maskable interrupts
Software interrupts
ADDRESSING MODES
• An addressing mode is the way the 8086 identifies the operands for
the instruction. All instructions that access the data use one or
more of the addressing modes.
• The memory address of an operand consists of two components
1. Starting address of the memory segment
2. Offset
• When an operand is stored in a memory location, how for the
operand’s memory location is within a memory segment from the
starting address of the segment, is called Offset or Effective
Address (EA).
• The 8086 uses 20 bit memory address. The segment register gives
16 MSBs of the starting address of the memory segment. The BIU
generates 20 bit starting address of the memory segment by
shifting the content of the segment register left by 4 bits. In other
words it puts 4 zeros in 4 LSB positions.
• Memory Address = Starting address of the memory
segment + Offset
The 8086 has the following addressing modes:
• Register Addressing Mode
• Immediate Addressing Mode
• Direct Addressing Mode
• Register Indirect Addressing Mode
• Base Addressing Mode
• Indexed Addressing Mode
• Based Indexed Addressing Mode
• String Addressing Mode
• I/O Port Addressing Mode
• Relative Addressing Mode
• Implied Addressing Mode
Register Addressing Mode
• Both source and destination operands are
registers. The operand sizes must match. MOV
destination, source
• Examples:
• MOV AL, AH
• MOV AX, BX
Immediate Addressing Mode
• The data operand is supplied as part of the
instruction. The immediate operand can only be a
source.
• Examples:
• MOV CH, 3A H
• MOV DX, 0C1A5 H
Direct Addressing Mode
• One of the operands is a memory location, given by a
constant offset.
• In this mode the 16 bit effective address (EA) is taken
directly from the displacement field of the instruction.
• Examples:
• MOV AX,[1234 H]
• MOV DL, [3BD2 H],
Register Indirect Addressing Mode
• One of the operands is a memory location, with the
offset given by one of the BP, BX, SI, or DI registers.
• Example:
• MOV [BX], CL
• MOV DL, [BX]
Base Addressing Mode
• In this mode EA is obtained by adding a
displacement (signed 8 bit or unsigned 16 bit)
value to the contents of BX or BP. The segment
registers used are DS and SS.
• Example:
• MOV AX, [BP + 200]
Indexed Addressing Mode
• The operand’s offset is the sum of the content of
an index register SI or DI and an 8-bit or 16-bit
displacement.
• Example:
• MOV AH, [DI]
Based Indexed Addressing Mode
• In this mode, the EA is computed by adding a base
register (BX or BP), an index register (SI or DI) and a
displacement (unsigned 16 bit or sign extended 8
bit)
• Example:
• MOV AX, [BX + SI + 1234 H]
• MOV CX, [BP][SI] + 4
String Addressing Mode
• The instruction is a string instruction, which uses
index registers implicitly to access memory.
• Example:
• MOVS B
• MOVS W
I/O Port Addressing Mode
• The destination or source of the data is an I/O port.
Either direct port addressing (including an 8-bit port
address) or indirect addressing (DX must contain the
port address) may be used.
• Examples:
• IN AX, 50H ; Direct
• OUT DX, AL ; Indirect
Relative Addressing Mode
• In this mode, the operand is specified as a signed 8
bit displacement, relative to PC(Program Counter).
• Examples:
• JMP 0200 H
• JNC START
Implied Addressing Mode
• Instructions using this mode have no operands.
• Examples:
• CLC, STC, CMC
SCAS
• SCAS destination-string
• This (Scan String) instruction subtracts the destination string element (addressed by
DI) from the contents of AL or AX and updates the flags.
• Example :
• SCAS Buffer
LODS
• LODS source-string
• This (Load String) instruction transfers the byte/word string element addressed by SI
to register AL or AX and updates SI to point to the next element in the string.
• (DEST) (SRC)
• Example :
• LODSB name
• LODSW name
STOS
• STOS destination - string
• This (Store String) instruction transfers a byte/word from register AL or AX to the
string element addressed by DI and updates DI to point to the next location in the
string.
• (DEST) (SRC)
• Example :
• STOS display
UNIT – 4
MICROCONTROLLERS
BASIC BLOCK DIAGRAM
FEATURES
High integration of
functionality :
• Microcontrollers are called as chip
single
computers because they have on -
memory and I/O circuitry and other circuitries
chip
that enable them to function as small stand -
alone computers without other supporting
circuitry.
• Field flexibility :
programmability,
Microcontrollers often use EPROM
E2PROM as their storage device to or allow field
programmability so they are flexible to use.
• Once the program is tested to be correct then
large quantities of microcontrollers can be
programmed to be used in embedded systems.
• Easy to use.
Advantages of microcontrollers
• The overall system cost is low, as the
peripherals are integrated in a single chip.
• The product is of small size as compared to the
microprocessor based system and is very
handy.
• The system is more reliable.
• The system is easy to troubleshoot and
maintain.
• If required additional RAM, ROM and I/O
ports may be interfaced
ARCHITECTURE OF 8051
The features of the 8051 are :
• 8 bit CPU with registers A (the accumulator) and B
• 16 bit Program Counter (PC) and Data Pointer (DPTR)
• 8 bit Program Status Word (PSW)
• 64K Program memory address space
• 64K Data memory address space
• 128 bytes of on chip data memory
• 32 I/O pins for four 8 bit ports : Port 0, Port 1, Port 2,
Port 3
• Two 16 bit timers / counters : T0 and T1
• Full duplex UART : SBUF
• Two external and three internal interrupt sources
• On chip clock oscillator.
Central processing unit
• The CPU is the brain of the microcontrollers
reading user’s programs and executing the
expected task as per instructions stored there
in. It’s primary elements are an Accumulator
(ACC), B register (B), Stack pointer (SP),
Program counter (PC), Program status word
(PSW), Data pointer register (DPTR) and few
more 8 bit registers.
Accumulator
• The accumulator performs arithmetic and logic
functions on 8 bit input variables.
• Arithmetic operations include basic addition,
subtraction, multiplication and division.
• Logical operations are AND, OR XOR as well
as rotate, clear, complement etc.
• Apart from all the above, accumulator
is responsible for conditional branching
decisions and provides a temporary place
in a data transfer operations within the
device.
B Register
• B register is used in multiply and divide
operations.
• During execution B register either keeps one
of the two inputs and then retains a portion
of the result.
• For other instructions it is used as general
purpose register.
Stack Pointer
• Stack Pointer (SP) is an 8 bit register.
• This pointer keeps track of memory space where
the important register information are stored when
the program flow gets into executing a subroutine.
• The stack portion may be placed in anywhere in
the onchip RAM.
• But normally SP is initialized to 07H after a
device reset and grows up from the location 08H.
• The SP is automatically incremented or
decremented for all PUSH or POP instructions
and for all subroutine calls and returns.
Program Counter
• The Program Counter (PC) is the 16 bit
register giving address of next instruction to be
executed during program execution.
• It always points to the program memory space.
Data Pointer Register
• The Data Pointer Register (DPTR) is the 16 bit
addressing register that can be used to fetch
any 8 bit data from the data memory space.
• When it is not being used for this purpose, it
can be used as two eight bit registers, DPH and
DPL.
Program Status Word
• The Program Status Word keeps
the current status of
(PSW) the arithmetic and
logic
operations in different bits.
• The 8051 has four math flags that respond
automatically to the outcomes of arithmetic and
logic operations and 3 general purpose user flags
that can be set 1 or cleared to 0 by the
programmer as desired.
• The math flags are carry (C), auxiliary carry
(AC), overflow (OV) and parity (P).
• User flags are named flag 0 (F0), Register bank
select bits RS0 and RS1.
Input / Output Ports
• 8051 has 32 I/O pins configured as 4 eight bit
parallel ports (P0, P1, P2 and P3).
• Each pin can be used as an input or as
an output under the software control.
• These I/O pins can be accessed directly by
memory instructions during program execution
to get require flexibility.
Timers / Counters
• 8051 has two 16 bit Timers / Counters, T0 and T1
capable of working in different modes.
• Each consists of a ‘HIGH’ byte and a ‘LOW’ byte
which can be accessed under software.
• There is a mode control register (TMOD)
and a control register (TCON) to configure
these timers
/ counters in number of ways.
• These timers are used to measure time intervals,
determine pulse widths or initiate events with one
microsecond resolution upto a maximum 65ms.
Serial Port
• The 8051 has a high speed full duplex serial
port which is software configurable in 4
basic modes :
• Shift register mode
• Standard UART mode
• Multiprocessor mode
• 9 bit UART mode
Interrupts
• The 8051 has five interrupt sources : One from
the serial port (RI / TI) when a transmission or
reception operation is executed : two from the
timers (TF0, TF1) when overflow occurs and two
come from the two input pins INT0, INT1.
• Each interrupt may be independently enabled or
disabled to allow polling on same sources and
each may be classified as high or low priority.
• These operations are selected by Interrupt Enable
(IE) and Interrupt Priority (IP) registers.
Oscillator and Clock
• The 8051 generates the clock pulses by which
all internal operations are synchronized.
• Pins XTAL 1 and XTAL 2 are provided for
connecting a resonant network to form an
oscillator.
• A quartz crystal is used for oscillator.
• The crystal frequency is the basic internal
clock frequency of the microcontroller.
SPECIAL FUNCTION REGISTERS (SFRS)
• The address of the Special Function Registers
are above 80H, since the addresses 00H to
7FH are the addresses of RAM memory.
• The SFRs have addresses between 80H and
FFH.
• But all the address space of 80H to FFH is not
used by the SFRs.
• The unused locations are reserved and must
not be used by the programmer.
ADDRESSING MODES
• Immediate addressing mode
• Register addressing mode
• Direct addressing mode
• Register indirect addressing mode
• Indexed addressing mode
Immediate Addressing Mode
• When a source operand is a constant rather
than a variable, then the constant can be
embedded into the instruction itself.
• This kind of instructions take two bytes and
first one specifies the opcode and second byte
gives the required constant.
• The operand comes immediately after the
opcode. The mnemonic for immediate data is
the pound sign (#).
• This addressing mode can be used to load
information into any of the registers
including DPTR register.
Register Addressing Mode
• Register addressing accesses the eight working
registers (R0 - R7) of the selected register bank.
• The least significant three bits of the
instruction opcode indicate which register is to
be used for the operation.
• One of the four banks of registers is to be
predefined in the PSW before using register
addressing instruction.
• ACC, B and DPTR can also be addressed in
this mode.
Direct Addressing Mode
• In the direct addressing mode, all 128 bytes of
internal RAM and the SFRs may be addressed
directly using the single - byte address
assigned to each RAM location and each SFR.
• Internal RAM uses address from 00H to 7FH
to address each byte.
Register Indirect Addressing Mode
• In this mode a register is used as a pointer to
the data.
• If the data is inside the CPU, only registers
R0 and R1 are used for this purpose.
• When R0 and R1 hold the addresses of RAM
locations, they must be preceded by the
“@” sign.
Indexed Addressing Mode
• Only the program memory can be accessed by this
mode.
• This mode is intended for reading lookup tables in the
program memory.
• A 16 bit base register (DPTR or PC) points to the base
of the lookup tables and accumulator carries the
constant indicating table entry number.
• The address of the exact location of the table is formed
by adding the accumulator data to the base pointer.
Example
MOVC A, @A + DPTR
• The contents of A are added to the DPTR to form the
16 bit address of the needed data. ‘C’ means code.
I/OPORTS
Port 0 (P0.0 - 0.7)
• Port 0 is used for both address and data bus (AD0
– AD7).
• When the microcontroller chip is connected to an
external memory, Port 0 provides both address
and data.
• ALE pin indicates if Port 0 has address or data.
• When ALE = 0, Port 0 provides data (D0 – D7)
= 1, Port 0 provides address (A0 – A7)
• ALE is used for demultiplexing address and data
with the help of a latch
Port 1 (P1.0 - P1.7)
• Port 1 pins are used as input or output.
• To make port 1 as an input port, write 1 to all
its 8 bits.
• To make port 1 as output port, write 0 to all its
8 bits.
• Thus port 1 pins have no dual functions.
Port 2 (P2.0 - P2.7)
• Port 2 pins are used as input / output pins
similar in operation to port 1.
• The alternate use of port 2 is to supply a high
order address byte (A8 – A15) when
the microcontroller is connected to
external memory
Port 3 (P3.0 - P3.7)
• Port 3 pins are used as input or output
INSTRUCTION SET
• An instruction is a command given to the
computer to perform a specified operation on
given data.
• The instruction set is the collection
instructions that the microcontroller of
designed to execute. is
• The programmer can write the program
in assembly language using these
instructions.
• Data transfer group
• Arithmetic group
• Logical group
• Boolean variable manipulation
• Program branching
Data Transfer Instructions
ARITHMETIC INSTRUCTIONS
COMPARISON OF MICROPROCESSOR,
MICROCONTROLLER, PIC AND ARM
PROCESSORS
Microprocessor
• Microprocessor has only a CPU inside them in one or
few Integrated Circuits. Like microcontrollers it does
not have RAM, ROM and other peripherals. They are
dependent on external circuits of peripherals to work.
But microprocessors are not made for specific task but
they are required where tasks are complex and tricky
like development of software’s, games and other
applications that require high memory and where input
and output are not defined. It may be called heart of a
computer system. Some examples of microprocessor
are Pentium, I3, and I5 etc.
Microcontroller
• A micro-controller can be comparable to a little stand
alone computer; it is an extremely powerful device, which
is able of executing a series of pre-programmed
tasks and interacting with extra hardware devices. Being
packed in a tiny integrated circuit (IC) whose size and
weight is regularly negligible, it is becoming the perfect
controller for as robots or any machines required some type
of intelligent automation.
• A single microcontroller can be enough to manage a
small mobile robot, an automatic washer machine or a
security system. Several microcontrollers contains a
memory to store the program to be executed, and a lot of
input/output lines that can be a used to act jointly with other
devices, like reading the state of a sensor or controlling a
motor.8051 microcontroller is an 8-bit family of
microcontroller is developed by the Intel in the year 1981.
PIC Microcontroller
• Peripheral Interface Controller (PIC) is
microcontroller developed by a Microchip, PIC
microcontroller is fast and simple to implement program
when we contrast other microcontrollers like 8051. The
ease of programming and simple to interfacing with
other peripherals PIC become successful microcontroller.
Microcontroller is an integrated chip which is consists of
RAM, ROM, CPU, TIMER and COUNTERS.
• The PIC is a microcontroller which as well consists
of RAM, ROM, CPU, timer, counter, ADC (analog to digital
converters), DAC (digital to analog converter). PIC
Microcontroller also support the protocols like CAN, SPI,
UART for an interfacing with additional peripherals. PIC
mostly used to modify Harvard architecture and also
supports RISC (Reduced Instruction Set Computer) by the
above requirement RISC and Harvard we can simply that
PIC is faster than the 8051 based controllers which is
prepared up of Von-Newman architecture.
ARM Processor
• An ARM processor is also one of a family of CPUs
based on the RISC (Reduced Instruction Set
Computer) architecture developed by Advanced RISC
Machines (ARM). An ARM makes at 32-bit and 64-bit
RISC multi- core processors. RISC processors are designed
to perform a smaller number of types of computer
instructions so that they can operate at a higher
speed, performing extra millions of instructions per
second (MIPS).
• By stripping out unnecessary instructions and
optimizing pathways, RISC processors give outstanding
performance at a part of the power demand of CISC
(complex instruction set computing) procedure. ARM
processors are widely used in customer electronic
devices such as smart phones, tablets, multimedia
players and other mobile devices, such as wearables.
Because of their reduced to instruction set, they need
fewer transistors, which enable a smaller die size of the
integrated circuitry(IC).