Anda di halaman 1dari 31

Microprocessors

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.

9.2 INTRODUCTION TO 8085


Any microprocessor family can be used for illustration of microprocessor fundamentals
and applications. We will use 8085 microprocessor family for this purpose. It will be
good to learn a microprocessor family well then you can learn the other families easily
since they have similar kinds of functions and operations. We will first introduce you to
the basic components of a computer for better understanding of the later parts of this
section.
9.2.1 Block Diagram of Computer
Figure 9.1 shows a block diagram for Von Neumann computer model. The major parts of
this model are the central processing unit (CPU), memory, and the Input and output
circuitry or l/O. Connecting these parts are three sets of parallel lines called buses. The
three buses are the address bus, the data bus, and the control bus. Let’s take a brief look
at each of these parts.

Figure 9.1 : Block Diagram of a Computer

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

In order to perform internal data operations, microprocessor needs registers,


arithmetic logic unit (ALU), control logic and internal data buses.
Accumulator
This register is a part of ALU denoted by A and used for arithmetic and
logical operations, the results of an operation are stored in this register.
Registers
8085 has six registers to store 8-bit data viz. B, C, D, E, H and L. They can
paired as BC, DE and HL for 16-bit operations. A programmer can use these
registers to transfer or load data.
Flags
Five Flip Flops are kept for testing data conditions in the accumulator and
other registers; they are set or reset accordingly. Five flags are Zero (Z),
Carry (CY), Sign (S), Parity (P), Auxiliary Carry (AC). For example Zero
Flag (Z) is set to one when an operation results in a zero.
Program Counter (PC)
It is a 16-bit register, which does the function of sequencing of programs
execution. It basically points to the memory address from which the next
machine code is to be collected. Whenever a machine code is obtained PC is
incremented by 1.
Stack Pointer (SP)
It is a 16-bit register and points to a memory location in R/W memory.
9.2.3 Assembly Language Programming
What is a Program?
A computer can only do what a programmer has instructed it to do, in the form of
a program. A program is just a sequence of very simple commands that lead the
computer to solve some problem. Once the program is written correctly, the
computer can execute the instructions very fast, and always do it the same, every
time, without a mistake. There lies the power of a computer. Even though the
program consists of very simple instructions, the overall result can be very
impressive, mostly due to the speed at which the computer can process the
instructions. Even though each step in the program is very simple, the sequence of
instructions, executing at millions of steps per second, can appear to be very
complicated, when taken as a whole. The trick is not to think of it as a whole, but
as a series of very simple steps, or commands.
The microprocessor itself is usually a single integrated circuit (IC). Most
microprocessors, or very small computers, have much the same commands or
instructions that they can perform. They vary mostly in the names used to describe
each command. In a typical microprocessor, there are commands to move data
around, do simple math (add, subtract, multiply, and divide), bring data into the
microprocessor from the outside world, and send data out of the microprocessor to
the outside world. A typical microprocessor has three basic parts inside. They are
the Program Counter (PC), Memory, and Input/Output (I/O). The Program Counter
keeps track of which command is to be executed. The Memory contains the
commands to be executed. The Input/Output handles the transfer of data to and
from the outside world.
A Simple Program
As stated before, a program is a sequence or series of very simple commands or
instructions. A real world example program might be the problem of crossing a
busy street.
115
Electronics Step 1
Walk up to the traffic lights and stop.
Step 2
Look at the traffic light.
Step 3
Is your light green?
Step 4
If the light is red, goto step 2. (Otherwise continue to step 5)
Step 5
Look to the left.
Step 6
Are there cars still passing by?
Step 7
If yes, goto step 5. (Otherwise continue to step 8).
Step 8
Look to the right.
Step 9
Are there cars still passing by? (There shouldn’t be any by now).
Step 10
If yes, goto step 8. (Otherwise continue to step 11).
Step 11
Proceed across the street, carefully.
Now this may seem childish at first glance, but this is exactly what you do every
time you cross a busy street, that has a traffic light. This is also exactly how you
would tell a microprocessor to cross the street, if one could. This is what I mean by
a sequence or series of very simple steps. Taken as a whole, the steps lead you
across a busy intersection, which, if a computer did it, would seem very intelligent.
People are intelligent. A programmer that programmed these steps into a
microprocessor, would impart that intelligence to the microprocessor. The
microprocessor would not, however, in this case, know what to do when it got to
the other side, since we didn’t tell it. A person, on the other hand, could decide
what to do next, at a moments notice, without any apparent programming. In the
case of a person, though, there has been some programming; it is called past
experiences.
Another program might be to fill a glass with water from a tap.
Step 1
Turn on the water.
Step 2
Put the glass under the tap.
Step 3
Look at the glass.
Step 4
Is it full?
116
Step 5 Microprocessors

