Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 71

Microprocessor Systems and

Interfacing

Dr. Naeem Shehzad


Intel 8255 Programmable Peripheral
Interface (PPI)
 PPI 8255 is a general purpose programmable I/O
device designed to interface the CPU with its
outside world such as ADC, DAC, keyboard etc.
 Programmable. It can be programmed to work as different
capacities at different times
 Peripheral. It is used along with Input output devices
 Interface. It is used as for connecting the microprocessor to
another device

It can be used with almost any microprocessor.

1/20/23 2
Motivation

Data is latched and remains here until the next


OUT instruction to this port is executed

1/20/23 3
REVISIT I/O Application in previous Lecture

Pull-up
Resistors To mP
Gate

0 1
Toggle switches

1/20/23 4
REVISIT I/O Application in previous Lecture

Pull-up
Resistors To mP
Gate

0 1
Toggle switches

1/20/23 5
Interfacing Bidirectional I/O Port

1/20/23 6
Intel 8255 PPI
 The 8255 allows the microprocessor to communicate
with the outside world through three programmable
8-bit wide I/O ports
 The PC uses a few 82C55 (in the chip set) to control
the keyboard, speaker, and parallel port

 The 8255 PPI is available in DIP or surface mount


forms
 Also implemented as functions within modern
interface chip sets

1/20/23 7
8255 PPI Pinout
D0 PA0
. .
.
.
. . . .
. . . .
D7 PA7
PB0 .
WR
.
. .
RD
. .
CS PB7

RESET PC0
.
.
. .
A1
A0 . .
PC7

8255 PPI
1/20/23 8
Important pins of PPI

1/20/23 9
8255 PPI Pinout
3 programmable
8-bit I/O ports: A, B, C

2 Groups
12-bit groups A, B
Data Bus A

2-bit Address I/P Port A + Upper half of C = Group A


(select port or (12 bits)
Command register
for Read or Write)
Read/Write B
Control Port B + lower half of C = Group B
(12 bits)
On the PC: Two 82C55s CS
- One 82C55 occupies Input
(low)
4 I/O ports 60H-63H:
Handling Keyboard, timer, C RESET initializes the PPI to operat
speaker, etc. in mode 0 & all 3 ports as inputs
at power up.
- One 82C55 occupies
4 I/O ports 378H-37BH
Parallel printer port 82C55 DIP Version
1/20/23 10
PPI Address Inputs

A1 A0 Function

0 0 PortA Selected

0 1 PortB Selected

1 0 PortC Selected

1 1 Control Word
Selected

1/20/23 11
Block Diagram of PPI

1/20/23 12
Complete the table and specify functions

A1 A0 RD WR CS

1/20/23 13
Interfacing with 8088 CPU

D0 D0 PA0
CPU . . .
.
data . . .
.
bus . . .
.
D7 D7 PA7

WR’ WR PB0
.
A2 CPU .
CPU Address bus

lines .
A3 RD’ RD .
.
A4 .
CS PB7
A5
A6 RESET RESET PC0 .
A7 CPU . .
A1 A1
IO/M’ Address . .
lines .
A0 A0
PC7

8255 PPI

1/20/23 14
82C55 connected to the 80386SX so that it functions at 8-bit I/O port
addresses C0H (port A), C2H (port B), C4H (port C), and C6H
(command register).

1/20/23 15
Example
Draw a diagram to connect 82C55 to a 8088 so that it
functions at 8-bit I/O port addresses 80H (port A), 82H
(port B), 84H (port C), and 86H (command register).

1/20/23 16
Example
Draw a decoder circuit to connect 82C55 to a 8088
such that it functions at 8-bit I/O port addresses A0H
(port A), A1H (port B), A2H (port C), and A3H
(command register).

1/20/23 17
Control Word Register

Group A lines Group B lines

7 6 5 4 3 2 1 0

PortC
Modes (PC3...PC0) I/O

PortA I/O PortB I/O


PortC
(PC7...PC4) I/O Modes

