Page 343 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 343
320 Chapter 11 Input/ Output
11.2 Parallel Ports
The ' A4 and 'B32 have two parallel ports, shown in Figure 11.3. The description of each
port and their special features and programming techniques are discussed in the first
subsection. The second subsection describes an object-oriented class for these ports.
The 6832's parallel ports have a direction port. For port A, for each bit position, if
the port A direction bit is zero, as it is after reset, the port bit is an input, otherwise if
the port A direction bit is one, the port bit is a readable output bit. A direction port is an
example of a control port, which is an output port that controls the device but doesn't
send data outside it.
We illustrate the use of PORTA in assembly language first, and in C or C++ after
that. To make PORTA an output port, we can write in assembly language:
LDAB #$FF ; generate all ones
STAB $2 ; put them in direction bits for output
Then, any time after that, to output accumulator B to PORTA we can output
accumulator B to port A by writing STAB $0. To make PORTA an input port, we
put zeros in direction bits for input by executing CLR $2. Then, any time after that, to
input PORTA into accumulator B we read PORTA into accumulator B by writing
LDAB $0. It is possible to make some bits, for instance the rightmost three bits,
readable output bits and the remaining bits input bits, as follows:
LDAB #7 ; generate three ones in rightmost bits
STAB $2 ; put them in direction bits for output
The instruction STAB $0 writes the rightmost three bits into the readable output port
bits. The instruction LDAA $0 reads the left five bits as input port bits and the right
three bits as readable output bits. A minor feature also occurs on writing the 3-bit word:
The bits written where the direction is input are saved in a register in the device and
appear on the pins if later the pins are made readable output port bits.
Ports can be identified by putting the @ sign after port names, followed by their
locations. These can be put in a header file that is #included in each program:
unsigned char PORTAiO, PORTBll, DDRA@2, DDRB83;
The equivalent operations in C or C++ are shown below. To make PORTA an output
port, we can write
DDRA = Oxff;
Address Name 'A4 Pins 'B32 Pins
Figure 113. Some 6812 Parallel I/O Ports