If no, goto step 3. (Otherwise, continue to step 6).


Step 6
Remove the glass from under the tap.
Step 7
Turn off the water.
This is a simpler program, with fewer steps, but it solves a problem, to fill a glass
with water. In a microprocessor, the problems are different but the logical steps to
solve the problem are similar, that is, a series of very simple steps, leading to the
solution of a larger problem. Also notice that since the steps are numbered, 1
through 7, that is the order in which they’re executed. The Program Counter, in
this case, is you, reading each line, starting with 1 and ending with 7, doing what
each one says. In a microprocessor, the Program Counter automatically advances
to the next step, after doing what the current step says, unless a branch, or jump, is
encountered. A branch is an instruction that directs the Program Counter to go to a
specific step, other than the next in the sequence. The branch in this example is
step 5. Not only is this a branch, but it is a conditional branch. In other words,
based on whether the glass is full or not, the branch is taken, or not. A
microprocessor has both branch and conditional branch instructions. Without this
ability to reuse instructions, in a sort of looping action, a solution would take many
more steps, if it would be possible at all. The point is to show how a simple set of
instructions can solve a bigger problem. Taken as a whole, the solution could
appear to be more complicated than any of the separate steps it took to solve it.
The most difficult problem to be solved in programming a microprocessor is to
define the problem you are trying to solve. Sounds silly but I assure you, it is not.
This is the Logical Thought Process. It is having a good understanding of the
problem you are trying to solve.
Microprocessor Instructions
In the CPU we will be using, there are 4 different types of instructions and several
variations of each, resulting in over 100 different instructions. These 4 types are
(a) ARITHMETIC,
(b) LOGICAL,
(c) BRANCHING, and
(d) DATA TRANSFER.
ARITHMETIC
The arithmetic instructions usually include addition, subtraction, division,
multiplication, incrementing, and decrementing although division and
multiplication were not available in most early CPUs. There are two flags
used with arithmetic that tell the program what was the outcome of an
instruction. One is the Carry (C) flag. The other is the Zero (Z) flag. The
C flag will be explained in the following example of addition. The Z flag, if
set, says that the result of the instruction left a value of 0 in the accumulator.
Addition
This is straightforward and is simply to add two numbers together and
get the result. However there is one more thing. If, in the addition, the
result was too big to fit into the accumulator, part of it might be lost.
There is a safeguard against this. Take the case of 11111111b (255)
and 11111111b (255). These are the largest numbers that can fit into
an 8-bit register or memory location. You can add these as decimal
numbers, since I gave you their values in decimal also, and you would
get 510. The binary value for 510 is 111111110b (9 bits). The
accumulator is only 8 bits wide, it is a byte. How do you fit a 9-bit
number into 8 bits of space? The answer is, you can't, and it’s called
an OVERFLOW condition. So how do we get around this dilemma? 117
Electronics We do it with the CARRY (C) flag. If the result of the addition is
greater than 8 bits, the CARRY (C) flag will hold the 9th bit. In this
case the accumulator would have in 11111110b (254) and the C flag
would be a 1, or set. This 1 has the value of 256 because this is the
9th bit. We haven’t covered a 9-bit number, but they come up all the
time as overflows in addition. Adding 254 and 256, we get 510, the
answer, and we didn't loose anything, because of the C flag. Had the
result of the addition not caused an overflow, the C flag would be 0,
or cleared.
Subtraction
In the case of subtraction, the process is more difficult to explain. It
involves 1's complement and 2's complement representation. But I
will tell you this, you can subtract two numbers and if there is an
under flow, the C flag will be a 1, otherwise it will be a 0. An under
flow is where you subtract a larger number from a smaller number.
Basically there are four steps for subtraction: (a) converts subtrahend
(the number to be subtracted) into its 1’s complement (b) add 1 to 1’s
complement to obtain 2’s complement of the subtrahend (c) add 2’s
complement to the minuend (d) complements the carry flag.
Multiplication and Division
In the 8085, multiply and divide instructions are not available.
Increment and Decrement
Two other instructions are included in the arithmetic group. They are
increment and decrement. These instructions are used to count events
or loops in a program. Each time an increment is executed, the value
is incremented by 1. A decrement, decrements the value by 1. These
can be used with conditional jumps to loop a section of program, a
certain number of times. We will see these used later.
LOGICAL
In microprocessors there are other mathematical instructions called logical
instructions. These are OR, AND, XOR, ROTATE, COMPLEMENT and
CLEAR. These commands are usually not concerned with the value of the
data they work with, but, instead, the value, or state, of each bit in the data.
OR
The OR function can be demonstrated by taking two binary numbers,
1010b and 0110b. When ORing two numbers, it doesn’t matter at
which end you start, right or left. Let’s start from the left. In the first
bit position there is a 1 in the first number and a 0 in the second
number. This would result in a 1. The next bit has a 0 in the first
number and a 1 in the second number. The result would be 1. The
next bit has a 1 in the first number and a 1 in the second number. The
result would be a 1. The last bit has a 0 in the first number and a 0 in
the second number, resulting in a 0. So the answer would be 1110b.
The rule that gives this answer says that with an OR, a 1 in either
number result in a 1, or said another way, any 1 in, gives a 1 out.
AND
ANDing uses a different rule. The rule here is a 0 in either number
will result in a 0, for each corresponding bit position. Using the same
two numbers 1010b and 0110b the result would be 0010b. You can
see that every bit position except the third has a zero in one or the
other number. Another way of defining an AND is to say that a 1
AND a 1 results in a 1.
XOR (eXclusive OR)

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