1/20/23 18
Control Word Register
 82C55 is programmed through its control register,
command Byte A or command Byte B

 Bit at position 7 selects either command Byte A or


command Byte B

 Command byte A programs the function of group A and B,

 Command byte B sets (1) or resets (0) bits of port C only if


the 82C55 is programmed in mode 1 or 2.
 In this mode only port C bits are used for set or reset.

1/20/23 19
Control Word Register

1/20/23 20
Groups of PPI Lines
 Group A consists on eight pins of PortA and upper four
pins of PortC (PC4 to PC7)

 Group B consists on eight pins of PortB and lower four


pins of PortC (PC0 to PC3)

 Direction is selected through programming an 8-bit


‘control word’ register

1/20/23 21
8255 Modes
 Mode 0 (for groups A & B)- the most commonly used mode:
All 12 bits of the group are simple inputs or simple
latched outputs Data
Data
 Mode 1 (for groups A & B)- is used occasionally to provide
handshaking to an I/O device and operate asynchronously with
the device. Most Port C bits are dedicated for handshake
functions for the operation. A few are controlled separately
using the Command byte B format for handshaking I/O.
Data
Control, e.g. Busy,
Strobe, etc.
 Mode 2 (for group A only- Group B not used)- is a bidirectional
mode for Port A only (Port B is not used). Port C provides
handshaking signals.
Group I/O mode
 Deals with Group A and Group B I/O
 Activated with placing logic 1 in bit7 of control word
register
 FOR PORT A
 All the lines of Port A can be configured either input or
output
 For group A, all the four lines of Port C (PC7…PC4) can be
configured either input or output
 FOR PORT B
 All the lines of Port B can be configured either input or
output
 For group B, all the four lines of Port C (PC3…PC0) can be
configured either input or output
1/20/23 23
Mode 0: Basic I/O mode

 Mode 0, called the basic I/O mode, configures I/O lines


as ‘buffered inputs’ or ‘latched outputs’

1/20/23 24
Examples of configuring Basic I/O mode
 Configure all lines of Group A as ‘input’ and all lines
of Group B as ‘output’.
 Configure PortA as ‘input’, PortB as ‘output’ and
PortC as ‘output’
 In Group A, configure PortA as ‘output’, and PortC as
‘input’
 In Group B, configure PortB as ‘input’, and PortC as
‘output’

1/20/23 25
Bit-select mode
 Activated by placing logic 0 in bit7 of control word
register
 Selects direction of individual bit of PortC

0 X X X

Don’t care Direction

Bit
selection

1/20/23 26
Programming the 82C55
 To program the command
register of the 82C55 and select
operation use command byte A
 For example, to program all the
ports as outputs and in mode 0
(the most common mode) use:
MOV AL,80H
MOV DX,COMMAND_PORT
OUT DX,AL
Programming the 82C55
 Example. Program Command
Register of 82C55 such that
port A acts as input and port B
acts as output port.

 Command Byte A
 1001 X00X
Mode 0 Application: 7-Segement Display

Segment
Driver Common
7-Segement Display
CA  Vcc

Anode

Cathode
Select Segments: Switched Resistors to GND

CC
Select Segments: Switched Resistors to Vcc

 GND
7-Segement Display

Anode

Cathode

Segment Data (1 byte)


for each character
Multiplexed 7-Segement Display
Common
To segment
on all Digits

n=8
Digits

Sequentially
Turn ON one digit at a time

Recommended rate: 100 – 1500 times per sec


Multiplexed 7-Segement Display
Multiplexed 7-Segement Display
1 turns
segment ON
A: O/P Port:
Segment data Tr 1 Significan
Most
For selected digit Tr 2
(MS) Digit
Multiplex the eight digit displays
(only one is ON at a time)

