You are on page 1of 19

Chapter 12

Parallel Interfacing
Expected Outcomes
Identify the internal registers of MC6821
Design the hardware interface for various I/O devices using MC6821
Develop and write codes using MC6821

NMKNYFKEEUMP
Parallel Interface/Timer
I/O interface using a simple I/O device such as latch or buffer has
its drawbacks
One of them is the circuit design must be reconstructed if a user
decide to change its I/O devices
A dedicated peripheral such as the 68230 (PI/T - Parallel
Interface/Timer)
Its primary function is to provide parallel interface
Its secondary function is a programmable timer
It provides 4 modes of operation with various handshaking and
buffering capabilities
Unidirectional 8-bits
Unidirectional 16-bits
Bidirectional 8-bits
Bidirectional 16-bits

NMKNYFKEEUMP
Parallel Interface/Timer
The programmable timer provides a variety of services
Periodic interrupt generation
Square wave generator
Interrupt after time-out
Elapse time measurement
System watchdog
Since, it is part of 68xxx family, the PI/T is expensive due to its
capability to provide wider functions
A simple 8-bit family can be used in certain cases to provide
parallel I/O interface
PIA 6821 peripheral interface adapter is introduced to give
flexibility in I/O system

NMKNYFKEEUMP
PIA 6821
PIA was initially designed for use in 6800-based system
However, it is widely used in 68000-based system due its flexibility
and cost
Since it is part of 6800 family, additional pin connections are
needed to operate in asynchronous mode
The port A and B may be programmed individually to be an
input or an output – allowing the software to adjust to a new
system requirement
Additional signal lines may be programmed to allow interrupts
and strobe signals for each port
Internal register to allow storage of data temporary thus allowing
to interface with a slower devices such as printer

NMKNYFKEEUMP
Each individual signal line (PA0 through PA7 and PB0 through PB7)
PIA has two port with each port may drive two TTL loads

Vss 1 40 CA1
PA0 2 39 CA2
PA1 3 38 IRQA*
4 37 IRQB*
can be programmed as an input or an output

PA2
PA3 5 36 RS0
PA4 6 35 RS1
PA5 7 34 RESET*
PA6 8 33 D0
PA7 9 32 D1
PB0 10 31 D2
6821

NMKNYFKEEUMP
PB1 11 30 D3
PB2 12 29 D4
PB3 13 28 D5
PB4 14 27 D6
PB5 15 26 D7
PB6 16 25 E
PB7 17 24 CS1
CB1 18 23 CS2*
CB2 19 22 CS0
Vcc 20 21 R/W*
PIA 6821
PIA 6821
PIA has 6 internal registers that can be programmed to its need
Each port has three registers

For Port A For Port B


Data Register A (DRA) Data Register B(DRB)
To transfer data in or out To transfer data in or out
Data Direction Register A (DDRA) Data Direction Register B (DDRB)
Determine direction of each line Determine direction of each line
Control Register A (CRA) Control Register A (CRB)
Control the operation of port A Control the operation of port B

NMKNYFKEEUMP
PIA 6821
Internal structure of PIA consist of six registers and control unit

PA0
PA1
PA2
IRQA Data Direction Control Register PA3
IRQB Register A (DDRA) A (CRA) PA4
PA5
PA6
D7-D0 PA7
Data Register
A (DRA) CA1
RS0 Control CA2
RS1 Unit PB0
E Control Register PB1
R/W B (CRB) PB2
CS0 PB3
CS1 PB4
CS2 Data Register PB5
Data Direction
Register B (DDRB) B (DRB) PB6
RESET
PB7
CB1
CB1

NMKNYFKEEUMP
Interface With 68000
Since 6821 is operating in synchronous mode, additional pin
connections are required
68000 6821

PA7
PA6
RESET RESET
PA5
A0 RS0 PA4
A1 RS1 PA3
PA2
PA1
PA0
CA1
Address CA2
A3-A23 Decoder PB7
PB6
PB5
VPA* PB4
R/W* PB3
R/W*
E PB2
E
PB1
UDS* CS1 PB0
CB1
VMA* CS2 CB2

NMKNYFKEEUMP
PIA Registers
The address of 6 internal registers of PIA depends on
Address decoder
Data Strobe connection (UDS or LDS)

N DDRA/DRA N+1
A2 RS1
A1 RS0 CRA
N+2 N+3
LDS* CS1 N+4 DDRB/DRB N+5

N+6 CRB N+7

N DDRA/DRA N+1
A2 RS1
A1 RS0 CRA
N+2 N+3
UDS* CS1 N+4 DDRB/DRB N+5

N+6 CRB N+7

NMKNYFKEEUMP
PIA Registers

RS1 RS1 Register


Since there is 6 registers 0 0 Data Register A/Data Direction Reg. A
and only four locations,
two registers are located 0 1 Control Register A

in the same address 1 0 Data Register B/Data Direction Reg. B

1 1 Control Register B

To distinguish these RS1 RS0 CRA2 CRB2 Register


