Unit 1 Fundamentals of Microprocessor Micro Controllers
Unit 1 Fundamentals of Microprocessor Micro Controllers
1.1 Introduction
Microcomputer: The term microcomputer is generally synonymous with
personal computer, or a computer that depends on a microprocessor.
Microcomputers are designed to be used by individuals, whether in
the form of PCs, workstations or notebook computers.
A microcomputer contains a CPU on a microchip (the
microprocessor), a memory system (typically ROM and RAM), a bus
system and I/O ports, typically housed in a motherboard.
Microprocessor: A silicon chip that contains a CPU. In the world of
personal computers, the terms microprocessor and CPU are used
interchangeably.
A microprocessor (sometimes abbreviated µP) is a digital electronic
component with miniaturized transistors on a single semiconductor
integrated circuit (IC).
One or more microprocessors typically serve as a central processing
unit (CPU) in a computer system or handheld device.
Microprocessors made possible the advent of the microcomputer.
At the heart of all personal computers and most working stations
sits a microprocessor.
Microprocessors also control the logic of almost all digital devices,
from clock radios to fuel-injection systems for automobiles.
Three basic characteristics differentiate microprocessors:
Instruction set: The set of instructions that the microprocessor can
execute.
Bandwidth: The number of bits processed in a single instruction.
Clock speed: Given in megahertz (MHz), the clock speed determines
how many instructions per second the processor can execute.
In both cases, the higher the value, the more powerful the CPU. For
example, a 32-bit microprocessor that runs at 50MHz is more
powerful than a 16-bit microprocessor that runs at 25MHz.
1
Dr. N. Karuppiah & Dr. S. Ravivarman
2
Microprocessor and Microcontroller
Accumulator
Accumulator is nothing but a register which can hold 8-bit data.
Accumulator aids in storing two quantities. The data to be processed by
arithmetic and logic unit is stored in accumulator. It also stores the result of the
operation carried out by the Arithmetic and Logic unit. The accumulator is also
called an 8-bit register. The accumulator is connected to Internal Data bus and
ALU (arithmetic and logic unit). The accumulator can be used to send or receive
data from the Internal Data bus.
3
Dr. N. Karuppiah & Dr. S. Ravivarman
4
Microprocessor and Microcontroller
Yes. Stack pointer maintains the address of the last byte that is entered into
stack.
Each time when the data is loaded into stack, Stack pointer gets
decremented. Conversely it is incremented when data is retrieved from stack.
Temporary Register
As the name suggests this register acts as a temporary memory during the
arithmetic and logical operations. Unlike other registers, this temporary
register can only be accessed by the microprocessor and it is completely
inaccessible to programmers. Temporary register is an 8-bit register.
Flags
Flags are nothing but a group of individual Flip-flops. The flags are mainly
associated with arithmetic and logic operations. The flags will show either a
logical (0 or 1) (i.e.) a set or reset depending on the data conditions in
accumulator or various other registers. A flag is actually a latch which can hold
some bits of information. It alerts the processor that some event has taken
place.
D7 D6 D5 D4 D3 D2 D1 D0
S Z AC P CY
Fig. 1.2 Flag Register
Intel processors have a set of 5 flags.
1. Carry flag
2. Parity flag
3. Auxiliary carry flag
4. Zero flag
5. Sign flag
Consider two binary numbers.
For example
1100 0000
1000 0000
When we add the above two numbers, a carry is generated in the most
significant bit. The number in the extreme right is least significant bit, while the
number in extreme left is most significant bit. So, a ninth bit is generated due to
the carry. So how to accommodate 9th bit in an 8-bit register?
For this purpose, the Carry flag is used. The carry flag is set whenever a
carry is generated and reset whenever there is no carry. But there is an
5
Dr. N. Karuppiah & Dr. S. Ravivarman
auxiliary carry flag? What is the difference between the carry flag and auxiliary
carry flag?
Let’s discuss with an example. Consider the two numbers given below
0000 1100
0000 1001
When we add both the numbers a carry is generated in the fourth bit from
the least significant bit. This sets the auxiliary carry flag. When there is no
carry, the auxiliary carry flag is reset. So, whenever there is a carry in the most
significant bit Carry flag is set. While an auxiliary carry flag is set only when a
carry is generated in bits other than the most significant bit.
Parity checks whether it’s even or add parity. This flag returns a 0 if it is
odd parity and returns a 1 if it is an even parity. Sometimes they are also called
as parity bit which is used to check errors while data transmission is carried
out.
Zero flag shows whether the output of the operation is 0 or not. If the value
of Zero flag is 0 then the result of operation is not zero. If it is zero the flag
returns value 1.
Sign flag shows whether the output of operation has positive sign or
negative sign. A value 0 is returned for positive sign and 1 is returned for
negative sign.
6
Microprocessor and Microcontroller
7
Dr. N. Karuppiah & Dr. S. Ravivarman
data. If READY is low, the CPU will wait an integral number of clock
cycle for READY to go high before completing the read or write
cycle. READY must conform to specified setup and hold times.
Interrupt control
As the name suggests this control interrupts a process. Consider that a
microprocessor is executing the main program. Now whenever the interrupt
signal is enabled or requested the microprocessor shifts the control from main
program to process the incoming request and after the completion of request,
the control goes back to the main program. For example, an Input/output
device may send an interrupt signal to notify that the data is ready for input.
The microprocessor temporarily stops the execution of main program and
transfers control to I/O device. After collecting the input data, the control is
transferred back to main program. Interrupt signals present in 8085 are:
INTR
RST 7.5
RST 6.5
RST 5.5
TRAP
INTR is maskable 8080A compatible interrupt. When the interrupt occurs
the processor fetches from the bus one instruction, usually one of these
instructions: One of the 8 RST instructions (RST0 - RST7). The processor saves
current program counter into stack and branches to memory location N * 8
(where N is a 3 - bit number from 0 to 7 supplied with the RST instruction).
8
Microprocessor and Microcontroller
9
Dr. N. Karuppiah & Dr. S. Ravivarman
10
Microprocessor and Microcontroller
11
Dr. N. Karuppiah & Dr. S. Ravivarman
12
Microprocessor and Microcontroller
13
Dr. N. Karuppiah & Dr. S. Ravivarman
14
Microprocessor and Microcontroller
Immediate Addressing
In immediate addressing mode, the data is specified in the instruction itself.
The data will be a part of the program instruction.
EX. MVI B, 3EH - Move the data 3EH given in the instruction to B register;
LXI SP, 2700H.
Direct Addressing
In direct addressing mode, the address of the data is specified in the
instruction. The data will be in memory. In this addressing mode, the program
instructions and data can be stored in different memory.
EX. LDA 1050H - Load the data available in memory location 1050H in to
accumulator; SHLD 3000H
Register Addressing
In register addressing mode, the instruction specifies the name of the
register in which the data is available.
EX. MOV A, B - Move the content of B register to A register; SPHL; ADD C.
Implied Addressing
In implied addressing mode, the instruction itself specifies the data to be
operated. EX. CMA - Complement the content of accumulator; RAL
15
Dr. N. Karuppiah & Dr. S. Ravivarman
Processor Cycle
The function of the microprocessor is divided into fetch and execute cycle of
any instruction of a program. The program is nothing but number of
instructions stored in the memory in sequence. In the normal process of
16
Microprocessor and Microcontroller
The 1st machine cycle of any instruction is always an Opcode fetch cycle in
which the processor decides the nature of instruction. It is of at least 4-states. It
may go up to 6-states.
In the opcode fetch cycle, the processor comes to know the nature of the
instruction to be executed. The processor during (M1 cycle) puts the program
counter contents on the address bus and reads the opcode of the instruction
through read process. The T1, T2, and T3 clock cycles are used for the basic
memory read operation and the T4 clock and beyond are used for its
interpretation of the opcode. Based on these interpretations, the µP comes to
know the type of additional information/data needed for the execution of the
instruction and accordingly proceeds further for 1 or 2-machine cycle of
memory read and writes.
Instruction Fetch (FC)⇒An instruction of 1 or 2 or 3-bytes is extracted
from the memory locations during the fetch and stored in the µP’s instruction
register.
Instruction Execute (EC)⇒The instruction is decoded and translated into
specific activities during the execution phase.
Opcode Fetch
The 1st step in communicating between the microprocessor and memory is
reading from the memory. This reading process is called opcode fetch. The
17
Dr. N. Karuppiah & Dr. S. Ravivarman
process of opcode fetch operation requires minimum 4-clock cycles T1, T2, T3,
and T4and is the 1st machine cycle (M1) of every instruction. In order to
differentiate between the data byte pertaining to an opcode or an address, the
machine cycle takes help of the status signal IO/ M, S1, and S0. The IO/ M= 0
indicates memory operation and S1 = S0 = 1 indicates Opcode fetch operation.
The opcode fetch machine cycle M1 consists of 4-states (T1, T2, T3, and T4).
The 1st 3-states are used for fetching (transferring) the byte from the memory
and the 4th-state is used to decode it.
Example
Fetch a byte 41H stored at memory location 2105H.
For fetching a byte, the microprocessor must find out the memory location
where it is stored. Then provide condition (control) for data flow from memory
to the microprocessor. The process of data flow and timing diagram of fetch
operation are shown in Figs. 5.3 (a), (b), and (c). The µP fetches opcode of the
instruction from the memory as per the sequence below
A low IO/ M’ means microprocessor wants to communicate with
memory.
The µP sends a high on status signal S1 and S0 indicating fetch
operation.
The µP sends 16-bit address. AD bus has address in 1st clock of
the 1st machine cycle, T1.
AD7to AD0 address is latched in the external latch when ALE =
1.
AD bus now can carry data.
In T2, the RD control signal becomes low to enable the memory
for read operation.
The memory places opcode on the AD bus
The data is placed in the data register (DR) and then it is
transferred to IR.
During T3the RDsignal becomes high and memory is disabled.
18
Microprocessor and Microcontroller
19
Dr. N. Karuppiah & Dr. S. Ravivarman
The high order address (A15 ⇔A8) and low order address (AD7 ⇔AD0)
are asserted on 1st low going transition of the clock pulse. The timing diagram
for IO/M read are shown in Fig. The A15 ⇔A8 remains valid in T1, T2, and T3
i.e. duration of the bus cycle, but AD7⇔AD0 remains valid only in T1. Since it
has to remain valid for the whole bus cycle, it must be saved for its use in the T2
and T3. ALE is asserted at the beginning of T1 of each bus cycle and is negated
towards the end of T1. ALE is active during T1 only and is used as the clock
pulse to latch the address (AD7⇔AD0) during T1. The RD’ is asserted near the
beginning of T2. It ends at the end of T3. As soon as the RD’ becomes active, it
forces the memory or I/O port to assert data. RD’ becomes inactive towards the
end of T3, causing the port or memory to terminate the data.
20
Microprocessor and Microcontroller
21
Dr. N. Karuppiah & Dr. S. Ravivarman
Examples
Opcode fetch MOV B, C.
T1: The 1st clock of 1st machine cycle (M1) makes ALE high indicating
address latch enabled which loads low-order address 00H on AD7⇔AD0 and
high-order address 10H simultaneously on A15 ⇔A8. The address 00H is
latched in T1.
T2: During T2 clock, the microprocessor issues RD control signal to enable
the memory and memory places 41H from 1000H location on the data bus.
T3: During T3, the 41H is placed in the instruction register and RD= 1 (high)
disables signal. It means the memory is disabled in T3 clock cycle. The opcode
cycle is completed by end of T3 clock cycle.
T4: The opcode is decoded in T4 clock and the action as per 41H is taken
accordingly. In other word, the content of C-register is copied in B-register.
22
Microprocessor and Microcontroller
Assume the memory address for the instruction and let the content
of accumulator is C7H. So, C7H from accumulator is now stored in
526A.
23
Dr. N. Karuppiah & Dr. S. Ravivarman
24
Microprocessor and Microcontroller
What is an Assembler?
An assembler is a software tool - a program -- designed to simplify the task
of writing computer programs. If you have ever written a computer program
directly in a machine-recognizable form such as binary or hexadecimal code,
you will appreciate the advantages of programming in a symbolic assembly
language.
Assembly language operation codes (opcodes) are easily remembered
(MOV for move instructions, JMP for jump). You can also symbolically express
addresses and values referenced in the operand field of instructions. Since you
assign these names, you can make them as meaningful as the mnemonics for
the instructions. For example, if your program manipulates a date as data, you
can assign it the symbolic name DATE. If your program contains a set of
instructions used as a timing loop (a set of instructions executed repeatedly
until a specific amount of time has passed), you can name the instruction group
TIMER.
25
Dr. N. Karuppiah & Dr. S. Ravivarman
Example Programs
1. Statement: Store the data byte 32H into memory location 4000H.
Program 1
MVI A, 32H : Store 32H in the accumulator
STA 4000H : Copy accumulator contents at address 4000H
HLT : Terminate program execution
Program 2
LXI H : Load HL with 4000H
MVI M : Store 32H in memory location pointed by HL register
pair (4000H)
HLT : Terminate program execution
26
Microprocessor and Microcontroller
Sample problem
(4000H) = 14H
(4001H) = 89H
Result = 14H + 89H = 9DH
Source program
LXI H 4000H : HL points 4000H
MOV A, M : Get first operand
INX H : HL points 4001H
ADD M : Add second operand
INX H : HL points 4002H
MOV M, A : Store result at 4002H
HLT : Terminate program execution
Sample problem
(4000H) = 51H
(4001H) = 19H
Result = 51H - 19H = 38H
Source program
LXI H, 4000H : HL points 4000H
27
Dr. N. Karuppiah & Dr. S. Ravivarman
28
Microprocessor and Microcontroller
Decoder
It is used to select the memory chip of processor during the execution of a
program. No of IC's used for decoder is,
2-4 decoder (74LS139)
3-8 decoder (74LS138)
29
Dr. N. Karuppiah & Dr. S. Ravivarman
Memory Interfacing
The following are the steps involved in interfacing memory with 8085
processor.
1. First decide the size of memory requires to be interfaced. Depending
on this we can say how many address lines are required for it. For
example, if you want to interface 4KB (212) memory it requires 12
address lines. Remaining address lines can be used in address
decoding.
2. Depending on the size of memory required and given address range,
construct address decoding circuitry. This address decoding circuitry
30
Microprocessor and Microcontroller
Address Decoding
The result of ‘address decoding’ is the identification of a register for
a given address.
A large part of the address bus is usually connected directly to the
address inputs of the memory chip.
This portion is decoded internally within the chip.
What concerns us is the other part that must be decoded externally
to select the chip.
This can be done either using logic gates or a decoder.
Example
Interface 4KB memory to 8085 with starting address A000H.
1. 4KB memory requires 12 address lines for addressing as already
mentioned. But 8085 has 16 address lines. Hence four of address
lines are used for address decoding
2. Given that starting address for memory is A000H. So, for 4KB
memory ending address becomes A000H+0FFFH (4KB) = AFFFH.
A0-A11 address lines are directly connected to address bus of memory chip.
A12-A15 are used for generating chip select signal for memory chip.
31
Dr. N. Karuppiah & Dr. S. Ravivarman
A15 line is use for enabling 74x138 decoder chip. A12, A13, A14 lines are
connected to 74X138 chip as inputs. When these lines are 010 output should be
‘0’. This is provided at O2 pin of 74X138 chip.
A15, A14, A13, A12 inputs should be 1010, for enabling the chip. So, the
circuit for this is as shown above.
32
Microprocessor and Microcontroller
Absolute decoding
All the higher order lines of microprocessor, left after using the required
signals for memory are completely used for generating chip select signal as
shown in above example. This type of decoding is called absolute decoding.
Partial decoding
Only some of the address lines of microprocessor left after using the
required signals for memory are used for generating chip select signal. Because
of this multiple address ranges will be formed. If total memory space is not
required for the system then, this type of address decoding can be used. The
advantage of this technique is fewer components are required for memory
interfacing because of this board size reduces and in turn cost reduces.
Example
Connect 512 bytes of memory to 8085
1. For interfacing 512 bytes 9 address lines are required. So A0-A8 can
be used to directly connect to address bus of memory.
2. In the remaining A9-A15 for example only A15-A12 are used for
generating chip select signal. A11-A9 are don’t care signals.
33
Dr. N. Karuppiah & Dr. S. Ravivarman
Example
Consider a system in which 32kb memory space is implemented using four
numbers of 8kb memory. Interface the EPROM and RAM with 8085 processor.
The total memory capacity is 32Kb. So, let two number of 8kb n memory be
EPROM and the remaining two numbers be RAM. Each 8kb memory requires 13
address lines and so the address lines A0- A12 of the processor are connected
to 13 address pins of all the memory. The address lines and A13 - A14 can be
decoded using a 2-to-4 decoder to generate four chips select signals. These four
chips select signals can be used to select one of the four memory IC at any one
time. The address line A15 is used as enable for decoder. The simplified
schematic memory organization is shown.
34
Microprocessor and Microcontroller
35
Dr. N. Karuppiah & Dr. S. Ravivarman
IO mapped I/O
In this method separate address space is given to IO devices. Each IO device
is given an 8-bit address. Hence maximum 256 devices can be interfaced to the
processor. The address range for the IO devices is 00H-FFH. IO control signals
are used to perform read, write operations. For reading data from IO device or
writing data to IO device IN, OUT instructions needs to be used. Arithmetic and
logical operations can’t be performed directly on IO devices as in memory
mapped IO. IO devices can be interfaced, by using buffers for simple IO i.e. by
using address decoding circuit to enable buffer. For handshake IO or to
interface more peripherals ICs like 8255 peripheral programmable interface
(PPI) can be used.
36
Microprocessor and Microcontroller
37