0 turns digit
B: O/P Port: digit ON Vcc
Select # Displayed
B: O/P Port: 1 digit
Select digit . . . . . .
GND
To be displayed
Programming Part
Set the PORT A and PORT B as output ports
Programming Part
The procedure to multiplex the displays is listed in assembly language
; Program the 82C55 for Port A and Port B are output ports in mode 0
MOV AL, 80H ; 80H Data into AL
MOV DX, 703H ; Address of Command Port into DX 8 bytes of
OUT DX, AL ; Write 80H into Command Port
; ; to program PPI Digit Data
; An assembly language procedure that multiplexes the 8-digit display.
MEM+7 In memory
MS Digit
; This procedure must be called often enough for the display to appear stable .
DISPPROC NEAR USES AX BX DX SI .
PUSHF BX
MOV BX,8 ;load counter BX with # of display digits .
MEM LS Digit
MOV AH,7FH ;load initial digit selection pattern to enable MS digit (01111111)
MOV SI,OFFSET MEM - 1 ;Load SI with offset (MEM) - 1
MOV DX,701H ;address Port B (for Port A: decrement DX)
;Sequentially display all 8 digits starting with MS digit
.REPEAT
MOV AL,AH
OUT DX,AL ;send digit selection pattern to Port B
DEC DX ;Address Port A (to send Digit Data)
MOV AL,[BX+SI] ;Load digit data from memory into AL
OUT DX,AL ;send digit data to Port A
CALL DELAY ;wait 1.0 ms leaving displayed digit ON
ROR AH,1 ;adjust selection pattern to point to next digit
INC DX ;Address port B
DEC BX ;decrement counter for data of next digit.
.UNTIL BX == 0
POPF
Procedure for 1 ms delay, e.g. a loop of instruc
RET i.e. digit remains ON for 1 ms before moving to
DISPENDP
Delay
Interfacing of LCD using PPI
44780 LCD Controller
 Controls alphanumeric printing
on LCD
 Has 8-bit and 4-bit interface

 Single controller can control one

16x2 character LCD


 Takes ASCII codes as input for

characters to be printed

41
Interfacing of LCD using PPI
LCD Pin Description
 Pin No  Function  Name
1 Ground (0V) Ground
2 Supply voltage; 5V (4.7V – 5.3V)  Vcc
3 Contrast adjustment; through a variable resistor  VEE
4 Selects command register when low; and data register Register
when high Select
5 Low to write to the register; High to read from the register Read/write

6 Sends data to data pins when a high to low pulse is given Enable

7 DB0
8 DB1
9 DB2
10 DB3
8-bit data pins
11 DB4
12 DB5
13 DB6
14 DB7
15 Backlight VCC (5V) Led+
16 Backlight Ground (0V) Led-

1/20/23 43
LCD PPI Interfacing

1/20/23 44
LCD PPI Interfacing

The DMC-20481 is a 4-line by 20-characters-per-line display


that accepts ASCII code as input data.

1/20/23 45
LCD PPI Interfacing
This illustrates an 8-bit interface. If a 4-bit interface is
desired, D4–D7 pins are used for the data where the data
must be formatted with the high nibble first, followed by the
low nibble.

Control pins
• RS (register select) input selects data (RS = 0) or
instructions (RS = 1).

• The E (enable) input must be a logic 1 for the DMC-20481


to read or write information and functions as a clock

• R/W pin selects a read or a write operation

1/20/23 46
LCD PPI Interfacing
In order to program the DMC-20481 we must first initialize it.
Initialization is accomplished via the following steps:

1. Wait at least 15 ms after VCC rises to 5.0 V.


2. Output the function set command (30H), and wait at least 4.1 ms.
3. Output the function set command (30H) a second time, and wait at
least 100 μs.
4. Output the function set command (30H) a third time, and wait at least
40 μs.
5. Output the function set command (38H) a fourth time, and wait at least
40 μs.
6. Output 08H to disable the display, and wait at least 40 μs.
7. Output a 01H to home the cursor and clear the display, and wait at
least 1.64 ms.
8. Output the enable display cursor off (0CH), and wait at least 40 μs.
9. Output 06H to select auto-increment, shift the cursor, and wait at least
40 μs.

