Professional Documents
Culture Documents
Memory
CS*
MAD
M68k
(LED, Switches, Motor,
7-Segment, Keypad, etc.)
CS*
Port A Device #1
Data Bus
M68230 Port B Device #2
Port C Device #3
How M68230 connects to M68k
D0-D7 D0-D7 PA0-PA7
DTACK* DTACK*
PB0-PB7
R/W* R/W*
CLK CLK
PC0-PC7
RESET* RESET*
A6-A23
MAD CS*
M68k M68230
M68230 Ports
Registers in M68230
M68230 contains 23 registers.
Each of the registers have a unique address that
refers to them.
To initialize ports, some registers need to be
configured.
Port General Control Register.
Port X Control Register (A, B).
Port X Data Direction Register (A, B, C).
Port X Data Register (A, B, C).
PGCR
Port General Control Register.
Used to set the operation of Port A & Port
B.
You only need to know (and use) Mode 0.
MOVE.B #$00,PGCR
PGCR Settings
A23 A22 A21 A20 A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
X X X X X
5 lines allocated
UDS/LDS
(reserved)
Step 2: Set Base Address
A23 A22 A21 A20 A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 X X X X X
A 5 0 0
UDS/LDS
(reserved)
Step 3: Find Lower Range
A23 A22 A21 A20 A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
A 5 0 0 0 0
Step 4: Find Upper Range
A23 A22 A21 A20 A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0
1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1
A 5 0 0 3 F
Step 5: Design Decoder
A23 A22 A21 A20 A19 A18 A17 A16 A15 A14 A13 A12 A11 A10 A9 A8 A7 A6
1 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0
A 5 0 0
SELIO*
NAND
NAND
NAND
A23 A16 A15 A8 A7 A6 AS*
Memory Block Diagram
$000000
unused
unused
$FFFFFF
Sample Programs
LEDs & Switches
Example 1
Example 1: Set LED
M68230
A set of LEDs are connected to LED0
PB0
Port B in M68230. Write a program
that turns on LED3 and LED4, and PB1 LED1
turns off the rest.
PB2 LED2
Port Address
PGCR $800001
PB3 LED3
PACR $800005
PB4 LED4
PBCR $800007
A B
A B LED
END START
Example 1: Set LED
M68230
0 LED0
PB0
PB1 0 LED1
0 LED2
PB2
PB3 1 LED3
1 LED4
PB4
0 LED5
PB5
0 LED6
PB6
0 LED7
PB7
Example 2
Example 2: Read Switches &
Output to LED
A set of switches are connected to Port A,
and a set of LEDs are connected to Port B
in M68230. Write a program that reads
the value in the switches and turns on the
respective LEDs.
Switch Operation
+5V
Switch A
OPEN 0
A CLOSE 1
R
Switch Operation
+5V
R
Switch A
A
OPEN 1
CLOSE 0
Circuit Diagram
+5V
M68230
LED0
PA0 PB0
R
END START
Sample Output
+5V
M68230
0 LED0
PA0 PB0
R
PADR D0 PBDR
7-Segment
7-Segment
Consists of 7-LEDs
arranged together.
Can display numbers and
characters.
Each segment is marked
with a letter (a to g).
To display characters,
need to turn on/off certain
segments.
Also has E (enable) pin to
turn on/off 7-segment.
Interfacing 7-Segment with M68230
E Input Output
0 0 OFF
0 1 ON
1 0 OFF
1 1 ON
Example: Interfacing CC 7-Segment
with M68230 (No Transistor)
a
M68230 B0
b
B1
c
B2
B3 d
B4 e
B5 f
B6 g
B7 E
(Common cathode)
B3 d
B4 e
B5 f
B6 g
B7
E
(Common cathode)
To turn on the 7-segment, R
E must be set to 1,
and the input to be turned on
must be set to 1.
By setting E to 1, the transistor is
turned ON, providing a
path to GND.
Displaying Numbers: CC7S (No Transistor)
E a b c d e f g Number
1 X X X X X X X None
0 1 1 0 0 0 0 0 1
0 1 1 0 1 1 0 1 2
0 1 1 1 1 0 0 1 3
0 0 1 1 0 0 1 1 4
0 1 0 1 1 0 1 1 5
0 0 0 1 1 1 1 1 6
0 1 1 1 0 0 0 0 7
0 1 1 1 1 1 1 1 8
0 1 1 1 0 0 1 1 9
0 1 1 1 1 1 1 0 0
Displaying Numbers: CC7S (with Transistor)
E a b c d e f g Number
0 X X X X X X X None
1 1 1 0 0 0 0 0 1
1 1 1 0 1 1 0 1 2
1 1 1 1 1 0 0 1 3
1 0 1 1 0 0 1 1 4
1 1 0 1 1 0 1 1 5
1 0 0 1 1 1 1 1 6
1 1 1 1 0 0 0 0 7
1 1 1 1 1 1 1 1 8
1 1 1 1 0 0 1 1 9
1 1 1 1 1 1 1 0 0
Common Anode 7-Segment
E
E Input Output
0 0 OFF
0 1 OFF
1 0 ON
1 1 OFF
Example: Interfacing CA 7-Segment
with M68230
a
M68230 B0
b
B1
c
B2
B3 d
B4 e
B5 f
B6 g
B7 E
(Common anode)
B3 d=1
B4 e=1
B5 f=1
B6 g=0
B7
E=1
(Common cathode)
R
MOVE.B #$00,PGCR
MOVE.B #$80,PBCR
MOVE.B #$FF,PBDDR
ULANG MOVE.B #$B9,PBDR
BRA ULANG
Displaying More Numbers/Characters
B3 d d
B4 e e
B5 f f
B6 g g
B7
(Common cathode)
E1
A0
A1
E2
Example 2
Example: Displaying on Multiple 7-Segs
B3 d d
B4 e e
B5 f f
B6 g g
B7
(Common cathode)
E1
A0
A1
E2
Step 1: Init Ports
MOVE.B #$00,PGCR
MOVE.B #$80,PACR
MOVE.B #$80,PBCR
MOVE.B #$FF,PADDR
MOVE.B #$FF,PBDDR
Step 2: Activate E2, Send First Number
B3=1
d d
B4=1
e OFF e
B5=0
f f
B6=1
g g
B7
(Common cathode)
E1 = 1 (off)
A0
A1
E2 = 0 (on)
M68230
Step 2: Activate E1, Send Second Number
B3=0
d d
B4=0
e e OFF
B5=0
f f
B6=0
g g
B7
(Common cathode)
E1 = 0 (on)
A0
A1
E2 = 1 (off)
M68230
Step 3: Activate E2 Back, Send First Number
Again
B3=1
d d
B4=1
e OFF e
B5=0
f f
B6=1
g g
B7
(Common cathode)
E1 = 0 (off)
A0
A1
E2 = 1 (on)
M68230
Discussion
Using multiplexing, only one digit may be
turned on at one time.
But, if the delay is fast enough (<100ms),
our eyes wont be able to catch the
change.
Example: Displaying 12 on 2 7-Segments
a a
M68230 B0
b b
B1
c c
B2
B3 d d
B4 e e
B5 f f
B6 g g
B7
(Common cathode)
E1
A0
A1
E2
Complete Program
ORG $080C00
INIT MOVE.B #$00,PGCR
DELAY MOVE.L #50,D7 MOVE.B #$80,PACR
DELLOOP SUB.L #1,D7 MOVE.B #$80,PBCR
CMP.L #0,D7 MOVE.B #$03,PADDR
BNE DELLOOP MOVE.B #$7F,PBDDR
RTS
BEGIN MOVE.B #$01,PADR
MOVE.B #$5B,PBDR
START ORG $080D00 BSR DELAY
B6 g g
B7
(Common cathode)
E1
A0
A1
E2
BCD Decoder I/O
B3 B2 B1 B0 Number
0 0 0 1 1
0 0 1 0 2
0 0 1 1 3
0 1 0 0 4
0 1 0 1 5
0 1 1 0 6
0 1 1 1 7
1 0 0 0 8
1 0 0 1 9
0 0 0 0 0
Example 3
Displaying 12 on 7-Segments
A circuit is wired as in the next figure.
Write a program that displays 12 on the
7-Segment.
Example: 7-Segment + BCD
Decoder
a a
M68230 B0
b b
B1
c c
B2
BCD
B3 d d
7-Seg
e e
B4 Decoder
B5 f f
B6 g g
B7
(Common cathode)
E1
A0
A1
E2
Step 1: Init Ports
MOVE.B #$00,PGCR
MOVE.B #$80,PACR
MOVE.B #$80,PBCR
MOVE.B #$FF,PADDR
MOVE.B #$FF,PBDDR
Step 2: Activate E2, Send First Number
(Common cathode)
E1 = 1 (off)
A0
A1
E2 = 0 (on)
M68230
Step 2: Activate E1, Send Second Number
(Common cathode)
E1 = 0 (on)
A0
A1
E2 = 1 (off)
M68230
Step 4: Activate E2 Back, Send First Number
Again
(Common cathode)
E1 = 1 (off)
A0
A1
E2 = 0 (on)
M68230
Discussion
Using multiplexing, only one digit may be
turned on at one time.
But, if the delay is fast enough (<100ms),
our eyes wont be able to catch the
change.
Example: Displaying 12 on 2 7-Segments
a a
M68230 B0
b b
B1
c c
B2
BCD
B3 d d
7-Seg
e e
B4 Decoder
B5 f f
B6 g g
B7
(Common cathode)
E1
A0
A1
E2
Complete Program
ORG $080C00
INIT MOVE.B #$00,PGCR
DELAY MOVE.L #50,D7 MOVE.B #$80,PACR
DELLOOP SUB.L #1,D7
CMP.L #0,D7 MOVE.B #$80,PBCR
BNE DELLOOP MOVE.B #$FF,PADDR
RTS MOVE.B #$FF,PBDDR
BEGIN MOVE.B #$01,PADR
MOVE.B #$02,PBDR
START ORG $080D00 BSR DELAY
MOVE.B #$02,PADR
PGCR EQU $100001 MOVE.B #$01,PBDR
PADDR EQU $100005 BSR DELAY
PBDDR EQU $100007 BRA BEGIN
PCDDR EQU $100009
PADR EQU $100011 END START
PBDR EQU $100013
PCDR EQU $100019
PACR EQU $10000D
PBCR EQU $10000F
DC Motor
Controlling DC Motors
Has two terminals (positive/negative),
connected to DC voltage.
If positive voltage applied at positive
terminal, motor moves clockwise.
If negative voltage applied at positive
terminal, motor moves anti-clockwise.
DC Motor
+12V +12V
+ - + -
M68230
R
A0
+
A1
A2 - MOVE.B #$00,PGCR
A3 R MOVE.B #$80,PACR
A4
MOVE.B #$FF,PADDR
MOVE.B #$10,PADR
A5
A6
R
A7
Interfacing DC Motor with M68230 (Two Directions)
+12V
R
R
R R
T1 T2
A0 A2
+
-
R R
A1 T4 T3 A3
+12V
R
R
0 1 R R 0 1
T1 T2
A0 A2
+
1 0 R R 1 0
A1 T4 T3 A3
+12V
R
R
1 0 R R
1 0
T1 T2
A0 A2
+
0 1 R R 0 1
A1 T4 T3 A3
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 1: Initialization
Lets say Port A is connected to keypad.
MOVE.B #$00,PGCR
MOVE.B #$80,PACR
MOVE.B #$0F,PADDR
Step 2 Scan 1st Column
P0=1 P1 P2
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 2: Scan 1st Column
COL1 BCLR.B #1,PBDR IS4 MOVE.B #4,D0
BCLR.B #2,PBDR BSR WAIT
BSET.B #0,PBDR
MOVE.B #9,D3
MOVE.B PBDR,D1 TRAP #0
AND.B #$F0,D1 BRA COL1
CMP.B #$10,D1
BEQ IS1 IS7 MOVE.B #7,D0
CMP.B #$20,D1 BSR WAIT
BEQ IS4
MOVE.B #9,D3
CMP.B #$40,D1
BEQ IS7 TRAP #0
CMP.B #$80,D1 BRA COL1
BEQ ISSTAR
BNE COL2 ISSTAR MOVE.B #$00,D0
BSR WAIT
IS1 MOVE.B #1,D0
MOVE.B #9,D3
BSR WAIT
MOVE.B #9,D3 TRAP #0
TRAP #0 BRA COL1
BRA COL1
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 3: Scan 2nd Column
COL2 BCLR.B #0,PBDR IS5 MOVE.B #5,D0
BCLR.B #2,PBDR BSR WAIT
BSET.B #1,PBDR MOVE.B #9,D3
MOVE.B PBDR,D1 TRAP #0
AND.B #$F0,D1 BRA COL1
CMP.B #$10,D1
BEQ IS2 IS8 MOVE.B #8,D0
CMP.B #$20,D1 BSR WAIT
BEQ IS5 MOVE.B #9,D3
CMP.B #$40,D1 TRAP #0
BEQ IS8 BRA COL1
CMP.B #$80,D1
BEQ IS0 IS0 MOVE.B #0,D0
BNE COL3 BSR WAIT
MOVE.B #9,D3
IS2 MOVE.B #2,D0 TRAP #0
BSR WAIT BRA COL1
MOVE.B #9,D3
TRAP #0
BRA COL1
Step 4 Scan 3rd Column
P0 P1 P2=1
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 4: Scan 3rd Column
COL3 BCLR.B #0,PBDR IS6 MOVE.B #6,D0
BCLR.B #1,PBDR BSR WAIT
BSET.B #2,PBDR MOVE.B #9,D3
MOVE.B PBDR,D1 TRAP #0
AND.B #$F0,D1 BRA COL1
CMP.B #$10,D1
BEQ IS3 IS9 MOVE.B #9,D0
CMP.B #$20,D1 BSR WAIT
BEQ IS6 MOVE.B #9,D3
CMP.B #$40,D1 TRAP #0
BEQ IS9 BRA COL1
CMP.B #$80,D1
BEQ ISHASH ISHASH MOVE.B #0,D0
BNE COL1 BSR WAIT
MOVE.B #9,D3
IS3 MOVE.B #3,D0 TRAP #0
BSR WAIT BRA COL1
MOVE.B #9,D3
TRAP #0
BRA COL1
Complete Program
ORG $080C00 COL1BCLR.B #1,PBDR ISSTAR MOVE.B
BCLR.B #2,PBDR #$00,D0
DELAY MOVE.B #$1F,D4 BSET.B #0,PBDR BSR WAIT
NEXTDEL SUB.B #1,D4 MOVE.B PBDR,D1 MOVE.B #9,D3
BNE NEXTDEL AND.B #$F0,D1 TRAP #0
CMP.B #$10,D1 BRA COL1
WAIT MOVE.B PBDR,D2 BEQ IS1 END
AND.B #$F0,D2 CMP.B #$20,D1 START
CMP.B #$00,D2 BEQ IS4
BNE WAIT CMP.B #$40,D1 COL2BCLR.B #0,PBDR
RTS BEQ IS7 BCLR.B #2,PBDR
CMP.B #$80,D1 BSET.B #1,PBDR
BEQ ISSTAR MOVE.B PBDR,D1
START ORG $080D00 AND.B #$F0,D1
BNE COL2 CMP.B #$10,D1
PGCR EQU $100001 BEQ IS2
PACR EQU $10000D IS1 MOVE.B #1,D0 CMP.B #$20,D1
PBCR EQU $10000F BSR WAIT BEQ IS5
MOVE.B #9,D3 CMP.B #$40,D1
PADDR EQU $100005 TRAP #0 BEQ IS8
PBDDR EQU $100007 BRA COL1 CMP.B #$80,D1
PCDDR EQU $100009 BEQ IS0
PADR EQU $100011 IS4 MOVE.B #4,D0 BNE COL3
PBDR EQU $100013 BSR WAIT
PCDR EQU $100019 MOVE.B #9,D3 IS2 MOVE.B #2,D0
TRAP #0 BSR WAIT
BRA COL1 MOVE.B #9,D3
INIT MOVE.B #$00,PGCR TRAP #0
MOVE.B #$80,PACR IS7 MOVE.B #7,D0 BRA COL1
MOVE.B #$80,PBCR BSR WAIT
MOVE.B #$0F,PBDDR MOVE.B #9,D3
MOVE.B #$00,PBDR TRAP #0
BRA COL1
Complete Program
IS5 MOVE.B #5,D0 IS3 MOVE.B #3,D0
BSR WAIT BSR WAIT
MOVE.B #9,D3 MOVE.B #9,D3
TRAP #0 TRAP #0
BRA COL1 BRA COL1
IS8 MOVE.B #8,D0
BSR WAIT IS6 MOVE.B #6,D0
MOVE.B #9,D3 BSR WAIT
TRAP #0 MOVE.B #9,D3
BRA COL1 TRAP #0
BRA COL1
IS0 MOVE.B #0,D0
BSR WAIT IS9 MOVE.B #9,D0
MOVE.B #9,D3 BSR WAIT
TRAP #0 MOVE.B #9,D3
BRA COL1 TRAP #0
BRA COL1
COL3BCLR.B #0,PBDR
BCLR.B #1,PBDR ISHASH MOVE.B #0,D0
BSET.B #2,PBDR BSR WAIT
MOVE.B PBDR,D1 MOVE.B #9,D3
AND.B #$F0,D1 TRAP #0
CMP.B #$10,D1 BRA COL1
BEQ IS3
CMP.B #$20,D1
BEQ IS6
CMP.B #$40,D1
BEQ IS9
CMP.B #$80,D1
BEQ ISHASH
BNE COL1
Example
Example 4 Pressed
P0 P1 P2
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 2: Scan 1st Column
COL1 BCLR.B #1,PBDR IS4 MOVE.B #4,D0
BCLR.B #2,PBDR BSR WAIT
BSET.B #0,PBDR
MOVE.B #9,D3
MOVE.B PBDR,D1 TRAP #0
AND.B #$F0,D1 BRA COL1
CMP.B #$10,D1
BEQ IS1 IS7 MOVE.B #7,D0
CMP.B #$20,D1 BSR WAIT
BEQ IS4
MOVE.B #9,D3
CMP.B #$40,D1
BEQ IS7 TRAP #0
CMP.B #$80,D1 BRA COL1
BEQ ISSTAR
BNE COL2 ISSTAR MOVE.B #$00,D0
BSR WAIT
IS1 MOVE.B #1,D0
MOVE.B #9,D3
BSR WAIT
MOVE.B #9,D3 TRAP #0
TRAP #0 BRA COL1
BRA COL1
Example 8 Pressed
P0 P1 P2
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 3: Scan 2nd Column
COL2 BCLR.B #0,PBDR IS5 MOVE.B #5,D0
BCLR.B #2,PBDR BSR WAIT
BSET.B #1,PBDR MOVE.B #9,D3
MOVE.B PBDR,D1 TRAP #0
AND.B #$F0,D1 BRA COL1
CMP.B #$10,D1
BEQ IS2 IS8 MOVE.B #8,D0
CMP.B #$20,D1 BSR WAIT
BEQ IS5 MOVE.B #9,D3
CMP.B #$40,D1 TRAP #0
BEQ IS8 BRA COL1
CMP.B #$80,D1
BEQ IS0 IS0 MOVE.B #0,D0
BNE COL3 BSR WAIT
MOVE.B #9,D3
IS2 MOVE.B #2,D0 TRAP #0
BSR WAIT BRA COL1
MOVE.B #9,D3
TRAP #0
BRA COL1
Example 6 Pressed
P0 P1 P2
1 2 3
P4
4 5 6
P5
7 8 9
P6
* 0 # P7
Step 4: Scan 3rd Column
COL3 BCLR.B #0,PBDR IS6 MOVE.B #6,D0
BCLR.B #1,PBDR BSR WAIT
BSET.B #2,PBDR MOVE.B #9,D3
MOVE.B PBDR,D1 TRAP #0
AND.B #$F0,D1 BRA COL1
CMP.B #$10,D1
BEQ IS3 IS9 MOVE.B #9,D0
CMP.B #$20,D1 BSR WAIT
BEQ IS6 MOVE.B #9,D3
CMP.B #$40,D1 TRAP #0
BEQ IS9 BRA COL1
CMP.B #$80,D1
BEQ ISHASH ISHASH MOVE.B #0,D0
BNE COL1 BSR WAIT
MOVE.B #9,D3
IS3 MOVE.B #3,D0 TRAP #0
BSR WAIT BRA COL1
MOVE.B #9,D3
TRAP #0
BRA COL1
Delay Subroutine
Delay Subroutine
In some applications, we may need to delay the
output before executing next instruction.
Can be achieved using delay subroutine:
Does some meaningless repetitive task over and
over.
Wastes processing time of M68k.
Can be set to repeat until desired delay is achieved.
Delay Subroutine Example
DELAY MOVE.L #xxx,Dn
LOOP SUB.L #1,Dn
CMP.L #0,Dn
BNE LOOP
RTS
Calculating The Delay
To calculate delay, you need to know the
time required to execute each instruction:
MOVE.L 12 0.0000012s
Executed n times.
SUB.L 16 0.0000016s
CMP.L 14 0.0000014s
BNE 10 0.0000010s
RTS 16 0.0000016s
10,000,000 = 28 + 40n
n = (10,000,000 28)/40
MOVE.L 12 0.0000012s
Executed n times.
SUB.L 16 0.0000016s
CMP.L 14 0.0000014s
BNE 10 0.0000010s
RTS 16 0.0000016s
2,500,000 = 28 + 40n
n = (2,500,000 28)/40
END START
Conclusion
Conclusion
The M68230 is a parallel interface used by
M68k to connect with various devices.
The M68230 has three ports, which can be
configured to interface with many devices.
To use the ports, it MUST be initialized
first.
Conclusion
The delay subroutine is used to waste
the CPUs time by telling it to do repetitive
tasks.
The delay format is basically the same,
just adjust the counter to get the delay you
want.
The End
Please read:
Antonakos, pg. 352-366
M68230 Datasheet