This is only a preview of the December 1993 issue of Silicon Chip. You can view 29 of the 96 pages in the full issue, including the advertisments. For full access, purchase the issue for $10.00 or subscribe for access to the latest issues. Articles in this series:
Items relevant to "Build A Low-Voltage LED Stroboscope":
Items relevant to "A Low-Cost 25W Amplifier Module":
Articles in this series:
Articles in this series:
Articles in this series:
|
Lesson 3
Programming the Motorola
68HC705C8 microcontroller
In Lesson 2, we covered the following topics:
(1) Mnemonics; (2) Addressing Modes; and (3)
the 6805 Instruction Set. This month, we look
further at addressing modes.
By BARRY ROZEMA
Table 1
Opcode
Mnemonic
A. Mode
No. Bytes
No. Cycles
A6
LDA
IMM
2
2
C6
LDA
EXT
3
4
86
SWI
INH
1
10
C7
STA
EXT
3
5
CC
JMP
EXT
3
3
43
COMA
INH
1
3
A3
CPX
IMN
2
2
42
MUL
INH
1
11
Before moving into new territory,
let’s first take a look at the answers to
the exercises in Lesson 2.
Exercise 1: fill in the blank spaces
in Table 2 (Lesson 2). A look at the instruction set in Lesson 2 and/or the op
code map on page 30 of the Motorola
MC68HC705C8 technical summary
(BR594/D) should have given you the
information to get the results shown
in Table 1.
You should also have modified your
programs in last months lesson to get
the following results. Each exercise
is a modification of the previous program. You add the same instructions
on to the program with a change to the
data. The flow charts have the new or
modified processes shown with an
asterisk (*).
Exercise 2: rewrite the flow chart
and the program to make the LEDs
give a smooth inward pattern; ie, to
make the LEDs close in one bit at a
time instead of two.
To do this, you will need to examine
the bit pattern to get the hex values.
Table 2 shows the bit map.
Notice that the bits come “on” one
bit at a time in an inward direction.
The asterisks show the data that’s
added to give a smoother display
pattern. Table 3 shows the modified
program.
To do this, you need to change the
immediate byte that sets the time
delay. Remember, the time delay uses
a subroutine that is in the MAL-4
monitor ROM. There are seven time
delay subroutines and each one is set
by loading the accumulator before
jumping to the subroutine.
You may have found that experimenting with various delay values
by changing the immediate byte in
the LDA #$?? instruction quickly
became rather tedious. A better way
is to make the delay time adjustable
while the program is running. To do
this, you load the accumulator with
the value of the input port instead of
a fixed value; ie, you use extended
addressing instead of immediate. The
PORT A input port address is $0000.
The instruction looks like this: LDA
$$0000.
The modified process is shown
with an asterisk in the flow chart of
Fig.2 and Table 4 shows the modified
program. Note: remember to enable
PORT A by turning switch 7 of DIP
SW2 (Bit 6) on.
Kitt scanner
Exercise 4: rewrite the flow chart
and the program to make an 8-bit
“Kitt” scanner; ie, one LED on at a
time switching from left to right and
back again.
Better visual effect
This program will need to produce
a display with a pattern like the one in
Exercise 3: experiment with the time
the bit map of Table 5. If you make the
delay to give a better visual effect.
time delay adjustable as in exercise 3,
Table 2
the program will repeat the following
instructions.
B7 B6 B5 B4 B3 B2 B1 B0
HEX
A6 xx
LDA #$xx
0
0
0
0
0
0
0
0
$00
C7 00 01 STA $$0001
1
0
0
0
0
0
0
1
$81 *
C6 00 00 LDA $$0000
CD 14 D9 JSR
$$14D9
1
1
0
0
0
0
1
1
$C3
The xx will contain the pattern data.
1
1
1
0
0
1
1
1
$E7 *
There are 14 patterns to be displayed
1
1
1
1
1
1
1
1
$FF
before the program starts again. The
December 1993 53
Table 3
ADDRESS
CODE
LABEL
MNEMONIC
OPERAND
COMMENT
0030
A600
START
LDA
#$00
0032
C70001
STA
$$0001
Clear accumulator
& store at output
0035
A632
LDA
#$32
0037
CD14D9
JSR
$$14D9
003A
A681
LDA
#$81
003C
C70001
STA
$$0001
003F
A632
LDA
#$32
0041
CD14D9
JSR
$$14D9
0044
A6C3
LDA
#$C3
0046
C70001
STA
$$0001
0049
A632
LDA
#$32
004B
CD14D9
JSR
$$14D9
004E
A6E7
LDA
#$E7
0050
C70001
STA
$$0001
0053
A632
LDA
#$32
0055
CD14D9
JSR
$$14D9
0058
A6FF
LDA
#$FF
005A
C70001
STA
$$0001
005D
A632
LDA
#$32
005F
CD14D9
JSR
$$14D9
Set time delay 50
($32) x ACC = 0.5
seconds
0062
CC0030
JMP
$$0030
Jump to start
ADDRESS
CODE
LABEL
MNEMONIC
OPERAND
COMMENT
0030
A600
START
LDA
#$00
0032
C70001
STA
$$0001
Clear accumulator
& store at output
0035
C60000
LDA
$$0000
0038
CD14D9
JSR
$$14D9
003B
A681
LDA
#$81
003D
C70001
STA
$$0001
Set time delay 50
($32) x ACC = 0.5
seconds
Load accumulator
& store at output
Set time delay 50
($32) x ACC = 0.5
seconds
Load accumulator
& store at output
Set time delay 50
($32) x ACC = 0.5
seconds
Load accumulator
& store at output
Set time delay 50
($32) x ACC = 0.5
seconds
Load accumulator
& store at output
Table 4
Fig.1: the flow chart for Exercise 2.
The program first turns on the two
outside LEDs at the output port, then
turns the remaining LEDs on to give a
smooth inward pattern; ie, the LEDs
close in one bit at a time.
Set time delay input
port A times ACC
Load accumulator
& store at output
0040
C60000
LDA
$$0000
0043
CD14D9
JSR
$$14D9
0046
A6C3
LDA
#$C3
0048
C70001
STA
$$0001
004B
C60000
LDA
$$0000
004E
CD14D9
JSR
$$14D9
0051
A6E7
LDA
#$E7
0053
C70001
STA
$$0001
0056
C60000
LDA
$$0000
0059
CD14D9
JSR
$$14D9
Addressing modes
005C
A6FF
LDA
#$FF
In Lesson 2, we covered the following three addressing modes: Inherent, Immediate and Extended. This
lesson, we will introduce another
005E
C70001
STA
$$0001
0061
C60000
LDA
$$0000
0064
CD14D9
JSR
$$14D9
Set time delay input
port A times ACC
0067
CC0030
JMP
$$0030
Jump to start
program will take 14 x 11 bytes = 154
bytes plus two jumps (one jump to go
back to the start and one to jump to
the RAM at location $0100). The last
jump is needed because the MAL-4
only has 144 bytes of user RAM at
page zero ($0030 - $00BF) – see the
memory map in the November 1993
issue of SILICON CHIP.
54 Silicon Chip
Set time delay input
port A times ACC
Load accumulator
& store at output
Set time delay input
port A times ACC
Load accumulator
& store at output
Set time delay input
port A times ACC
Load accumulator
& store at output
Table 2
B7
B6
B5
B4
B3
B2
B1
B0
HEX
0
0
0
0
0
0
0
1
$01
0
0
0
0
0
0
1
0
$02
0
0
0
0
0
1
0
0
$04
0
0
0
0
1
0
0
0
$08
0
0
0
1
0
0
0
0
$10
0
0
1
0
0
0
0
0
$20
0
1
0
0
0
0
0
0
$40
1
0
0
0
0
0
0
0
$80
0
1
0
0
0
0
0
0
$40
0
0
1
0
0
0
0
0
$20
0
0
0
1
0
0
0
0
$10
0
0
0
0
1
0
0
0
$08
0
0
0
0
0
1
0
0
$04
0
0
0
0
0
0
1
0
$02
addressing mode called “Direct” or
“Zero Page”.
Direct Addressing Mode
Symbol for Direct addr ess
ing: $ or Z or
none.
The CPU requires two bytes of data to process
this instruction. The first byte is the
op-code, while the second byte is the
Low address of the operand in memory. This is like the extended addressing
mode except that you can only address
zero page.
The CPU sets the High address to
$00 and so you can only address data
from $0000 to $00FF. The CPU requires
the operand (byte) which is “directly”
at zero page in memory. The memory
location for this byte is known at the
time the program is written. The opcode for direct addressing is found in
Lesson 2, Table 1, column 5. In these
lessons, we will use the “Z” symbol to
indicate Direct addressing (Z for Zero
page). The mnemonics will have a “Z”
tacked on the end of them, eg: ADDZ,
ANDZ, ORAZ, EORZ, LDAZ, STAZ
and LDXZ.
The MAL-4 can make good use of
zero page (Direct) addressing. Most
of the user RAM is located at zero
page, as are all of the input/output,
timer, watchdog and other control
registers. Thus, it is possible to write
programs that use more direct (zero
page) addressing than extended. This
saves one byte of program each time
you use direct instead of extended
addressing.
The program in Table 6 is the same
as in Table 3 from Lesson 2 except that
direct addressing was used instead of
extended addressing, were possible.
The four asterisks (*) in Table 6 indicate instructions with direct (zero
page) addressing. The first three (STAZ
$01) are used because the output port
(PORT B) is at address $0001 which
is in zero page of memory. The last in
struction (JMPZ $30) is used because
our program is written in zero page
RAM, from $0030.
Running the program
Load the program into the MAL-4
and run it from location $0030. The
output port LEDs should flash in the
pattern described in Lesson 2. If not,
go back and check that the program
Table 6
ADDRESS
CODE
LABEL
MNEMONIC
OPERAND
COMMENT
0030
A600
0032
B701
START
LDA
#$00
*
STAZ
$01
Clear accumulator
& store at output
0034
A632
LDA
#$32
0036
CD14D9
JSR
$$14D9
0039
A6C3
LDA
#$C3
003B
B700
STAZ
$00
003D
A632
LDA
#$32
003F
CD14D9
JSR
$$14D9
0042
A6FF
LDA
#$FF
0044
B700
STAZ
$01
0046
A632
LDA
#$32
0048
CD14D9
JSR
$$14D9
Set time delay 50
($32) x ACC = 0.5
seconds
004B
BC30
JMPZ
$30
Jump to start
*
*
*
Set time delay 50
($32) x ACC = 0.5
seconds
Load accumulator
& store at output
Set time delay 50
($32) x ACC = 0.5
seconds
Load accumulator
& store at output
Fig.2: this modified flow chart will
provide a better visual effect than
the flow chart shown in Fig.1. In this
case, the time delays have been set
by loading the accumulator with the
value of the input port instead of a
fixed value.
has been entered correctly. If there
are problems, Mode 2 (the disassemble mode) may help you find your
mistake.
Things to do
In Lesson 4, we will continue with
addressing modes and we will explain
relative addressing. Make sure that
you read up on 8-bit 2’s complement
negative numbers. Finally, rewrite all
your programs in Exercises 2-4 to use
direct addressing were possible. Note
SC
the saving on memory.
December 1993 55
|