Professional Documents
Culture Documents
UNIT 9 MICROPROCESSORS
Structure
9.1 Introduction
Objectives
9.2 Introduction to 8085
9.2.1 Block Diagram of Computer
9.2.2 Microprocessors Architecture
9.2.3 Assembly Language Programming
9.3 I/O and Interfacing LSI Counters
9.3.1 Programmable Interval Timers
9.3.2 Programmable Peripheral Interface
9.4 D/A and A/D Converters
9.4.1 DAC
9.4.2 ADC
9.5 Serial Interfacing and Communication
9.6 Introduction to 2051 Microcontroller
9.6.1 Microcontroller Architectures
9.6.2 Instruction Sets
9.7 Recent Trends in Microprocessors
9.7.1 8086
9.7.2 80286
9.7.3 80386
9.7.4 Digital Signal Processors
9.8 Summary
9.9 Answers to SAQs
9.1 INTRODUCTION
Microcomputers are small computers and it can perform all the basic functions of a
digital computer. Microprocessor is the central processing unit (CPU) of microcomputers
and it is usually fabricated on a single integrated circuit. Microcontrollers are single chip
processor, which contains all the basic components of a digital computer like CPU, Read
and Write Memory (RAM), Read Only Memory (ROM), etc. Highly complex circuits are
densely packed on a single chip using Very Large Scale Integration (VLSI) and Ultra
Large Scale Integration (ULSI) technologies.
Microprocessors are now one of the major advances in the computer industry and others
such as communication, control and automobile industries. Our intention here is to
introduce to the fascinating world of microprocessor: its integrated circuit components,
how they can be programmed for a particular application, etc. To do this, we will study
the 8085 microprocessor family in detail and will also introduce you to other advanced
microprocessor families like 80286, 80386, etc.
Objectives
After reading this unit, you should be able to
• list the basic components of a computer, explain 8085 microprocessor
architecture and be able to write assembly language programs,
• explain 8253/8254 Programmable Interval Timer, 8255 Programmable
Peripheral Interface (PPI) and their operating modes,
• explain the purpose of DAC/ADC and describe some commonly used
circuits for ADC/DAC, 111
Electronics • understand the standards for serial data communication between the Data
Communication Equipment (DCE) and Data Terminal Equipment (DTE),
• describe the 3051 single-chip microcontroller architecture and instruction
sets, and
• explain the basic features and improvements made in recent microprocessors
like 8086, 80286, TMS-320C24, etc.
Memory
The memory section usually consists of a mixture of RAM (Random Access
Memory) and ROM (Read Only Memory). It may also have magnetic floppy disks,
magnetic hard disks, or optical disks (CDs, DVDs). Memory has two purposes.
The first purpose is to store the binary codes for the sequences of instructions you
want the computer to carry out. When you write a computer program, what you are
really doing is writing a sequential list of instructions for the computer. The second
purpose of the memory is to store the binary-coded data with which the computer
is going to be working. For example, this data might be the inventory records of a
supermarket.
Input/Output
The input/output or I/O section allows the computer to take in data from the
outside world or send data to the outside world. Peripherals such as keyboards,
video display terminals, printers, and modems are connected to the I/O section.
112 These allow the user and the computer to communicate with each other. The actual
physical devices used to interface the computer buses to external systems are often Microprocessors
called ports. An input port allows data from a keyboard, an A/D converter, or some
other source to be read into the computer under control of the CPU. An output port
is used to send data from the computer to some peripheral, such as a video display
terminal, a printer, or a D/A converter. Physically, the simplest type of input or
output port is just a set of parallel D flip-flops. If they are being used as an input
port, the D inputs are connected to the external device, and the Q outputs are
connected to the data bus, which runs to the CPU. Data will then be transferred
through the latches when they are enabled by a control signal from the CPU. In a
system where they are being used as an output port, the D inputs of the latches are
connected to the data bus, and the Q outputs are connected to some external
device. Data sent out on the data bus by the CPU will be transferred to the external
device when the latches are enabled by a control signal from the CPU.
Data Bus
The data bus consists of 8, 16, or 32 parallel signal lines. As indicated by the
double-ended arrows on the data bus line in Figure 9.1, the data bus lines are
bidirectional. This means that the CPU can read data in from memory or from a
port on these lines, or it can send data out to memory or to a port on these lines.
Many devices in a system will have their outputs connected to the data bus, but
only one device at a time will have its outputs enabled. Any device connected on
the data bus must have three-state outputs so that its outputs can be disabled when
it is not being used to put data on the bus.
Address Bus
The address bus consists of 16, 20, 24, or 32 parallel signal lines. On these lines
the CPU sends out the address of the memory location that is to be written to or
read from. The number of address lines determines the number of memory
locations that the CPU can address. If the CPU has N address lines, then it can
N
directly address 2 memory locations. For example, a CPU with 16 address lines
16
can address 2 or 65,536 memory locations, a CPU with 20 address lines can
20 24
address 2 or 1,048,576 locations, and a CPU with 24 address lines can address 2
or 16,777,216 locations. When the CPU reads data from or writes data to a port, it
sends the port address out on the address bus.
Control Bus
The control bus consists of 4 to 10 parallel signal lines. The CPU sends out signals
on the control bus to enable the outputs of addressed memory devices or port
devices. Typical control bus signals are Memory Read, Memory Write, I/O Read,
and l/O Write. To read a byte of data from a memory location, for example, the
CPU sends out the memory address of the desired byte on the address bus and then
sends out a Memory Read signal on the control bus. The Memory Read signal
enables the addressed memory device to output a data word onto the data bus. The
data word from memory travels along the data bus to the CPU.
Central Processing Unit
The central processing unit or CPU controls the operation of the computer. In a
computer the CPU is a microprocessor. The CPU fetches binary-coded instructions
from memory, decodes the instructions into a series of simple actions, and carries
out these actions in a sequence of steps. The CPU also contains an address counter
or instruction pointer register, which holds the address of the next instruction or
data item to be fetched from memory; general-purpose registers, which are used
for temporary storage of binary data; and circuitry, which generates the control bus
signals.
113
Electronics 9.2.2 Microprocessor Architecture
Architecture is the logic design for data manipulation and communication of the
microprocessor. There are basically three broad categories of functions a microprocessor
can perform, viz.,
(a) operations initiated by the microprocessor,
(b) operations initiated externally, and
(c) internal data operation. All the basic operations of a microprocessor are
performed by a group of logic circuits along with necessary control signals
called as Micro Processing Unit (MPU)/ Central Processing Unit (CPU). We
will study them one by one.
Operations Initiated by the Microprocessor
It basically involves communication between the MPU and peripheral devices of a
microprocessor and the process is initiated from the MPU. Usually MPU follows
the following three common sense step procedure while communicating with a
peripheral device: first, identify the peripheral device; second, transfer the data and
third, provide timing. This can be achieved with the help of three buses, viz.,
address bus, data bus and control bus.
MPU uses the address bus to identify a peripheral device or a memory location.
Address bus is unidirectional and has only one way of communication. They are a
group of sixteen lines for an 8-bit microprocessor like 8085 and it can carry
address of 216 memory locations. In a microcomputer, a binary number identifies
each peripheral or a memory location. Address bus carries that binary address of a
memory or peripheral device.
The data bus is a group of eight lines for an 8-bit microprocessor and it allows data
flow in both direction (bi-directional), i.e. from MPU to peripheral and
vice-versa. A group of eight lines can carry data from 00 (0000 0000) to
FF (1111 1111).
Control bus consists of single lines carrying timing signals. MPU uses control bus
to send control signals to the peripheral device.
Operations Initiated Externally
An external device can initiate the following operations :
Reset
When reset is activated from an external device, it suspends all internal
operations and clears the program counter so that the next program
execution can start at the zero memory address.
Interrupt
When interrupt is activated from an external device, it interrupts the normal
operation of a microprocessor and ask to execute some emergency functions,
after finishing those routines only then the microprocessor can run normal
operation.
Ready
When ready is activated low from an external device, it forces the
microprocessor into wait state, which enables other slow peripherals to
synchronize with the microprocessor.
Hold
When hold is activated from an external device, the microprocessor frees the
buses and let it be used by the external device.
114
Internal Data Operations Microprocessors
118
XORing is similar to ORing with one exception. An OR can also be Microprocessors
called an inclusive OR. This means that a 1 in either number or both
will result in a 1. An eXclusive OR says that if either number has a 1
in it, but not both, a 1 will result. A seemingly small difference, but
crucial. Using the same two numbers, the result would be 1100b. The
first two bits have a 1 in either the first or the second number but not
both. The third bit has a 1 in both numbers, which results in a 0. The
fourth has no 1's at all, so the result is 0. The difference may seem
small, even though the OR and XOR result in different answers. The
main use of an XOR is to test two numbers against each other. If they
are the same, the result will be all 0’s, otherwise the answer will have
1’s where there are differences.
Complement
Complementing a number results in the opposite state of all the 1’s
and 0’s. Take the number 1111b. Complementing results in 0000b.
This is the simplest operator of all and the easiest to understand. Its
uses are varied, but necessary, as you will see later.
Rotate
These instructions rotate bits in a byte. The rotation can be left or
right, and is done one bit each instruction. An example might be
where the accumulator has a 11000011b in it. If we rotate left, the
result will be 10000111b. You can see that bit 7 has now been moved
into bit 0 and all the other bits have move 1 bit position in, the left
direction.
Clear
This instruction clears, or zero’s out the accumulator. This is the same
as moving a 0 into the accumulator. This also clears the C flag and
sets the Z flag.
BRANCHING
There are also program flow commands. These are branches or jumps. They
have several different names reflecting the way they do the jump or on what
condition causes the jump, like an overflow or under flow, or the results
being zero or not zero. But all stop the normal sequential execution of the
program, and jump to another location, other than the next instruction in
sequence.
Jump on Condition (of a Bit)
These instructions let you make a jump based on whether a certain bit
is set (a 1) or cleared (a 0). This bit can be the CY (carry) flag, the
Z (zero) flag, or any other bit.
Call
There is also a variation on a jump that is referred to as a CALL. A
CALL does a jump, but then eventually comes back to the place
where the CALL instruction was executed and continues with the next
instruction after the CALL. This allows the programmer to create
little sub-programs, or subroutines, that do repetitive tasks needed by
the main program. This saves programming time because once the
subroutine is written, it can be used by the main program whenever it
needs it, a kind of way to create your own instructions.
DATA TRANSFER
Moving
These instructions do exactly what you would think. They move data
around between the various registers and memory.
Exchanging
119
Electronics Exchanging is a variation on the move instruction. Here data is
exchanged between two places.
Memory and Addressing
There are several different types of memory in a microprocessor. One is Program
memory. This is where the program is located. Another is Data memory. This is
where data that might be used by the program is located. The strange thing is that
they both reside in the same memory space and can be altered by the program.
That’s right, a program can actually alter itself if that was necessary. Two terms
are used when talking about memory. Reading (load) is getting a value from
memory and Writing (store) is putting a value into memory.
There are three buses associated with the memory subsystem. One is the address
bus, the second is the data bus, and the third is the control bus. It’s important for
you to know exactly how all this works, because these buses transport data and
addresses everywhere. All three are connected to the memory subsystem. It is also
good to know the function of each to better understand what’s happening. In the
8085 CPU, the address bus is 16 bits wide. It acts to select one of the unique
216 (64K) memory locations. The control bus determines whether this will be a
read or a write. In the case of an instruction fetch, the control bus is set up for a
read operation. Data is read or written through the data bus, which is 8 bits wide.
This is why all registers and memory are 8 bits wide, its the width of the data bus
on the 8085 CPU. A bus is just a group of connections that all share a common
function. Instead of speaking of each bit or connection in the address separately,
for example, all 16 are taken together and referred to simply as the address bus.
The same is true for the control and data buses.
A byte is the most used number in a microprocessor because each memory location
or register is one byte wide. Memory has to be thought of as a sort of file cabinet
with each location in it being a folder in the cabinet. In a file cabinet, you go
through the tabs on the folders until you find the right one. To get to each memory
location, a different method is used. Instead, a unique address is assigned to each
location. In most microprocessors this address is a word or 16 bits, or
4 digit hex. This allows for a maximum of 65536 (216 or 64K) unique addresses or
memory locations that can be accessed. These addresses are usually referred to by
a 4 digit hex number. Memory usually starts at address 0000h and could go up to
FFFFh (216 or 64K or 65536 in total). To access these locations, a 16 bit address is
presented to memory and the byte at that location is either read or written.
The Program Counter is what holds this address when the microprocessor is
executing instructions. The reason instructions are read sequentially is because the
program counter automatically increments after fetching the current instruction. It
does this even before the current instruction is acted upon. The sequence is that the
program counter’s contents are placed on the memory address bus and the
instruction is fetched from memory through the data bus, and immediately the
program counter is incremented by 1. Then the microprocessor looks at the
instruction and starts processing it. If the instruction is not some kind of jump or
call, the instruction is completed and the program counter is presented to the
memory address bus again and the next instruction is fetched, the program counter
is incremented and the process starts over. This is referred to, in computer jargon,
as fetch, decode, and execute. In the case of reading or writing data, the process is
a little different. Data can be read from or written to memory in similar fashion to
the fetch. But data does not need the decode and execute steps.
What is Assembly Language?
Inside the 8085, instructions are really stored as binary numbers, not a very good
way to look at them and extremely difficult to decipher. An assembler is a program
that allows you to write instructions in, more or less, English form, much more
easily read and understood, and then converted or assembled into hex numbers and
finally into binary numbers.
120
The program is written with a text editor (NOTEPAD or similar), saved as an Microprocessors
ASM file, and then assembled by the assembler (TASM or MASM or similar)
program. The final result is an OBJ file you download to the 8085. Here is an
example of the problem of adding 2 plus 2 :
mvi A,2; move 2 into the A register
mvi B,2; move 2 into the B register
add B; add reg. B to reg. A, store result in reg. A
The first line moves a 2 into register A. The second moves a 2 into register B. This
is all the data we need for the program. The third line adds the accumulator with
register B and stores the result back into the accumulator, destroying the 2 that
were originally in it. The accumulator has a 4 in it now and B still has a 2 in it. In
the program above all text after the ‘;’ are treated as comments, and not executed.
This is a very important habit to acquire.
Assembly language follows some rules that we will describe as they come up.
With most instructions, especially those involving data transfer, the instruction is
first, followed by at least 1 space, then the destination followed by a comma, and
then the source. The destination is where the result of the instruction will end up
and the source is where the data is coming from.
Next we will read a switch, and light an LED if the switch is pressed. This happens
quite often in your lab experiments. Bit 0 of Port 0 will be the switch. When the
switch is closed or pressed, bit 0 will be a 1, and if the switch is open or not
pressed, bit 0 will be a 0.
Bit 0 of Port l is the LED. If bit 0 is a 0 the LED is off and if bit 0 is a 1, the LED
will be on. All the other bits of reg. A will be ignored and assumed to be all 0’s,
for the sake of discussion
Start
IN 0 ; read Port 0 into reg. A
CMP 1 ;compare reg. A with the value 1
JNZ start ; jump to start if the comparison does not yield 0
OUT 1 ; send a 1 to Port 1, turning the LED on
JMP start
The first line has something new. It’s called a label. In this case it is start :. A label
is a way of telling the assembler that this line has a name that can be referred to
later to get back to it. All labels are followed by the symbol :, which tells the
assembler that this is a label. In the first line we also read the switch by reading
Port and putting it into the accumulator. Reg. A is the only register that can read
in/send out data via ports or perform compares. Thus, we need not write ‘A’ in the
command it’s implied.
The next line compares the value in reg. A with the value 1. If they are equal, the
Zero flag is set (to 1). The next line then jumps to start : only if the Zero flag is not
set, i.e. : the value in reg. A is not 1 therefore the switch was not pressed. The
program will therefore keep looping until the switch is pressed.
If the switch is pressed then the penultimate line writes the value 1 to the
accumulator, therefore bit 0 = 1, and the LED comes on.
The last line jumps back to start. This completes the loop of reading the switch and
writing to the LED.
This particular problem could have been solved with just a switch connected to an
LED, like a light is connected to a wall switch in your house. But with a
microprocessor in the loop, much more could be done. We could have a clock that
also turns on and off the LED based on time. Or we could monitor the temperature 121
Electronics and turn the LED on and off based on what temperature it is. Or we could monitor
several switches and turn the LED on and off based on a combination of switches,
etc. It is up to the imagination what can be controlled.
In the above example we assumed that the other bits of ports 0 and 1 were all
zeros. But in reality, each of these bits could have a function assigned to them.
Then we would need to look only at bit 0 in port 0 and bit 0 in port 1. This further
complicates the problem. Also, we assume that port 0 was previously defined as an
input port whereas port 1 was defined as an output port.
In assembly we can assign a name to a port and refer to it by that name, instead of
port 0 or port 1. This is done with an equate directive. Directives are assembler
commands that don’t result in program but instead direct the assembler to some
action. All directives start with a period.
.equ switch, 0 ;port 0 is now called switch
.equ LED,1 ;port 1 is now called LED
start : IN switch ; read Port 0 into reg. A
CMP 1 ; compare reg. A with the value 1
JNZ start ; jump to start if the comparison does not yield 0
OUT LED ; send a 1 to Port 1, turning the LED on
JMP start
This has the same result as the previous program. Also the equate only has to be
made once at the start of the program, and thereafter the name or label is used
instead of the port number. This makes things much simpler for the programmer.
All equates must be defined before they are used in a program. This holds true for
labels also. Another advantage of naming ports with an equate is that if, later in the
design process, you decide to use a different port for the LED or the switch, only
the equate has to be changed, not the program itself.
Please note that comments are very important. When you initially write a program,
the tendancy is not to write much in the comment field because you’'re in a hurry.
But if you have to come back to it a few weeks later, it is much easier to
understand what you’ve written if you’ve taken the time to write good comments.
Also good comments help in debugging.
To digress just a little here, an instruction like add B is a one-byte instruction. In
other words this instruction would end up inside the 8085 as one byte. Part of the
byte is the opcode and the other part is which register is affected or used. The
reason for this is that a prime concern in programming a microprocessor is how
many bytes the program will actually take up inside the microprcessor, after it has
been assembled. The idea is to cram as much as possible into as few bytes as
possible. This is why implied addressing is used. It limits choices in the use of the
instruction, you always have to use the accumulator as either the source or the
destination, but it shrinks the size of the instruction, so that more instructions can
fit inside the microprocessor. This is a choice made by the maker of the
microprocessor, and is not up for discussion. It is a trade off of flexibility vs. size.
That is why you will see lots of instructions that use the accumulator. This is the
best way to describe implied addressing.
In the case of an instruction like mvi A, 1, two bytes are assembled. The first byte
says that this is a move instruction and that the accumulator is the destination. The
second byte is the immediate data itself. Thus we see that an instruction can have
its data ‘next’ to it. It is transparent to the programmer where the bytes are actually
stored in memory. Once we can ‘find’ it by an instruction is all that matters. We
will get into this again, later.
Another form of addressing variables is called register indirect or just plain
indirect addressing. This is a little more complicated. Here the address is held in a
122 register, usually the H and L registers but sometimes the B and C or D and E.
Since an address is 16 bits long, we need two registers (a register pair) to store an Microprocessors
address. Register indirect instructions reference memory via a register pair. Thus,
the instruction MOV M, C moves the contents of the C register into the memory
address stored in the H and L register pair. The instruction LDAX B loads the
accumulator with the byte of data specified by the address in the B and C register
pair.
Lastly, let us explain something else about the assembler. The source file is what
the above program, or any program that has been written, is referred to. It is the
source for the assembler, or the file that is going to be read by the assembler to
generate the object file (the object of the assembler) from. The object file is the file
that will be download to the 8085 kit in the laboratory. They are two different files.
One you have written with a text editor (the source or ASM file) and the other is
created by the assembler (the object or OBJ file) when you assemble the source
file. You use an assembler with the object in mind of generating a file to download
to the microprocessor, hence the name, object file.
We have left out some directives, for simplicities sake, that we need to mention
now. One is the .org directive. It is the originate or origin directive. This tells the
assembler at what address the first byte of assembled code is to be placed inside
the 8085. It is the origin of the program or the beginning. Here is how this would
look for our last example program:
.org 2000H ; begin using memory address 2000H
Using an Assembler
If you are using a DOS based assembler, you will need to get to DOS. The first
step in writing a program is to define the problem as completely as possible. You
will always think of things as you go along that you left out. After thinking out the
problem, you start by typing up a source file. Source files all end with the .asm
extension. The extensions created by the assembler are .obj, which is the object
file, and .lst, which is the listing file. The listing file shows all the addresses
resolved by the assembler, all the code generated and all the comments. This file is
very important in for assisting you in the laboratory. The listing file also shows
any errors in the assembly process so that you can correct them. It is crucial that
you look at the listing file to be sure that there are no errors listed. The way you
would use a program in real life is to write each program, assemble it, and then
execute it.
The Stack
The stack is one of the most important things you must know when programming.
Think of the stack as a deck of cards. When you put a card on the deck, it will be
the top card. Then you put another card, then another. When you remove the cards,
you remove them backwards, the last card first and so on. The stack works the
same way; you put (push) words (addresses or register pairs) on the stack and then
remove (pop) them backwards. That is called LIFO, Last In First Out. The 8085
use a 16-bit register to know where the stack top is located, and that register is
called the SP (Stack Pointer).
PUSH and POP
As you may have guessed, push and pop “pushes” bytes on the stack and then
takes them off. When you push something, the stack counter will decrease with
2 (the stack “grows” down, from higher addresses to lower) and then the register
pair is loaded onto the stack. When you pop, the register pair is first lifted of the
stack, and then SP increases by 2. Note that Push and Pop only operate on words
(2 bytes, i.e. 16 bits). You can push (and pop) all register pairs : BC, DE, HL and
PSW (Register A and Flags). When you pop PSW, remember that all flags may be
changed. You can’t push an immediate value. If you want, you’ll have to load a
register pair with the value and then push it. Perhaps it is worth noting that when
you push something, the contents of the registers will still be the same; they won’t
be erased or something. Also, if you push DE, you can pop it back as HL (you 123
Electronics don’t have to pop it back to the same register where you got it from). The stack is
also updated when you CALL and RETURN from subroutines. The PC (program
counter which points at the next instruction to be executed) is pushed to the stack
and the calling address is loaded into PC. When returning, the PC is loaded with
the word popped from the top of the stack (TOS). So, when is this useful? It is
almost always used when you call subroutines. For example, you have an
often-used value stored in HL. You have to call a subroutine that you know will
destroy HL (with destroy we mean that HL will be changed to another value,
which you perhaps do not know). Instead of first saving HL in a memory location
and then loading it back after the subroutine, you can push HL before calling and
directly after the calling pop it back. Of course, it is often better to use the pushes
and pops inside the subroutine. All registers you know will be changed are often
pushed in the beginning of a subroutine and then popped at the end, in reverse
order. Do not forget – last in first out. If you want to only push one 8-bit register,
you still have to push its “friend”. Therefore, be aware that if you want to store
away D with pushing and popping, remember that E will also be changed back to
what it was before. In those cases, if you don’t want that to happen, you should try
first to change register (try to store the information in E in another register if you
can) or else you have to store it in a temporary variable. Before executing a
program, you should keep track of your pushes and pops, since they are
responsible for 99% of all computer crashes. For example, if you push HL and
then forget to pop it back, the next RET instruction will cause a jump to HL, which
can be anywhere in the ROM/RAM and the computer will crash. Note however,
it’s also a way to jump to the location stored in HL, but then you should really use
the JMP instruction, to do the same thing. Push and pop doesn’t change any flags,
so you can use them between a compare and jump instructions, depending on a
condition, which is often very useful.
Instruction Naming Conventions
The mnemonics assigned to the instructions are designed to indicate the function
of the instruction. The instructions fall into the following functional categories :
Data Transfer Croup
The data transfer instructions move data between registers or between
memory and registers.
MOV Move
MVI Move Immediate
LDA Load Accumulator Directly from Memory
STA Store Accumulator Directly in Memory
LHLD Load H and L Registers Directly from Memory
SHLD Store H and L Registers Directly in Memory
An ‘X’ in the name of a data transfer instruction implies that it deals with a
register pair (16-bits);
LXI Load Register Pair with Immediate data
LDAX Load Accumulator from Address in Register Pair
STAX Store Accumulator in Address in Register Pair
XCHG Exchange H and L with D and E
XTHL Exchange Top of Stack with H and L
Arithmetic Group
The arithmetic instructions add, subtract, increment, or decrement data in
registers or memory.
ADD Add to Accumulator
ADI Add Immediate Data to Accumulator
124
ADC Add to Accumulator Using Carry Flag Microprocessors
126
Microprocessors
SAQ 2
(a) What does a bus mean?
(b) List the Hardware interrupts and Software interrupts in 8085. Which
interrupt has the highest priority?
(c) Name 5 different addressing modes.
(d) What are input and output devices? What is clock frequency for 8085?
127
Electronics
Counters
There are 3 counters (or timers), which are labelled as Counter 0, Counter 1 and
Counter 2. Each counter has 2 input pins – CLK (clock input) and GATE – and
1 pin, OUT, for data output. The 3 counters are 16-bit down counters independent
of each other, and can be easily read by the CPU.
The first counter (selected by setting A1 = A0 = 0, see Control Word Register
below) helps generate an 18.2 Hz clock signal. The second counter
(A1 = 0, A0 = 1) assists in generating timing, which will be used to refresh the
DRAM memory. The last counter (A1 = 1, A0 = 0) generates tones for the PC
speaker.
Besides the counters, a typical Intel 8253 chipset also contains the following
components :
Data/Bus Buffer
This block contains the logic to buffer the data bus to/from the microprocessor,
and to the internal registers. It has 8 input pins, usually labelled as D7..D0, where
D7 is the MSB.
Read/Write Logic
The Read/Write Logic block has 5 pins, which are listed below. Notice that
X\denotes an active low signal.
• RD\: read signal
• WR\: write signal
• CS\: chip select signal
• A0, A1: address lines
Operation mode of the PIT is changed by setting the above hardware signals. For
example, to write to the Control Word Register, one needs to set CS\ = 0, RD\ = 1,
WR\ = 0, A1 = A0 = 1.
Control Word Register
This register contains the programmed information, which will be sent (by the
microprocessor) to the device. It defines how the PIT logically works.
To initialize the counters, the microprocessor must write a control word (CW) in
this register. This can be done by setting proper values for the pins of the
Read/Write Logic block and then by sending the control word to the Data/Bus
Buffer block.
128
The control word contains 8 bits, labeled D7..D0 (D7 is the MSB). Microprocessors
Bit# D7 D6 D5 D4 D3 D2 D1 D0
Name SC1 SC0 RW1 RW0 M2 M1 M0 = 0, 16-b binary counter
The following table describes how to use the Read/Write bits (RW1, RW0).
RW 1 RW 0 Description
0 0 Counter Latch Command
0 1 Read/Write the last significant byte (LSB) only
1 0 Read/Write the most significant byte (MSB)
only
1 1 Read/Write LSB first, followed by MSB
When setting the PIT, the microprocessor first sends a control message, then a
count message to the PIT. The counting process will start after the PIT has
received these messages, and, in some cases, if it detects the rising edge from the
GATE input signal. On most PCs, the address for the Control Word Register is 043
hex, and 040h, 041h, 042h for each counter, respectively.
Operation Modes
The D3, D2, and D1 bits of the Control Word set the operating mode of the timer.
There are 6 modes in total; for modes 2 and 3, the D3 bit is ignored, so the missing
modes 6 and 7 are aliases for modes 2 and 3. Notice that, for modes 0, 2, 3 and 4,
GATE must be set to HIGH to enable counting. For modes 1 and 5, the rising edge
of GATE starts the count.
Mode 0 (000) : Interrupt on Terminal Count
In this mode, the counter will start counting from the initial COUNT value
loaded into it, down to 0. Counting rate is equal to the input clock
frequency. The OUT pin is set low after the Control Word is written, and
counting starts one clock cycle after the COUNT programmed. OUT
remains low until the counter reaches 0, at which point OUT will be set high
until the counter is reloaded or the Control Word is written.
Mode 1 (001) : Hardware-Triggered One Shot
This is similar to mode 0, but counting is started by a rising edge on the
GATE input instead of immediately after programming. The GATE input is
ignored while counting. The output is set high as soon as the Control Word
is written. After COUNT is written, the device will wait until the rising edge
of the GATE input. One clock cycle after this rising edge is detected, OUT
will become and remain low until the counter reaches 0. OUT will then go
high, waiting for the next trigger.
Mode 2 (x10 ) : Rate Generator
In this mode, the device acts as a divide-by-n counter, which is commonly
used to generate a real-time clock interrupt. Like other modes, counting
process will start the next clock cycle after COUNT is sent. OUT will then
remain high until the counter reaches 1, and will go low for one clock pulse.
OUT will then go high again, and the whole process repeats itself. The time
between the high pulses depends on the preset count in the counter’s
register, and is calculated using the following formula: Value to be loaded
129
Electronics into counter = input frequency/output frequency. Note that the values in the
COUNT register range from n to 1. The register never reaches zero.
Mode 3 (x11) : Square Wave Generator
This mode is similar to mode 2. However, the duration of the high and low
clock pulses of the output will be different. Suppose n is the number loaded
into the counter (the COUNT message), the output will be
• high for n/2 counts, and low for n/2 counts, if n is even.
• high for (n+1)/2 counts, and low for (n-1)/2 counts, if n is odd.
Mode 4 (100) : Software Triggered Strobe
After Control Word and COUNT is loaded, the output will remain high until
the counter reaches zero. The counter will then generate a low pulse for 1
clock cycle (a strobe) – after that the output will become high again.
Mode 5 (101) : Hardware Triggered Strobe
This mode is similar to mode 4. However, the counting process is triggered
by the GATE input. After receiving the Control Word and COUNT, the
output will be set high. Once the device detects a rising edge on the GATE
input, it will start counting. When the counter reaches 0, the output will go
low for one clock cycle – after that it will become high again, to repeat the
cycle on the next rising edge of GATE.
0 0 PORT A
0 1 PORT B
1 0 PORT C
1 1 CONTROL
Figure 9.3 : Block Diagram of the 8255 Programmable Peripheral Interface (PPI) 131
Electronics SAQ 3
(a) What can I do with one of 8253/8254 chips?
(b) Draw the block diagram of 8255 Programmable Peripheral Interface.
9.4.1 DAC
Suppose we were to set the input resistor values at multiple powers of two : R, 2R, and
4R of the comparator circuit of Figure 9.5(a). Starting from V1 and going through V3, this
would give each input voltage exactly half the effect on the output as the voltage before
it. In other words, input voltage V1 has a 1 : 1 effect on the output voltage (gain of 1),
while input voltage V2 has half that much effect on the output (a gain of 1/2), and V3 half
of that (a gain of 1/4). These ratios are not arbitrarily chosen: they are the same ratios
corresponding to place weights in the binary number system. If we drive the inputs of
this circuit with digital gates so that each input is either 0 volts or full supply voltage, the
output voltage will be an analog representation of the binary value of these three bits. If
we wish to expand the resolution of this DAC (add more bits to the input), all we need to
do is add more input resistors, holding to the same power-of-two sequence of values as in
Figure 9.5(b).
132
Microprocessors
(a)
(b)
Figure 9.5 : (a) Simple 3-bit DAC; and (b) 6-bit Binary-weighted DAC
9.4.2 ADC
Also called the parallel A/D converter, the circuit of Figure 9.6 is the simple to
understand. It is formed of a series of comparators, each one comparing the input signal
to a unique reference voltage. The comparator outputs connect to the inputs of a priority
encoder circuit, which then produces a binary output. Following illustration of Figure 9.6
shows a 3-bit flash ADC circuit. Not only is the flash converter, the simplest in terms of
operational theory, but it is the most efficient of the ADC technologies in terms of speed,
being limited only in comparator and gate propagation delays. Unfortunately, it is the
most component-intensive for any given number of output bits. This three-bit flash ADC
requires eight comparators. A four-bit version would require 16 comparators. With each
additional output bit, the number of required comparators doubles. Considering that eight
bits is generally considered the minimum necessary for any practical ADC (256
comparators needed), the flash methodology quickly shows its weakness. An additional
advantage of the flash converter, often overlooked, is the ability for it to produce a
non-linear output. With equal-value resistors in the reference voltage divider network,
each successive binary count represents the same amount of analog signal increase,
providing a proportional response. For special applications, however, the resistor values
in the divider network may be made non-equal. This gives the ADC a custom, nonlinear
response to the analog input signal. No other ADC design is able to grant this
signal-conditioning behaviour with just a few component value changes.
Pin 1 is Reset. This pin can be used to force the 2051 to start over at the beginning of the
program. Pin 2 and Pin 3 can be used to communicate with the computer or other devices
(RXD is receive and TXD is transmit). Pin 2 and Pin 3 are also part of Port 3. Port 3
includes P 3.0, P 3.1, P 3.2, P 3.3, P 3.4, P 3.5 and P3.7 (there is no P 3.6). These pins are
usually used as general input/output pins. They can be connected to LEDs to turn them
on and off (this would be using them as outputs). Or they can be connected to switches so
that the 2051 can look and see if a user has turned a switch on or off (this would be using
them as inputs). Pins 4 and 5 are connected to the 11.0592 MHz crystal. The 2051 uses
this crystal to create a clock. The speed of the crystal determines the speed that the 2051
runs at. You can make programs run faster by using a faster crystal such as 24 MHz. Pin
10 is the ground connection for the 2051. Pins 12 to 19 make up Port 1. This is another
set of pins that can be used as general inputs and outputs. Pins 6, 7, 8, 9, 12 and 13 also
have other possible uses that we will not get into here.
136
Microprocessors
9.6.2 Instruction Sets
Command Description
ADD Add Two Numbers
SUBB Subtract Two Numbers
INC Increment Data (Add 1 to existing amount)
DEC Decrement Data (Subtract 1 from existing amount)
MUL Multiply Two Numbers
DIV Divide Two Numbers
ANL Logical AND Two Numbers
ORL Logical OR Two Numbers
XRL Logical XOR Two Numbers
CLR Clear (reset) data to 0
CPL Complement (Flip) Data (1s go to 0 and 0s go to 1)
MOV Move data around in the chip from register to register
SETB Set a number to 1
JB Jump to a new location if a number is 1
JNB Jump to a new location if a number is 0
ACALL Jump to a subroutine, then return to this point when
done with subroutine
RET Return from subroutine (used at end of subroutine)
AJMP Jump to a new location
JZ Jump if a number is 0
JNZ Jump if a number is not 0
CJNE Compare two numbers and jump if they are not equal
DJNZ Decrease a number by 1 and jump if result is not zero
NOP No Operation (used to waste time when waiting for
something to happen)
SAQ 6
Draw the pin configuration of 2051 Microcontroller.
9.8 SUMMARY
In this unit, we have studied 8085 family of microprocessors. Firstly, we understand what
are basic components of a computer, 8085 microprocessor architecture and assembly
language programming. Then we understand microprocessor I/O and LSI Counters.
Specifically we have discussed about 8255 PPI and 8253 PIT. ADC and DAC are
discussed for digital and analog interfacing. For serial data communications we have
learnt the RS232C standards. 2051 Microcontroller is then studied to understand the
concepts of Microcontroller and how to program them. Finally recent trends in
microprocessor technology like 8086, 80286, 80386 and Digital Signal Processors have
been investigated.
138
Microprocessors
9.9 ANSWERS TO SAQs
SAQ 1
(a) Various registers in 8085 are Accumulator register, Temporary register,
Instruction register, Stack Pointer, Program Counter. Stack pointer and
Program counter have 16 bits.
(b) Sign flag, Zero flag, Auxillary flag, Parity flag, Carry flag.
(c) Stack pointer is a special purpose 16-bit register in the Microprocessor,
which holds the address of the top of the stack. LIFO (Last In First Out)
stack is used in 8085.In this type of Stack the last stored information can be
retrieved first.
(d) Program counter holds the address of either the first byte of the next
instruction to be fetched for execution or the address of the next byte of a
multi byte instruction, which has not been completely fetched. In both the
cases it gets incremented automatically one by one as the instruction bytes
get fetched. Also Program register keeps the address of the next instruction.
SAQ 2
(a) A bus is a group of conducting lines that carriers data, address, & control
signals.
(b) Hardware Interrupts: TRAP, RST7.5, RST6.5, RST5.5, INTR. Software
Interrupts: RST0, RST1, RST2, RST3, RST4, RST5, RST6, RST7. TRAP
has the highest priority.
(c) Immediate, Direct, Register, Register indirect, Implied addressing modes.
(d) Keyboards, Floppy disk are the examples of input devices. Printer,
LED/LCD display, CRT Monitor are the examples of output devices.
3 MHz is the maximum clock frequency for 8085.
SAQ 3
(a) The uses of a timer/counter chip are quite varied. You may need to time an
event very accurately, check the speed of something, create a square wave or
pulses at a particular rate, or even control the speed of a DC motor. With
many programmable modes, these chips can answer almost any timing or
counting problem you can conceive.
(b) Refer to Figure 9.3.
SAQ 4
In the early 1960s, a standards committee, today known as the Electronic
Industries Association, developed a common interface standard for data
communications equipment. At that time, data communications was thought to
mean digital data exchange between a centrally located mainframe computer and a
remote computer terminal, or possibly between two terminals without a computer
involved. These devices were linked by telephone voice lines, and consequently
required a modem at each end for signal translation. While simple in concept, the
many opportunities for data error that occur when transmitting data through an
analog channel require a relatively complex design. It was thought that a standard
was needed first to ensure reliable communication, and second to enable the
interconnection of equipment produced by different manufacturers, thereby
fostering the benefits of mass production and competition. From these ideas, the
RS232 standard was born. It specified signal voltages, signal timing, signal
function, a protocol for information exchange, and mechanical connectors.
SAQ 5 139
Electronics RS232 is a standard for serial binary data interconnection between a DTE (Data
terminal equipment) and a DCE (Data Circuit-terminating Equipment).
SAQ 6
Refer to Figure 9.7.
SAQ 7
(a) 80386.
(b) A digital signal processor (DSP) is a specialized microprocessor designed
specifically for real-time digital signal processing. The first DSP produced
by Texas Instruments is TMS32010.
FURTHER READING
G. W. Roberts and A. S. Sedra, (1992), SPICE for Microelectronic Circuits, Saunders
College Publishing, USA.
J. Millman and C. C. Halkias, (1971), Integrated Electronics, McGraw-Hill Book
Company, Chapter 15.
Donald A. Neamen, (2002), Electronic Circuit Analysis and Design, Second Edition,
Tata McGraw Hill Edition.
D. V. Bugg, (2004), Electronics : Circuit, Amplifiers and Gates, Overseas Press
(INDIA), Private Limited.
B. G. Streetman, (1995), Solid State Electronic Devices, Prentice Hall of India, New
Delhi.
J. Millman, and A. Grabel, (1987), Microelectronics, McGraw-Hill, International.
L. Millman, and C. C. Halkias, (1995), Integrated Electronics : Analog and Digital
Circuits and Systems, Tata McGraw-Hill Publishing Company, New Delhi.
H. Taub, and D. Schilling, (1985), Digital Integrated Electronics, Tata McGraw-Hill
Publishing Company, New Delhi.
S. M. Sze, (1981), Physics of Semiconductor Devices, Wiley Eastern.
R. S. Gaonkar, (1990), Microprocessor Architecture : Programming and Applications
with the 8085/8080 A, Wiley Eastern.
I. Liu and G. A. Gibson (1986), Microprocessor Systems : The 8086/8088 Family,
2nd Edition, Prentice Hall.
140
Microprocessors
ELECTRONICS
Block 2 of the course Principle of Electrical and Electronics Sciences covers four units.
Unit 6 deals with semi-conductor devices. In this unit, you will be introduced with p-n
junction diodes and zener diodes. Different types of transistors and power devices have
been also explained in this unit.
Unit 7 discusses about electronic circuits. In this unit, rectifier circuits, transistor
amplifier circuits, operational amplifiers, voltage regulator circuits, and IC Timer 555
have been described.
Unit 8 is on Digital Electronics and cover logic gates and Boolean algebra, Karnaugh
maps, tristate concepts, sequential circuits and memories. Introduction to 8085, I/O and
Interfacing LSI counters, D/A and A/D converters, serial interfacing and communication,
introduction to 2051 microcontroller and recent trends in microprocessors are discussed
in Unit 9 on Microprocessors.
141