registers, bit2 of control 0 0 0 X Data Direction Reg. A (DDRA)
register is used 0 0 1 X Data Register A (DRA)
0 1 X X Control Register A (CRA)
1 0 X 0 Data Direction Reg. B (DDRB)
1 0 X 1 Data Register B (DRB)
1 1 X X Control Register B (CRB)

NMKNYFKEEUMP
PIA Registers
Data Register A (DRA)
bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0

DRA7 DRA6 DRA5 DRA4 DRA3 DRA2 DRA1 DDRA0

Data Direction Register A (DDRA)


bit7 bit6 bit5 bit4 bit3 bit2 bit1 bit0

DDRA7 DDRA6 DDRA5 DDRA4 DDRA3 DDRA2 DDRA1 DDRA0

Logic 1 in each DDRAi causes the signal line PAi to become output line
Logic 0 in each DDRAi causes the signal line PAi to become input line

For example:
If DDRA = $4C, PA6, PA3 and PA2 are output and others are input

NMKNYFKEEUMP
Control Register

CRA7 CRA6 CRA5 CRA4 CRA3 CRA2 CRA1 CRA0

DDRA/
IRQA IRQB CA2 CA2 CA2 CA1 CA1
DRA

Set if transition in CA1 0: IRQA disabled


Refer to data sheet 1: IRQA is activated
Set if transition in CA2 for complete
information
0: CA2 is input 0: CA1 is recognized on
1: CA2 is output positive -to negative
transition
If CRA5=0, CRA3 & CRA4
follow 1: CA1 is recognized on
positive -to negative
transition

0: DDRA is chosen
1: DRA is chosen

NMKNYFKEEUMP
Initialize PIA
Initializing PIA is the most crucial steps in
programming a system using this I/O device Set CRx2=1

Followings are brief procedure to initialize PIA for


simple I/O (Assuming port A)
Fill bit 2 of CRA with 0 to access DDRA Set direction

Fill DDRA with proper value to determine the (DDRx)

role of each signal line of the port A (1 for output


and 0 for input)
Fill bit 2 of CRA with 1 to access DRA Set CRx2=0

Write or read data using DRA

Read/Write
Data to DRx

NMKNYFKEEUMP
Initialize PIA
Example : Initialize PIA assuming port A is an output port and port
B is an input port

; Initialize Port A
MOVE.B #0,CRA
MOVE.B #$FF,DDRA
MOVE.B #4,CRA

; Initialize Port B
MOVE.B #0,CRB
MOVE.B #0,DDRB
MOVE.B #4,CRB

NMKNYFKEEUMP
More Examples..

Write a program to switch on the +5V

LED as the respective switch is


pressed assuming all ports are
2K2
PB0 PA0
330R

initialized
2K2
PB1 PA1
330R

2K2
PB2 PA2
330R

2K2
PB3 PA3
START MOVE.B DRA,D0 330R

PB4 PA4
2K2

330R

NOT.B D0 330R
PB5 PA5
2K2

MOVE.B DRB 330R


PB6 PA6
2K2

BRA START
2K2
PB7 PA7
330R

NMKNYFKEEUMP
More Examples..
Write a program to display a +5V

pressed number on seven


segment display
2K2
PA0

2K2
PA1

2K2

CLR.B CRA PA2

2K2

MOVE.B #$F0,DDRA PA3

MOVE.B #4,CRA PA4 A a


b
a

c
LOOP MOVE.B DRA,D0 PA5 B d
f
g
b

7448 e
ASL.B #4,D0 PA6 C
g
f e
d
c

MOVE.B D0,DRA dp dp
PA7 D

BRA LOOP

NMKNYFKEEUMP
More Examples..
Write a program to display an +5V

upward counter (0,1,2..8,9,0…)


continuously
2K2
PA0

2K2
PA1

2K2

MAIN CLR.B D0 PA2

2K2

LOOP MOVE.B D0,DRA PA3

BSR DELAY PA4 A a


b
a

c
ADDQ.B #1,D0 PA5 B d
7448 e
f
g
b

CMPI.B #10,D0 PA6 C


g
f e
d
c

dp dp
BNE LOOP PA7 D

BRA MAIN

NMKNYFKEEUMP
Self-Test
Exercise
Write as simple program to initialize port A where PA0-PA3 are output
and PA4-PA7 are input
Exercise
If port B is connected to 7-segment display, write a program to
initialize port B. Then, write a program to display downward counter
on port B
Exercise
If PB0 is connected to a low current speaker, write a program to
generate continuous tone with frequency of 1kHz to the speaker

NMKNYFKEEUMP
Self-Test
Exercise
Write a program to meet
+5V

following requirements, PA0


2K2

If switch 1 is pressed, the 2K2

segment will display upward


PA1

counter
2K2
PA2

If switch 2 is pressed, the


2K2
PA3

segment will display downward PA4 A a

counter
a
b
c f b
PA5 B d g

If switch 3 is pressed, the 7448 e

segment will display random


PA6 C f e c
d
g
dp

value continuously
dp
PA7 D

If switch 4 is pressed, the


program is terminated

NMKNYFKEEUMP