e011012.PDF

(659 KB) Pobierz
MICRO PROCESSOR
Upgrading to the
68HC12 16-bit
microcontroller (1)
an introduction
By Oliver Thamm
The application of microcontrollers on the other side of the 8-bit bound-
ary often seems like a closed book. Here we show that it can actually be
fairly easy to start working with such microcontrollers — it’s not even
necessary to be an accomplished ‘HC11 programmer!
Circuits using microcontrollers are
very flexible, and they enjoy a corre-
spondingly high level of popularity.
The Motorola 68HC11 family has for
years been one of the favourites for
hobby applications. These 8-bit
microcontrollers have an easily
understood internal structure and
can be readily programmed via an
RS232 link. The HC11 fan club has
grown over the years, and the num-
ber of published designs has also
increased (see Literature). However,
these days the HC11 has become
somewhat technically obsolescent.
New application areas demand con-
trollers that are more flexible and
that have more processing power.
Motorola, the manufacturer of the
HC11, finally decided to make a rad-
ical change in their manufacturing
technology, which however could
not easily be carried out with the
HC11 types. The result was the
68HC812A4, the first member of the
new, powerful HC12 family.
Many HC11 users do not realise
that they can easily change over to
12
Elektor Electronics
1/2001
855738351.051.png 855738351.061.png
MICRO PROCESSOR
the faster HC12. This is because the new
models have inherited the complete HC11
programming model. That means that the
structure of the CPU registers (see Figure 1 ),
the assembler instructions and the address-
ing modes have remained the same. Pro-
grammers will thus find it very easy to
change to the new family, since existing
source code only has to be retranslated. If
you’re only starting, rather than switching
over, you can still enjoy certain advantages.
In brief, the HC12 masters an important bal-
ancing act, combining high performance with
a relatively low level of complexity.
Practical circuits
Enough of the introductory remarks, now it’s
time to look at a circuit diagram for the HC12.
Figure 2 shows an HC812A4 IC and the
external circuitry that the microcontroller
needs to run. Is that all it takes? Yes, indeed,
and this is one of the main advantages of this
microcontroller unit (MCU) – almost all the
important components are integrated into the
controller.
IC3 is the well-proven Maxim TTL/RS232
signal-level converter. The HC812A4 has two
asynchronous serial interfaces, which are
internally designated SCI0 and SCI1. Their
operation is mutually independent, and they
easily manage a data rate of 38,400 baud
with the clock crystal used here. A second
serial interface has been on the wish list of a
lot of HC11 users for a long time. Now you
finally have all the resources you need, for
example to exchange messages with the
application program via the first channel
while sending debugging data via the second
channel. The two connectors X2 and X3 are
implemented as pin headers, to which one-
to-one crimped flatcables can be connected,
with 9-pin sub-D connectors (also crimped) at
the PC end.
Figure 1. HC12 CPU registers.
HC12 Operating Modes
The HC12 can work in several different operating modes that are selected via
pins MODA and MODB. The levels on these pins are read in by the processor on
the rising edge of the reset signal, to determine the operating mode. Normally,
the BKGD pin must maintain a steady High level at this moment. The following
operating modes, which are the most important, are frequently encountered in
HC12 circuits.
Normal Single Chip Mode (MODA=L, MODB=L)
The HC12 operates without an external bus interface, using only the internal
memory (RAM, EEPROM and Flash EEPROM if available). The bus leads that are
thereby made free are made available as general-purpose I/O leads.
Normal Expanded Wide Mode (MODA=H, MODB=H)
The HC812A4 operates with a 16-bit-wide external bus interface. Ports A and B
provide the address bus, while the data bus is found at ports C and D. Bus con-
trol is provided by the signals ECLK, R/W and /LSTRB (port E). The HC12 gener-
ates up to seven chip select signals on port F, as necessary. In addition, it is possi-
ble to use Memory Banking to drive memory regions beyond the 64-kB bound-
ary. Up to six leads of port G are responsible for this.
A quick tour of the MCU
The clock is generated using the usual com-
bination of a quartz crystal, a pair of ceramic
capacitors and a resistor. HC11 users will
recognise the circuit, but in this case a 16-
Mhz crystal provides the time standard. Com-
pared to standard HC11 types, this provides
four times the internal processing speed
(8 MHz E clock).
In order to reliably reset the CPU when the
circuit is switched on (or restarted), an exter-
nal reset IC is prescribed. In our circuit, this
service is provided by IC2, an MC34064P5. In
addition, it is possible to connect a manual
reset pushbutton via jumper JP3.
Jumpers JP4 and JP5 are normally closed
Normal Expanded Narrow Mode (MODA=H, MODB=L)
In this mode, the HC812A4 behaves the same as in the Expanded Wide mode,
except that the data bus is only eight bits wide (Port C). The MCU automatically
splits every 16-bit access into two sequential 8-bit accesses.
Special Single Chip Mode (MODA=L, MODB=L)
This mode is specially provided for putting the IC into operation with the Back-
ground Debug Interface Mode interface. When the reset signal is released, the
connected BCM pod must hold the BKGD lead Low for a short time. The HC12
system and the pod subsequently communicate via this lead. The CPU does not
start with processing an application program, as usual, but initially executes only
BDM instructions. In this software-development operating mode, the restrictions
on the use of some of the control registers are relaxed, since some of the protec-
tive provisions of the MCU are disabled.
1/2001
Elektor Electronics
13
855738351.072.png 855738351.083.png
MICRO PROCESSOR
V CC
1
1
R6
R5
JP4
JP5
V CC
14
2
42 79
95
JP1
R7
4k7
43
85
V CC
VDDPLL
VRH
C4
C5
36
37
49
50
MODA
XIRQ
100n
100n
X2
C8
IRQ
1
2
IC1
JP2
MODA
MODB
10µ
16V
3
4
R8
4k7
2
5
6
V+
1
16
7
8
C1+
C6
9
10
MODB
68HC812A4
IC3
3
10µ
16V
C1–
97
98
99
12
13
14
RX0
RS232 #0
RXD0
TXD0
RXD1
TXD1
R1OUT
R1IN
V CC
V CC
11
TX0
T1IN
T1OUT
9
8
RX1
TX1
R2OUT
R2IN
X1
R2
100
10
7
T2IN
T2OUT
X3
VDD
RES
GND
6
5
VPP
NC
4
C1F
C2+
C7
4
3
40
19
1
2
MAX232A
RESET
BKGD
100n
2
1
BKGND
5
15
3
4
10µ
16V
C2–
V-
5
6
BDM12
45
86
6
7
8
VSSPLL
VRL
C9
9
10
V CC
10µ
16V
R3
EXTAL
XTAL
RS232 #1
IC2
2
15
1
41 80 46
47 96
R1
10M
IN
V CC
1
OUT
Q1
1
MC34064
C1
C1A
C1B
C1C
C1D
C1E
P5
JP3
RESET
GND
C3
C2
3
47µ
16V
100n
100n
100n
100n
100n
18p
18p
Q1 = 16MHz
000077 - 11
Figure 2. The circuit diagram of the HCA812A4 component set corresponds to that of the HC12 Welcome Kit.
(installed), so that the operating voltage (Vcc,
+5 V) is applied to the power supply and ref-
erence voltage inputs of the integrated A/D
converter. These inputs can be fed from exter-
nal voltages by removing the jumpers, for
example if it is necessary to use a more pre-
cise reference voltage.
The internal EEPROM serves as the
program store. With a size of 4 kB, it
is larger than the internal program
store of the HC11. In addition, there
is 1 kB of RAM for variable data.
Since the instruction set of the HC12
is very efficient, it is possible to store
a fairly sizeable program in the inter-
nal memory. Some examples will be
provided in the second part of this
article, in the December 2000 issue.
the microcontroller works via this
lead, which is the interface for the
Background Debug Mode (BDM). As
the name indicates, the BDM inter-
face is used for more than just down-
loading software into the RAM or
EEPROM. The BKGD pin also pro-
vides a ‘back door’ to the microcon-
troller, which allows any desired
memory addresses to be read and
written, ranging from the RAM and
EEPROM to the IC control registers.
This means that, via this pin and
BDM, you can start and stop appli-
cation programs as desired, set
breakpoints, run software in single-
step mode and read or modify the
contents of the processor registers.
The most important details of
BDM12 operation are explained in
the box ‘How does BDM work?’.
This all sounds like we have a
complete hardware emulator on
board. Normally, you can expect to
pay the cost of a small car for such a
Mode selection
Two additional jumpers are needed to set the
operating mode of the HC12. JP1 is con-
nected to the MODA pin, and JP2 to the
MODB pin. The manner in which these sig-
nals affect the behaviour of the HC12 is
explained in the ‘HC12 Operating Modes’
box. In our case, both jumpers are set to the
1–2 positions and thus select the Single Chip
operating mode. Single Chip mode does not
mean that there are not any other ICs on the
board. Instead, in this mode the HC12 dis-
ables all bus signals for external memory ICs.
The ports that are made free as a conse-
quence can be used as general-purpose I/O
lines, and this means a gain of up to 40 lines!
In the background
Apart from a few blocking capacitors
and pull-up resistors, we would be
finished with the description of the
schematic diagram, except for the
six-pin connector X1. Only two ‘real’
signals are tied to this connector,
namely /RES and BKGD. The signal
/RES is an extension of the MCU
/RESET signal, while BKGD is con-
nected directly to the microcontroller.
The built-in debugging function of
14
Elektor Electronics
1/2001
855738351.001.png 855738351.002.png 855738351.003.png 855738351.004.png 855738351.005.png 855738351.006.png 855738351.007.png 855738351.008.png 855738351.009.png 855738351.010.png 855738351.011.png 855738351.012.png 855738351.013.png 855738351.014.png 855738351.015.png 855738351.016.png 855738351.017.png 855738351.018.png 855738351.019.png 855738351.020.png 855738351.021.png 855738351.022.png 855738351.023.png 855738351.024.png 855738351.025.png 855738351.026.png 855738351.027.png 855738351.028.png 855738351.029.png 855738351.030.png 855738351.031.png 855738351.032.png 855738351.033.png 855738351.034.png 855738351.035.png 855738351.036.png 855738351.037.png 855738351.038.png 855738351.039.png 855738351.040.png 855738351.041.png 855738351.042.png 855738351.043.png 855738351.044.png 855738351.045.png 855738351.046.png 855738351.047.png 855738351.048.png 855738351.049.png 855738351.050.png 855738351.052.png 855738351.053.png 855738351.054.png 855738351.055.png 855738351.056.png 855738351.057.png 855738351.058.png 855738351.059.png
 