ACI Add Immediate data to Accumulator Using Carry


SUB Subtract from Accumulator
SUI Subtract Immediate Data from Accumulator
SBB Subtract from Accumulator Using Borrow (Carry) Flag
SBI Subtract Immediate from Accumulator Using Borrow
(Carry) Flag
INR Increment Specified Byte by One
DCR Decrement Specified Byte by One
INX Increment Register Pair by One
DCX Decrement Register Pair by One
DAD Double Register Add; Add Content of Register
Pair to H and L Register Pair
Logical Group
This group performs logical (Boolean) operations on data in registers and
memory and on condition flags. The logical AND, OR, and Exclusive OR
instructions enable you to set specific bits in the accumulator ON or OFF.
ANA Logical AND with Accumulator
ANI Logical AND with Accumulator Using Immediate Data
ORA Logical OR with Accumulator
OR Logical OR with Accumulator Using Immediate Data
XRA Exclusive Logical OR with Accumulator
XRI Exclusive OR Using Immediate Data
The Compare instructions compare the content of an 8-bit value with the
contents of the accumulator;
CMP Compare
CPI Compare Using Immediate Data
The rotate instructions shift the contents of the accumulator one bit position
to the left or right :
RLC Rotate Accumulator Left
RRC Rotate Accumulator Right
RAL Rotate Left Through Carry
RAR Rotate Right Through Carry
Complement and Carry Flag Instructions
CMA Complement Accumulator
CMC Complement Carry Flag
STC Set Carry Flag
Branch Group
The branching instructions alter normal sequential program flow, either
unconditionally or conditionally. The unconditional branching instructions
are as follows :
JMP Jump
CALL Call
RET Return 125
Electronics Conditional branching instructions examine the status of one of four
condition flags to determine whether the specified branch is to be executed.
The conditions that may be specified are as follows :
NZ Not Zero (Z = 0)
Z Zero (Z = 1)
NC No Carry (C = 0)
C Carry (C = 1)
PO Parity Odd (P = 0)
PE Parity Even (P = 1)
P Plus (S = 0)
M Minus (S = 1)
Thus, the conditional branching instructions are specified as follows :
Jumps Calls Returns
C CC RC (Carry)
INC CNC RNC (No Carry)
JZ CZ RZ (Zero)
JNZ CNZ RNZ (Not Zero)
JP CP RP (Plus)
JM CM RM (Minus)
JPE CPE RPE (Parity Even)
JP0 CPO RPO (Parity Odd)
Two other instructions can affect a branch by replacing the contents or the
program counter :
PCHL Move H and L to Program Counter
RST Special Restart Instruction Used with Interrupts
Stack I/O, and Machine Control Instructions
The following instructions affect the Stack and/or Stack Pointer :
PUSH Push two bytes of Data onto the Stack
POP Pop Two Bytes of Data off the Stack
XTHL Exchange Top of Stack with H and L
SPHL Move content of H and L to Stack Pointer
The I/0 instructions are as follows :
IN Initiate Input Operation
OUT Initiate Output Operation
The Machine Control instructions are as follows :
EI Enable Interrupt System
DI Disable Interrupt System
HLT Halt
NOP No Operation
SAQ 1
(a) What are the various registers in 8085? Name the 16 bit registers.
(b) What are the various flags used in 8085?
(c) What is Stack Pointer? Which Stack is used in 8085?
(d) What is Program counter?

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?

