GENERAL PURPOSE I/O CONFIGURATION
5 - 8
PORT B
MOTOROLA
Figure 5-7 details the process of programming Port B as GPIO. Normally, it is not good
programming practice to activate a peripheral before programming it. However, reset acti-
vates the Port B general-purpose I/O as all inputs; the alternative is to configure Port B as
an HI, which may not be desirable. In this case, it is probably better to insure that Port B
is initially configured for general-purpose I/O, and then configure the data direction and
data registers. It may be better in some situations to program the data direction or the data
registers first to prevent two devices from driving one signal. The order of steps 1, 2, and
3 in Figure 5-7 is optional and can be changed as needed.
5.2.2
Port B General Purpose I/O Timing
General purpose data written to Port B is synchronized to the central processing unit
(CPU) but delayed by one instruction cycle. For example, the instruction
MOVE
DATA15,X:PORTB
DATA24,Y:EXTERN
1. writes 15 bits of data to the Port B register, but the output pins do not change
until the following instruction cycle
2. writes 24 bits of data to the external Y memory, which appears on Port A dur-
ing T2 and T3 of the current instruction
As a result, if it is desirable to synchronize Port A and Port B outputs, two instructions must
be used:
MOVE
DATA15,X:PORTB
NOP
DATA24,Y:EXTERN
The NOP can be replaced by any instruction that allows parallel moves. Inserting one or
more “MOVE DATA15,X:PORTB DATA24,Y:EXTERN” instructions between the first and
•
MOVE
#$0,X:$FFE0
;Select Port B to be general-purpose I/O
MOVE
#$7F00,X:$FFE2
;Select pins PB0–PB7 to be inputs
•
;and pins PB8–PB14 to be outputs
•
MOVEP #data_out,X:$FFE4
;Put bits 8–14 of “data_out” on pins
;PB8–PB14 bits 0–7 are ignored
MOVEP X:$FFE4,#data_in
;Put PB0–PB7 in bits 0–7 of “data_in”
Figure 5-6 Instructions to Write/Read Parallel Data with Port B
F
re
e
sc
a
le
S
e
m
ic
o
n
d
u
c
to
r,
I
Freescale Semiconductor, Inc.
For More Information On This Product,
Go to: www.freescale.com
n
c
.
..