MICRO PROCESSOR
piece of equipment, but the HC12
includes the most important features
of such a debugging aid at no extra
charge. This sounds almost too good
to be true, and in fact there is a fly in
the ointment.
The connection to a PC that is
used for developing and download-
ing the software is not entirely with-
out problems. The BDM interface is
simply too fast to work with a nor-
mal serial or parallel PC interface.
This means that you need a bit of
hardware and software to act as an
interpreter between the PC and the
HC12. This is called a BDM pod, and
it is not particularly suitable for DIY
construction. Fortunately, there are
alternative solutions, such as the
NoICE debugger, that will not soak
up the annual budget of an ambi-
tious HC12 developer in one blow. A
large collection of links relating to
BDM and the general subject of
HC12 microcontrollers can be found
on the author’s HC12 Internet site at
http://hc12web.de .
of the HC812A4 are expensive and
hard to come by. In fact, they are so
expensive that it is worth taking a
look at the second option. This con-
sists of a pre-assembled controller
module, as shown in the photo-
graph. It not only includes the
peripheral circuitry shown in Fig-
ure 2 , but also makes all processor
signals available on lateral pin
strips, where they can be easily
accessed (even using non-profes-
sional means).
The German firm Elektronikladen
(see http://www.elektronikladen.de
on the Internet) offers such modules
in credit-card format under the des-
ignation ‘HC12 Welcome Kit’ (see
http://elektronikladen.de/kit12.html )
The MCU is soldered directly to the
circuit board in an SMD production step,
without a socket. This makes the whole thing
affordable, and for around £75 you receive a
complete starter kit, including a monitor pro-
gram for easy downloading of application
programs via the serial interface.
(000077-1)
Part 2 will discuss the programming of the internal
functional modules of the HC12 and the tools that
are needed for this.
Literature:
68HC11 emulator,
Elektor Electronics February 1997.
How does BDM work?
The Background Debug Mode (BDM) interface of the HC12 is basically supported by a sin-
gle lead (BKGD) of the microcontroller. In the idle state, this lead is held High by a pull-up
resistor. A special asynchronous serial protocol is used for communications. The underlying
clock is based on the clock speed of the HC12. For example, if a 16-MHz crystal is used,
the basic time unit of the BCM system is 125 ns.
The timing diagram shows how an individual bit is transferred. This requires 16 clock
cycles, which means that it takes 2 µs to transfer one bit at 125 ns per clock, and a full byte
thus takes 16 µs. A typical BDM command sequence consists of five bytes, and thus takes
around 80 µs. In practice, you can expect to see around 5 to 10 thousand BDM instructions
per second – and that’s already pretty fast.
A BDM instruction consists of a command byte and any necessary parameters. For
example, the instruction sequence for a 16-bit write access to address $0800/1 appears
as follows:
I/O leads
It’s a fortunate person who has
enough I/O heads to connect all of
his LCDs, pushbuttons, lamps and
relays. With an HC812A4, you won’t
find your self in a predicament quite
so quickly, at least if it is working in
Single Chip mode. More than 80 I/O
connections are available to the user,
each of which can be addressed as
an input and/or output. With regard
to the internal pull-up resistors, there
are several configuration options. A
substantial number of input signals
(roughly one third) can function as
interrupt triggers.
C8 08 00 1A 2F
1 Bit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
E-Clock
(Target)
28 Pins
×
4
case 1: pod sends "0"
HC12 reads "0"
BKGND
Pin
If you’re already getting curious and
would like to take a closer look at the
HC12, you have basically two
options for getting started quickly.
The first option is to obtain the
microcontroller IC and mount it in a
socket on a universal printed circuit
board. The relatively few external
connections will not present that
much of a problem. However, the
catch is that it is very difficult to
manually solder the IC, so that a
socket must be used – and suitable
sockets for the 112-pin QFP package
HC12 reads "1 "
case 2: pod sends "1"
BKGND
Pin
000077 - 13
The individual components of the message have the following meanings:
$C8 BDM command ‘WRITE_WORD’
$0800 address
$1A2F data word
1/2001
Elektor Electronics
15
855738351.060.png 855738351.062.png 855738351.063.png 855738351.064.png 855738351.065.png 855738351.066.png 855738351.067.png 855738351.068.png 855738351.069.png 855738351.070.png 855738351.071.png 855738351.073.png 855738351.074.png 855738351.075.png 855738351.076.png 855738351.077.png 855738351.078.png 855738351.079.png 855738351.080.png 855738351.081.png 855738351.082.png 855738351.084.png 855738351.085.png 855738351.086.png
 
Zgłoś jeśli naruszono regulamin