Class Notes 1 Microprocessor Interfacing
Class Notes 1 Microprocessor Interfacing
i
TABLE OF CONTENTS
Contents
1. INTRODUCTION................................................................................................................................1
2. LITERATURE REVIEW.....................................................................................................................2
2.1.1 TYPES OF MICROPROCESSOR INTERFACES...............................................................3
2.1.1.1 INPUT / OUTPUT (I/O) INTERFACING............................................................................3
2.1.1.2 MEMORY INTERFACING..................................................................................................16
2.1.1.2.4 Microprocessor Read Only Memory (ROM) Interfacing.........................................26
2.1.1.2.5 Microprocessor RAM Interfacing................................................................................28
4. CONCLUSION..................................................................................................................................35
ii
MICROPROCESSOR INTERFACING
1. INTRODUCTION
only one set of addresses and data buses to be used by all peripherals. This
microprocessor while isolating all other peripherals, and ensuring that all the
microprocessor to work with real world data. Data available in various forms
and from various sources requires input interfacing to feed them to the
microprocessor-based systems.
memory etc. The display unit and the keyboard requires to be connected with
data electronic processing circuits. After processing the real world data, the
1
converters, ports and devices to output data to the real world. Also the
2. LITERATURE REVIEW
gotten from the input / output bus, interprets them for peripherals and offers
signals for the peripheral controller. It is also synchronizes the data flow and
These commands are include control command, status command, data output
actuate the peripheral and notify it what to do. A status command is used to
output command makes the interface to respond by transmitting data from the
bus to one of its registers. The data input command is the opposite of the
data output. In this case the interface receives on item of data from the
2
2.1.1 TYPES OF MICROPROCESSOR INTERFACES
Input / output bus and interface module synchronize the data flow and delivers
keyboard, scanner and many other peripherals and writes data to output
devices like monitor, printer and many others. When one or several
3
interface carry out buffering, address coding, command addressing, timing,
and control.
Buffering
peripheral.
Address decoding
system.
Command decoding
Command decoding helps the peripherals to carry out activities other than
information transmission.
decoding. Interfacing devices are extensive hardware (IC chips) and are used
and others. Also there are other more sophisticated interfaces like the
function type.
printer, mouse, keyboard and many others. Input / Output (I/O) interfacing is
4
the linking of the microprocessor with the keyboard and other devices.
Latches and buffers are used to interface the microprocessor with the
There are three major required tasks in getting meaningful data from a
keyboard:
3. Encode the key press (produce a standard code for the pressed key).
Key Debounce:
5
Figure 2 A Mechanical Key and its response (Source: Reddy, 2000)
The rows of the matrix are linked to four output port lines and columns are
connected to four input port buses. When no keys are pressed, the column
lines are held high by the pull-up resistors connected to +5 volits. Pressing a
To determine whether any key is pressed is to output 0‟s to all rows & then
column. When all columns are high, the program enters another loop, which
key press. A simple twenty (20) or ten (10) milliseconds delay is executed to
debounce the task. After the debounce time, another determination is made
to perceive whether the key is still pressed. If the columns are this time all
high, then no key is pressed and the earlier detection would have been
recommended:
6
2. The microprocessor has to pause for the transient period (at least for ten
position.
If any of the columns are low at the moment, then the supposition is made
that it was an effective key press. The last activity is to define the row and
column of the pressed key and change this data to Hex-code for the pressed
key. The 4-bit code from the input port and the 4-bit code from the output port
7
2.1.1.1.2 Interfacing multiplexed 7-segment display
8
To read switches: IN 84H / 8CH /94H / 9CH. A = F8H.
The 8255 is used to transfer digital data output of analogue to digital (ADC) to
the CPU and port C to control signals. Assume that an anlage input present
9
Figure 9 Input / output (I / O) addressing
unique addresses. Input / output (I/O) addressing is done in two ways namely
memory locations.
I/O mapped I/O device is treated as I/O device. In I/O mapped I/O: eight
address lines are used (A0 – A7). 28 = 256 addresses are generated.
256 input and 256 output devices can be addressed. IN /OUT instructions are
used. [In XXH, OUT XXH]. Io/M is high i.e. control signals used are IOR and
low.
10
Figure 10 Output devices addressing (LEDs)
When a latch is enabled, data lines are transferred to LEDs. MVI, OFH
The instruction out 01Hb results in: A7 – A0 = 00000001 = 01H which makes
IOARD’ low; WR’ low; IO/M’ high; latch enabled; copying of accumulator
A0 and A1 lines are not used. Latch will be enabled for all values of A0 and
using four addresses: 00H.01H, 03H and 03H termed as partial decoding.
11
Figure 11 Output device addressing (LEDs): Partial decoding
D7.
IN FFH
12
Figure 12 Input device addressing (Switches)
For Latch
For Latch
13
Figure 13 Addressing using decoder
Microprocessor input / output interfacing use control, status and data input /
output commands.
1. Control command:
action to take.
2. Status command:
Data output / input command is used to transfer data from bus in one of the
shift registers.
14
MEMORY MAPPED I/O
lines are used (A0 – A15), 64K addresses are shared between memory I / O,
memory related instructions are used [LDA XXXX, STA XXXXH] and IO/M’ is
low that is control signals used are MEMR’ and MEMR’ and MEMW’.
For lach;
MVI A,48H,
STA FFF8H
For Buffer;
LDA FFF9H
A = B7H
15
Comparison of memory mapped I/O and I/O mapped I/O
interface device selects the required chip, identifies the required register and
memories, namely Random access memory (RAM) and Read only memory
(ROM).
1. A Read Only Memory reads signals and store programs that do not need
changes. The examples of Read Only Memories are PROM, EPROM and
EEPROM.
to read and writing data in a given register of the chip. To executing any
instruction, the microprocessor must link with the memory to read the data
16
and instruction codes stored in the memory. Both the microprocessor and the
needs matching of the requisite of the memory with the signals of the
microprocessor.
1. Arrange the available chips so as obtain a 16-bit data bus width. The
upper 8-bit bank is known as “odd address memory bank” and the lower 8 bit
the microprocessor and then connect the memor RD and WR input to the
decoding the required chip select signals for the odd and even memory
bit data bus. The control signals go between the two to control the transfer of
17
Figure 15 Microprocessor memory interface (Source: Cheung, 2018)
locations. D7:0 transfer one word (8 bits) of information either to the memory
microprocessor are tri-state (V ): they can be: - “logic 0”, or “high impedance”
(inputs). The control signal informs the memory what activity to perform and
The chip select (CS) helps the microprocessor to select the required chip.
determines which memory chip to enable. This circuit takes the upper bits of
the address bus, and produce enable signals for ROM, RAM, and
INOUTx for a specific I/O device. Normally an I/O device may take up to 4
memory locations.
In this case, INOUTx takes only the address space $F574 - $F577,
A15:2.
18
The ROM CE signal is another challenge. The ROM is enable if the address
A15:A12 falls between the range 4’b1011 and 4’b1110. You should prove for
yourself that the Boolean equation to decode the address for the ROM is as
shown here.
Every memory circuit has a “chip enable” input (CE). The “decoder” utilizes
the top few address bits to make a choice of which memory circuit should be
enabled. Every memory circuit is enabled only for the correct address range
as follows;
ROM = A15 & A14 & ~ (A13 & A12) | (A15 & ~ A14 & A13 & A12)
RAM = ~15
INOUTx = A15 & A14 & A13 & A12& ~A11 & A10 & ~A9 & A8 & ~A7 A6 & A5
& A4 & ~A3 & A2. INOUTX replies to addresses 16F574 TO 16F577, other
I/O circuits will have different addresses. Low n address bits choose one of 2 n
19
Figure 16 Memory chip selection (Source: Cheung, 2018)
1) A clock signal that regulates the timing (may be like the system CLOCK)
or write to memory. Must make sure the d7:0 is only driven at one end.
presume that there is at least two regulating signals from the microprocessor:
20
The memory clock signal, MCLOCK which could be different from the system
clock signal, CLOCK), and a WRITE signal to memory when high and vice
versa.
In Read Cycle the microprocessor declares the address A15:0 and the control
signals MCLOCK and WRITE. Shortly after the commencing of the Read
Cycle, the microprocessor must halt driving of the data bus D7:0, and at the
second half of the cycle, we presuppose that memory will deliver the data for
D7:0 from memory is solitary allowed when MCLOCK & ~WRITE true
21
Memory circuit control signals
This figure indicates the control circuit used to interface the microprocessor to
the 32k x 8 RAM chip. Chip Enable (CE) is run by the output from the
address decoder.
22
Figure 19 microprocessor memory interfacing timing (Source: Cheung, 2018)
presumed to hold its preceding value for at least 3 nanoseconds, but will
transit to the new value after 8 nanoseconds, likewise with the WRITE signal.
1. Place the existing memory chips so that you obtain a number of bit data
bus width. The upper number of bit bank is known as ‘odd address memory
bank’ and the lower number bit bank is known as ‘even address memory
bank’.
2. Attach existing memory address lines of the memory chips to those of the
23
conforming processor control signals. Link the total number of bit data bus of
3. The left over address lines of the microprocessor, BHE and A0 are used for
decoding the needed chip select signals for the even and odd and memory
banks. Chip select (CS) of memory is obtained from the decoding circuit
that is, there should be no windows in the map. A memory ___location must have
one address conforming to it, that is, outright decoding must be anticipated,
and least hardware should be used for decoding. Mostly, linear decoding are
appropriate maps. Upon reset, the IP and CS are set to form address
FFFFOH. So, this address should lie in the EPROM. The address of RAM
could be carefully chosen anywhere in the 1MB address space of 8086, but to
guarantee that the address map of the system is constant you select the
FFFFFH 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
EPROM 8K X 8
FE000H 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
FDFFFH 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1
RAM 8K X 8
FC000H 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Total 8K byte of EPROM takes13 address lines A 0 – A12 (Since 213 =8K. A13
– A19 are utilized for decoding to create the chip select. The BEH signal
24
accessed. Assuming that the latched address BEH and demultiplexed
statistics lines are freely available for interfacing. Figure 20 illustrates the
At this point it has a total four of 4K x 8 memory chips. The 4Kx8 chip ROM
and RAM are organized in parallel to achieve 16-bit data bus breadith. If A 0 is
o, i.e. the address is even and in RAM, then the lower RAM cip is selected
indicating 8-bit transfer at even address. If A 0 is 1, that is, the address is odd
and is in RAM, the BEH changes to low, the upper RAM chip is chosen,
further showing that 8-bit transfer is at an odd address. If the chosen address
are in ROM, the particular ROM chips are chosen. If at a time A 0 and BEH
both are 0, both the RAM and ROM chips are selected that is the data is of 16
25
Figure 20 Memory interfacing (Source: Rayand Bhurchandi, 2006)
and program instructions. The typical 8 bit microprocessor chip has a 16 bit
locations.
A simple case random access memory (ROM) is illustrate in Fig. 21. Here we
have 1024 bytes of ROM interfaced directly to the Z-80. In this situation the
existing are 00 00 (hex) to 03 FF (hex). Since it is dealing with the lower 1K, it
requires only the lower-order byte of the address bus, A O - A7, and two least-
26
Figure 21 ROM Interfacing (Source: Carr, 1982)
It consists of two chip-enable (CE) terminals CE 1 and CE2. The CE2 make
sure that the ROM responds only to address in the lower 1K of memory.
Address-bus bit-AlO at all times remains low when the CPU is addressing a
___location in the lower 1K, but goes high when an address greater than 03 FF
(hex) is chosen. The ROM, therefore, is enabled only when the address on
The second chip-enable pin (CE 1) turns on the ROM only when the
on the ROM when it sees a high. This is because a NOR gate outputs a high
only when both inputs are low. Therefore, by applying the MREQ and RD
control signals from the CPU to the inputs of a NOR gate you create a device-
27
select command for CE 1. The CE1 goes high only when the memory-read
At least two of the more prevalent ROM chips need only a single chip-enable
command.
To carry out the read operation you construct external circuitry that brings the
chip-enable terminal low when you want. The easiest method to attain this is
to utilize a three-input NOR gate and an inverter. The output of the NOR gate
goes high only when all the three of the inputs are low. When the MRE , RD,
and bit A8 of the address bus are connected to the respective inputs of the
NOR gate and the conditions are attained, the output of the gate goes high
An substitute method is illustrated in Fig. 23. Now use two inverters and a pair
of NOR gates to create the CE signal. The idea is to cause CE to go low when
the three conditions are met. To do this, both inputs of NOR-gate 2 must go
bus, as the other is connected to the inverted MWEQ of NOR gate 1. The
28
Figure 22 RAM Interfacing circuit (Source: Carr, 1982)
Note in Fig. 23 that two chips are utilized to form a 256-byte static-RAM. Many
memories need more than a one chip so as to form a whole byte-array. In this
scenario, each memory chip contains a 256 x 4-bit array, so two of them form
a 256 x 8-bit array (i.e., 256 bytes of memory). The prevalent 2102 is listed as
DYNAMIC MEMORY
Dynamic RAM does not keep its data for a long duration of time. It can on
keep data for a long time on when a refresh process is done. The refresh
process is a role of the CPU in most cases, but some non-central processing
units exist. Though the usage of Static RAM eradicates this problem, it
consumes more power. The Z-80A component provides for refresh of the
29
dynamic memory by summing a refresh fragment to the first machine cycle
(instruction fetch).
30
STEPPER MOTOR INTERFACING
position control of rotating shafts. It employs rotation of its shaft in terms of steps,
the stepper motor, a sequence of pulses is needed to be applied to the windings of the
stepper motor, in a proper sequence. The number of pulses required for one complete
rotation of the shaft of the stepper motor is equal to its number of internal teeth on its
rotor. The stator teeth and the rotor teeth lock with each other to fix a position of the
shaft. With a pulse applied to the winding input, the rotor rotates by one teeth position
or an angle x. The angle x may be calculated as: X=3600 /no. of rotor teeth. After the
rotation of the shaft through angel x, the rotor locks itself with the next tooth in the
sequence on the internal surface ofstator. The internal schematic of a typical stepper
The stepper motors have been designed to work with digital circuits. Binary level
pulses of 0-5V are required at its winding inputs to obtain the rotation of shafts. The
31
sequence of the pulses can be decided, depending upon the required motion of the
Fig.3 shows conceptual positioning of the rotor teeth on the surface of rotor, for a six
teeth rotor.
The circuit for interfacing a winding Wn with an I/O port is given in fig.4. Each of the
windings of a stepper motor needs this circuit for its interfacing with the output port.
A typical stepper motor may have parameters like torque 3 Kg-cm, operating voltage
12V, current rating 0.2 A and a step angle 1.80 i.e. 200 steps/revolution (number of
rotor teeth).
A simple schematic for rotating the shaft of a stepper motor is called a wave scheme.
In this scheme, the windings Wa, Wb, Wc and Wd are applied with the required
32
direction of rotation of the stepper motor shaft may be reversed. Table.1 shows the
scheme for rotation of a stepper motor shaft applies pulses to two successive windings
at a time but these are shifted only by one position at a time. This scheme for rotation
33
ASSEBLY LANGUAGE PROGRAMS
ASSEMBLY PROGRAMME FOR RUNNING A SEVEN SEGMENT
INTERFACED WITH SEVEN SEGMENT DISPLAY
34
ASSEMBLY PROGRAM FOR RUNNING A STEPPER MOTOR IN HALF
STEPS
35
ASSEMBLY LANGUAGE PROGRAM FOR RUNNING A STEPPER MOTOR
IN FULL STEPS
36
PROGRAM FOR STEPPER MOTOR ROTATION
37
38
ASSEMBLY LANGUAGE PROGRAM FOR INTERFACING A MATRIX
KEYBOARD
39
KEYBOARD INTERFACING CMD (COMMAND PROMPT)
PROGRAM
The desktop computer is turned ON and start option is clicked and CMD (command
prompt) is selected. In order to enter the editor window for writing the program the
following steps are performed.
40
41
AN ASSEBLY LANGUAGE PROGRAM FOR ROTATING A
STEPPER MOTOR CLOCKWISE WHEN INTERFACED WITH A
8086 MICROPROCESSOR
42