9.3 I/O AND INTERFACING LSI COUNTERS


9.3.1 Programmable Interval Timers
The Intel 8253 and 8254 are Programmable Interval Timers (PITs), which perform
timing and counting functions. They are found in all x86 PCs. The timer has three
counters, called channels. Each channel can be programmed to operate in one of six
modes. Once programmed, the channels can perform their tasks independently. The timer
is usually assigned to IRQ-0 (highest priority hardware interrupt) because of the critical
function it performs and because so many devices depend on it.

(a) Block Diagram

127
Electronics

(b) Pin Configuration


Figure 9.2 : 8253 Programmable Interval Timer

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

Func. Select Counter Read/Write Select Mode = 1, 4-decade BCD 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.

9.3.2 Programmable Peripheral Interface


8255 is a general purpose programmable peripheral parallel I/O device manufactured by
Intel and it is compatible with any microprocessor. It has three programmable ports
including one port for bi-directional data transfer.
Data Bus Buffer
This three-state bi-directional 8-bit buffer is used to interface the 8255 to the
system data bus. Data is transmitted or received by the buffer upon execution of
input or output instructions by the CPU. Control words and status information are
also transferred through the data bus buffer.
Read/Write and Control Logic
The function of this block is to manage all of the internal and external transfers of
both Data and Control or Status words. It accepts inputs from the CPU Address
and Control busses and in turn, issues commands to both of the Control Groups.
(CS) Chip Select. A “low” on this input pin enables the communication between
the 8255 and the CPU.
(RD) Read. A “low” on this input pin enables 8255 to send the data or status
information to the CPU on the data bus. In essence, it allows the CPU to “read
from” the 8255.
(WR) Write. A “low” on this input pin enables the CPU to write data or control
words into the 8255.
(A0 and A1) Port Select 0 and Port Select 1. These input signals, in conjunction
with the RD and WR inputs, control the selection of one of the three ports or the
control word register. They are normally connected to the least significant bits of
the address bus (A0 and A1).
(RESET) Reset. A “high” on this input initializes the control register to 9Bh and
all ports (A, B, C) are set to the input mode.
130
Microprocessors
A1 A0 SELECTION

0 0 PORT A

0 1 PORT B

1 0 PORT C

1 1 CONTROL

Group A and Group B Controls