1/20/23 47
LCD PPI Interfacing

1/20/23 48
LCD PPI Interfacing

1/20/23 49
LCD PPI Interfacing

1/20/23 50
LCD PPI Interfacing (Practice)

1/20/23 51
LCD PPI Interfacing (Practice)
Write a program to clear the display

PORTA_ADDRESS EQU 210H ;set port addresses


PORTB_ADDRESS EQU 211H
COMMAND_ADDRESS EQU 213H

MOV AL,80H ;Program the 82C55


MOV DX,COMMAND_ADDRESS
OUT DX,AL

MOV DX,PORTB_ADDRESS ;Clear Port B


SEND 01H, 0, 16

1/20/23 52
LCD PPI Interfacing (Writing)
Write a program for following interfacing to write an ASCII
character to LCD

1/20/23 53
LCD PPI Interfacing (Writing)

1/20/23 54
LCD PPI Interfacing (Busy)

1/20/23 55
Motor Interfacing using PPI
• What is A motor?

• An electric motor is an electrical machine that converts


electrical energy into mechanical energy.
• Most electric motors operate through the interaction
between the motor's magnetic field and electric current in
a wire winding to generate force in the form of torque
applied on the motor's shaft.

1/20/23 56
Motor Interfacing using PPI

1/20/23 57
Motor Interfacing using PPI

• Electric Car
• Fans
• Pumps
• Rolling machine
• Electric Cars
• Robotic arms

1/20/23 58
Stepper Motor Interfacing using
PPI
• Stepper motors are DC motors that move in discrete steps
• It rotates in a sequence of discrete steps controlled by sequentially
energizing a set of coils (windings)

• A common stepper motor is geared to move perhaps 15° per step in


an inexpensive stepper motor, to 1° per step in a more costly, high-
precision stepper motor

• The stepper motor is used for precise positioning with a motor, such


as hard disk drives, robotics, antennas, plotters, and some toys

1/20/23 59
Stepper Motor Interfacing using
PPI

1/20/23 60
Stepper Motor Interfacing using
PPI

1/20/23 61
Stepper Motor Interfacing using
PPI

1/20/23 62
Stepper Motor Interfacing using PPI (Full Step
Operation)

1/20/23 63
Stepper Motor Interfacing using PPI (Full Step
Operation)
A B C D STEP

0 0 0 1 90

0 0 1 0 90

0 1 0 0 90

1 0 0 0 90

0 0 0 1 90

1/20/23 64
Stepper Motor Interfacing using PPI (Full Step
Operation)
A B C D STEP

0 0 1 1 90

0 1 1 0 90

1 1 0 0 90

1 0 0 1 90

0 0 1 1 90

1/20/23 65
Stepper Motor Interfacing using PPI (Half Step Operation)
A B C D STEP

0 0 1 1 45

0 0 1 0 45

0 1 1 0 45

0 1 0 0 45

1 1 0 0 45

1 0 0 0 45

1 0 0 1 45

0 0 0 1 45

1/20/23 66
Stepper Motor Interfacing using PPI (Full Step
Operation) Darlington pairs
for driving
high load currents

1/20/23 67
Stepper Motor Interfacing using PPI

1/20/23 68
Stepper Motor Interfacing using PPI (Full Step
Operation)

33H = 00110011
66H = 01100110
CCH = 11001100
CX Positive: Rotate Anti-clockwise
99H = 10011001
Anti-Clockwise Clockwise
ROL ROR

POS 33H or 66H or CCH or 99H

1/20/23 69
Stepper Motor Interfacing EXAMPLE 1

Write a code that enables the interfacing of stepper motor


with 8088 processor via PPI such that:
• The code should allow the movement in 90-degree step
with single phase excitation

1/20/23 70
Stepper Motor Interfacing EXAMPLE 2

Write a code that enables the interfacing of stepper motor


with 8088 processor via PPI such that:
• The code should allow the movement in 45-degree step

1/20/23 71

You might also like