The systems software programs the functional configuration of each port. In
essence, the CPU “outputs” a control word to the 8255. The control word contains
information such as “mode”, “bit set”, “bit reset”, etc., that initializes the
functional configuration of the 8255. Each of the Control blocks (Group A and
Group B) accepts “commands” from the Read/Write Control logic, receives
“control words” from the internal data bus and issues the proper commands to its
associated ports.
Ports A, B, and C
The 8255 contains three 8-bit ports (A, B, and C). All can be configured to a wide
variety of functional characteristics by the system software but each has its own
special features or “personality” to further enhance the power and flexibility of
the 8255.
Port A One 8-bit data output latch/buffer and one 8-bit data input latch. Both “pull-
up” and “pull-down” bus-hold devices are present on Port A.
Port B One 8-bit data input/output latch/buffer and one 8-bit data input buffer.
Port C One 8-bit data output latch/buffer and one 8-bit data input buffer (no latch
for input). This port can be divided into two 4-bit ports under the mode control.
Each 4-bit port contains a 4-bit latch and it can be used for the control signal
output and status signal inputs in conjunction with ports A and B.

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 D/A AND A/D CONVERTERS


To interface two peripherals one of them is digital and the other one is analog we have to
add analog to digital converter (ADC) and digital to analog converter (DAC). Let us
study ADC and DAC in brief. Connecting digital circuitry to sensor devices is simple if
the sensor devices are inherently digital themselves. Switches, relays, and encoders are
easily interfaced with gate circuits due to the on/off nature of their signals. However,
when analog devices are involved, interfacing becomes much more complex. What is
needed is a way to electronically translate analog signals into digital (binary) quantities,
and vice-versa. An analog-to-digital converter, or ADC, performs the former task while a
digital-to-analog converter, or DAC, performs the latter. An ADC inputs an analog
electrical signal such as voltage or current and outputs a binary number. In block diagram
form, it can be represented as in Figure 9.4. It is much easier to convert a digital signal
into an analog signal than it is to do the reverse. Therefore, we will begin with DAC
circuitry and then move to ADC circuitry.

Figure 9.4 : ADC/DAC

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.

Figure 9.6 : Parallel ADC


133
Electronics SAQ 4
Draw a circuit diagram of DAC and ADC.

9.5 SERIAL INTERFACING AND


COMMUNICATION
Serial communications means that information is transmitted from source to destination
over a single pathway. A simplex serial data link transmits data in only one direction.
Usually, two serial data links are between a computer and terminal: one for transmission
in each direction. This is called full-duplex operation.
9.5.1 RS232
RS232 is a standard for serial binary data interconnection between a DTE (Data Terminal
Equipment) and a DCE (Data Communication Equipment). It is commonly used in
computer serial ports. The standard was originally promulgated by RETMA, a precursor
of the Electronic Industries Alliance. RS is an abbreviation for RETMA Standard. The
RS-232 communications standard has been in use for very many years and is one of the
most widely used standards for serial data communications. RS232 communication can
be used in either an asynchronous mode, which is the most common, or a synchronous
mode. Originally the RS232 communication specification was devised in 1962. When
there is need to transmit data along a variety of line started to grow, the telephone
companies saw the need to introduce some standards. As a result the Electrical Industries
Association (EIA) in the USA created a standard for serial data transfer or
communication known as RS232. It defines the electrical characteristics for transmission
of data between a DTE and the DCE. Normally the data communications equipment is
the modem (modulator/demodulator), which that encodes the data into a form that can be
transferred along the telephone line. Data Terminal Equipment could be a computer.
Since it was first introduced, there have been a number of updates to the RS-232
standard. These have included in EIA-232 and later EIA/TIA-232 (Telecommunications
Industry Association).
Interface Basics
The interface is intended to operate over distances of up to 15 meters. This is
because any modem is likely to be near the terminal. Data rates are also limited.
The maximum data rates for RS-232C is 19.2 k baud or bits per second although
slower rates are often used.
Connections
The RS-232C specification does not include a description of the connector to be
used. However, the most commonly used connector is the 25-pin D-type
connector.
RS232 Signal Levels
The voltage levels are one of the main specifications. For RS232 data signals, a
voltage between – 3V and – 25V represents logic 1. A voltage between + 3V and
+ 25V represents the logic 0. Control signals are in the “ON” state if their voltage
is between + 3V and + 25V and “OFF” if they are negative, i.e. between – 3V and
− 25V. The data is sent serially on RS232, each bit is sent one after the next
because there is only one data line in each direction. This mode of data
transmission also requires that the receiver knows when the actual data bits are
arriving so that it can synchronize itself to the incoming data. To achieve this logic
134
0 is sent as a start bit for the synchronization. This is followed by the data itself Microprocessors
and there are normally seven or eight bits. The receiver obviously has to know
how many data bits to expect, and there are often small dual in line switches either
on the back of the equipment or inside it to set this information. Data on RS232 is
normally sent using ASCII (American Standard Code for Information
Interchange). However other codes can be used equally well. After the data itself a
parity bit is sent. Again this requires setting because it is optional and it can be
even or odd parity. This is used to check the correctness of the received data and it
can indicate whether the data has an odd or even number of logic ones. Unlike
many systems these days there is no facility for error correction. Finally a stop bit
is sent. This is normally one bit long and is used to signify the end of a particular
byte. Sometimes two stop bits are required and again this is an option that can
often be set on the equipment. RS232 data transmission is normally asynchronous.
However transmit and receive speeds must obviously be the same. A certain
degree of tolerance is allowed. Once the start bit is sent the receiver will sample
the center of each bit to see the level. Within each data word the synchronization
must not differ by more than half a bit length otherwise the incorrect data will be
seen. Fortunately this is very easy to achieve with today's accurate bit or baud rate
generators.
Lines and Their Usage
There are four types of line defined in the RS232 specification. They are Data,
Control, Timing and Ground. Not all of them are required all the time. It is
possible to set up a very simple communication using very few lines. When
looking at the lines and their functions it is necessary to remember that they are
defined for a connection between a modem (the data set or communications
equipment) and a terminal or computer (data terminal equipment) in mind. All the
lines have directions, and when used in this way a one to one cable operates
correctly. The most obvious lines are the data lines. There are two of these, one for
data traveling in each direction. Transmit data is carried on pin 2 and the receive
data is carried on line three. The most basic of the control circuits is Data Carrier
Detected (DCD). This shows when the modem has detected a carrier on the
telephone line and a connection appears to have been made. It produces a high,
which is maintained until the connection is lost. Data Terminal Ready (DTR) and
Data Set Ready (DSR) are the main control circuits. They convey the main
information between the terminal and modem. When the terminal is ready to start
handling data it flags this on the DTR line. If the modem is also ready then it
returns its signal on the DSR line. These circuits are mainly used for telephone
circuits. After a connection has been made the modem will be connected to the line
by using DTR. This connection will remain until the terminal is switched off when
the DTR line is dropped. The modem will detect this and release the telephone
line. Sometimes pin 20 is not assigned to DTR. Instead another signal named,
Connect Data Set To Line (CDSTL) is used. This is virtually the same as DTR, but
differs in that DTR merely enables the modem to be switched onto the telephone
line. CDSTL commands the modem to switch, despite anything else it may be
doing. A further two circuits, Request To Send (RTS) and Clear To Send (CTS)
are also used. This pair of circuits is used together. The terminal equipment will
flag that it has data to send. The modem will then return the CTS signal to give all
clear after a short delay. This signaling is used particularly when switched carriers
are used. It means that the carrier is only present on the line when there is data to
send. It finds its uses when one central modem is servicing several others at remote
locations.
Secondary Lines
There are two types of lines that are specified in the RS-232 specification. There
are the primary channels that are normally used, and operate at the normal or
higher data rates. However, there is also provision for a secondary channel for
providing control information. If it is used it will usually send data at a much
slower rate than the primary channel. As the secondary lines are rarely used or 135
Electronics even implemented on equipment, manufacturers often use these connector pins for
other purposes. In view of this it is worth checking that the lines are not being used
for other purposes before considering using them. When the secondary system is in
use, the handshaking signals operate in the same way as for the primary circuit.
Grounding
The ground connections are also important. There are two. First the protective
ground ensures that both equipments are at the same earth potential. This is very
useful when there is a possibility that either equipment is not earthed. The signal
ground is used as the return for the digital signals traveling along the data link. It is
important that large currents that are not part of the signaling do not flow along
this line otherwise data errors may occur.
SAQ 5
What is RS232?

9.6 INTRODUCTION TO 2051 MICROCONTROLLER


9.6.1 Microcontroller Architectures
The 2051 microcontroller is a complex integrated circuit that is programmable. You can
give it a set of commands to follow and it will run through those commands and do
exactly what you want it to do. This section will give a quick overview of the pins of the
2051 and in the later we will discuss how to program the 2051. The 2051 is shown
below.

Figure 9.7 : 2051 Microcontroller Pin Configuration

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.7 RECENT TRENDS IN MICROPROCESSORS


9.7.1 8086
The 8086 is a 16-bit microprocessor chip designed by Intel in 1976, which gave rise to
the x86 architecture. It can be used as a CPU for microcomputer and it is compatible with
8085 microprocessor. It has 29,000 transistors. It has 16-bit data bus and 20-bit address
bus. It can read/write data to memory 16 bits or 8 bits at a time and it can address
220=1,048,576 memory locations which store a byte. 16-bit words will be stored in two
consecutive memory locations. The first commercial microcomputer built on the basis of
the 8086 was the Mycron 2000. The most influential microcomputer of all, the IBM PC,
used the Intel 8088, a version of the 8086 with a narrower memory bus. 137
Electronics 9.7.2 80286
The Intel 80286 (often abbreviated to 286) is an x86-family 16-bit microprocessor that
was introduced by Intel in 1982. It can be used as a CPU for a multi-user microcomputer.
It has 134,000 transistors. The 80286's performance is more than twice that of its
predecessors (the Intel 8086) per clock cycle. It has two modes of operation: real address
mode and virtual address mode. In real address mode 80286 is equivalent 8086, whereas,
in virtual address mode, it has the facility of keeping each users program separately,
protect system programs from destruction by the user’s programs. It was widely used in
IBM PC compatible computers during the mid 1980s to early 1990s.
9.7.3 80386
The Intel 80386 is a microprocessor, which was used as the central processing unit
(CPU) of many personal computers from 1986 until 1994 and later. During its design
phase the processor was code-named simply “P3”, the third-generation processor in the
x86 line, but was and is frequently referred to as the i386. 80386 is a 32-bit
microprocessor and it has 32-bit address, 32-bit data as well as it is compatible with the
earlier Intel 16-bit processors like 8086, 80286. The 80386 featured three operating
modes : real mode, protected mode and virtual mode. In the real mode, the 80386 (like
the 80286) would run just as a fast 8086. The protected mode allowed the use of all the
possibilities of the 286 and the protected mode extension of the 386, especially
addressing up to 4 GB of memory. Finally, the virtual 8086 mode made it possible to run
one or more virtual 8086 machines in a protected environment.
9.7.4 Digital Signal Processors
A digital signal processor (DSP) is a specialized microprocessor designed specifically for
real-time digital signal processing. The first DSP produced by Texas Instruments (TI),
the TMS32010 in 1983. It has separate instruction and data memory. It has a special
instruction set, with instructions like load-and-accumulate or multiply-and-accumulate. It
can work on 16-bit numbers and needed 390ns for a multiply-add operation. TI is now
the market leader in general purpose DSPs. The TMS320 series can be programmed
using high-level languages C, C++, and/or low-level assembly language. The processor is
available in many different variants, some with fixed-point arithmetic and some with
floating point arithmetic. The floating point DSP TMS320C3x, which exploits delayed
branch logic, has as many as three delay slots. The flexibility of this line of processors
has led to it being used not merely as a co-processor for digital signal processing but also
as a main CPU.
SAQ 7
(a) Which microprocessor is code-named as P3?
(b) What are the DSP? Name the first DSP produced by Texas Instruments.

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

Anda mungkin juga menyukai