Professional Documents
Culture Documents
250 2 9 2000 PDF
250 2 9 2000 PDF
To actuators
Displays,
keyboard
etc.
RAM, EPROM,
EEPROM, flash
Single Chip
Examples:
Motorola’s 68HC11, 68HC12, AMD 29K,
Zilog’s Z8, Z80, Intel’s 8052, Microchip’s PIC
Low-power, embedded versions of desktop CPUs: e.g Intel’s 80486
EECC250 - Shaaban
#2 Lec # 20 Winter99 2-9-2000
A Typical Microcontroller Application:
Car Cruise Control
Speed Measurement
EECC250 - Shaaban
#3 Lec # 20 Winter99 2-9-2000
The Motorola 68HC12 Microcontroller
A Typical 68HC12 has the following components on the chip:
– A 16-bit central processing unit (CPU12):
• 20-Bit ALU. Instruction Queue.
• Enhanced Indexed Addressing. Fuzzy Logic Instructions.
EECC250 - Shaaban
#4 Lec # 20 Winter99 2-9-2000
A Typical 68HC12
Chip Pin-Out
MC68HC912B32
EECC250 - Shaaban
#5 Lec # 20 Winter99 2-9-2000
M68EVB912B32 Evaluation Board Layout
EECC250 - Shaaban
#6 Lec # 20 Winter99 2-9-2000
Motorola 68HC12
16-bit Memory
Address Space
0x0800
User
Program
Memory:
256 bytes
0x08FF
0x0900
User
Data
Memory:
256 bytes
0x09FF
EECC250 - Shaaban
#7 Lec # 20 Winter99 2-9-2000
68HC12 Programming Model:
Registers
EECC250 - Shaaban
#8 Lec # 20 Winter99 2-9-2000
68HC12 Registers
A 8-bit Accumulator A
B 8-bit Accumulator B
D 16-bit Double accumulator D (A : B)
X 16-bit Index register X
Y 16-bit Index register Y
SP 16-bit Stack pointer
PC 16-bit Program Counter
CCR Condition code register:
S STOP instruction control bit
X Non-maskable interrupt control bit
H Half-carry status bit
I Maskable interrupt control bit
N Negative status bit
Z Zero status bit
V Two’s complement overflow status bit
C Carry/Borrow status bit
EECC250 - Shaaban
#9 Lec # 20 Winter99 2-9-2000
68HC12 Data Types
The HC12 uses the following types of data:
– Bits.
– 5-bit signed integers.
– 8-bit signed and unsigned integers.
– 8-bit, 2-digit binary coded decimal (BCD) numbers.
– 9-bit signed integers.
– 16-bit signed and unsigned integers.
– 16-bit effective addresses.
– 32-bit signed and unsigned integers.
• 5-bit and 9-bit signed integers are used only as offsets for indexed
addressing modes.
• 16-bit effective addresses are formed during addressing mode
computations.
• 32-bit integer dividends are used by extended division instructions.
• Extended multiply and extended multiply-and-accumulate instructions
produce 32-bit products.
EECC250 - Shaaban
#10 Lec # 20 Winter99 2-9-2000
68HC12 Addressing Modes
• Inherent Addressing Mode (INH).
• Immediate Addressing Mode (IMM).
• Direct Addressing Mode (DIR).
• Extended Addressing Mode (EXT).
• Indexed Addressing Modes:
• 5-Bit Constant Offset Indexed Addressing (IDX).
• Auto Pre/Post Decrement/Increment Indexed Addressing (IDX)
• Accumulator Offset Indexed Addressing (IDX).
• 9-Bit Constant Offset Indexed Addressing (IDX1).
• 16-Bit Constant Offset Indexed Addressing (IDX2).
• Indirect Indexed Addressing:
• 16-Bit Constant Offset Indexed Addressing [IDX2].
• Accumulator D Indirect Indexed Addressing [D, IDX].
EECC250 - Shaaban
#11 Lec # 20 Winter99 2-9-2000
68HC12 Addressing Modes
• Inherent Addressing Mode (INH):
– Instructions that use this addressing mode either have no operands
or all operands are in internal CPU registers.
– Examples:
NOP ; this instruction has no operands
CLRA ; clear A
ABA ; add A to B result in A
ASRA ; arithmetic shift right A
EECC250 - Shaaban
#12 Lec # 20 Winter99 2-9-2000
68HC12 Addressing Modes
• Direct Addressing Mode (DIR):
– Used to access operands in the memory address range $0000 through
$00FF
– Examples:
LDAA $55 ; load register A with 8-bit value in memory address $0055
LDX $20 ; load index register X with 16-bit value in $0020, $0021
STY $50 ; store value of Y to memory addresses $0050, $0051
EECC250 - Shaaban
#13 Lec # 20 Winter99 2-9-2000
68HC12 Indexed Addressing Modes
• 5-Bit Constant Offset Indexed Addressing (IDX):
– Uses an 5-bit signed offset (range -16 to 15) which is added to the base
index register (X, Y, SP, or PC) to form the effective address:
– Examples:
LDAA 12,X ; load A with the byte at memory address (X) + 12
STAB –8,Y ; store the byte in B at address (Y) - 8
ADDA 5,X ; add A to the byte at (X) + 5, result in A
EECC250 - Shaaban
#15 Lec # 20 Winter99 2-9-2000
Indexed Addressing Modes
Accumulator Offset Indexed Addressing (IDX):
– In this indexed addressing mode, the effective address is
the sum of the values in the base index register (X, Y, SP,
or PC) and an unsigned offset in one of the accumulators
(8bit A, B or 16-bit D).
– Example:
LDAA B,X
EECC250 - Shaaban
#16 Lec # 20 Winter99 2-9-2000
Indirect Indexed Addressing
• 16-Bit Constant Offset Indexed Addressing [IDX] :
– Adds a 16-bit instruction-supplied offset to the base index register
to form the address of a memory location that contains a pointer
to the memory location affected by the instruction.
– Example:
LDAA [10,X]
• In this example, X holds the base address of a table of pointers.
• Assume that X has an initial value of $1000, and that the value
$2000 is stored at addresses $100A and $100B.
• The instruction first adds the value 10 to the value in X to form
the address $100A.
• Next, an address pointer ($2000) is fetched from memory at
$100A.
• Then, the byte value stored in location $2000 is read and loaded
into the A accumulator.
EECC250 - Shaaban
#17 Lec # 20 Winter99 2-9-2000
Indirect Indexed Addressing
• Accumulator D Indirect Indexed Addressing [D,IDX]:
– Adds the value in the D accumulator to the value in the base index
register to form the address of a memory location that contains a
pointer to the memory location affected by the instruction.
– The square brackets distinguish this addressing mode from D
accumulator offset indexing.
– Example:
JMP [D,PC]
GO1 DC.W PLACE1
GO2 DC.W PLACE2
GO3 DC.W PLACE3
• Assume that the value in D is $0002.
• The JMP instruction adds the values in D and PC to form the
address of GO2.
• Next the CPU reads the address PLACE2 from memory at GO2
and jumps to PLACE2.
EECC250 - Shaaban
#18 Lec # 20 Winter99 2-9-2000
68HC12 Load & Store Instructions
EECC250 - Shaaban
#19 Lec # 20 Winter99 2-9-2000
68HC12 Transfer & Exchange Instructions
EECC250 - Shaaban
#20 Lec # 20 Winter99 2-9-2000
68HC12 Move Instructions
EECC250 - Shaaban
#21 Lec # 20 Winter99 2-9-2000
68HC12 Addition & Subtraction Instructions
EECC250 - Shaaban
#22 Lec # 20 Winter99 2-9-2000
68HC12 BCD Instructions
EECC250 - Shaaban
#23 Lec # 20 Winter99 2-9-2000
HC12 Increment & Decrement Instructions
EECC250 - Shaaban
#24 Lec # 20 Winter99 2-9-2000
HC12 Compare & Test Instructions
EECC250 - Shaaban
#25 Lec # 20 Winter99 2-9-2000
HC12 Logic Instructions
EECC250 - Shaaban
#26 Lec # 20 Winter99 2-9-2000
HC12 Clear, Complement & Negate Instructions
EECC250 - Shaaban
#27 Lec # 20 Winter99 2-9-2000
HC12 Multiplication & Division Instructions
EECC250 - Shaaban
#28 Lec # 20 Winter99 2-9-2000
Multiply and Accumulate Instruction
EMACS
• The EMACS instruction multiplies two 16-bit operands stored in
memory and accumulates the 32-bit result in a third memory location.
• Often used to implement simple digital filters.
EECC250 - Shaaban
#29 Lec # 20 Winter99 2-9-2000
HC12 Bit Test & Manipulation Instructions
EECC250 - Shaaban
#30 Lec # 20 Winter99 2-9-2000
HC12 Logical Shifts Instructions
EECC250 - Shaaban
#31 Lec # 20 Winter99 2-9-2000
HC12 Arithmetic Shifts Instructions
EECC250 - Shaaban
#32 Lec # 20 Winter99 2-9-2000
HC12 Rotate Instructions
EECC250 - Shaaban
#33 Lec # 20 Winter99 2-9-2000
HC12 Short Branch Instructions
EECC250 - Shaaban
#34 Lec # 20 Winter99 2-9-2000
HC12 Short Branch Instructions
EECC250 - Shaaban
#35 Lec # 20 Winter99 2-9-2000
HC12 Long Branch Instructions
EECC250 - Shaaban
#36 Lec # 20 Winter99 2-9-2000
HC12 Long Branch Instructions
EECC250 - Shaaban
#37 Lec # 20 Winter99 2-9-2000
HC12 Decrement/Branch Instructions
EECC250 - Shaaban
#38 Lec # 20 Winter99 2-9-2000
HC12 Jump & Subroutine Instructions
EECC250 - Shaaban
#39 Lec # 20 Winter99 2-9-2000
HC12 Interrupt Instructions
EECC250 - Shaaban
#40 Lec # 20 Winter99 2-9-2000
HC12 Stack Related Instructions
EECC250 - Shaaban
#41 Lec # 20 Winter99 2-9-2000
HC12 Stack Related Instructions
EECC250 - Shaaban
#42 Lec # 20 Winter99 2-9-2000
HC12 Condition Codes Instructions
EECC250 - Shaaban
#43 Lec # 20 Winter99 2-9-2000
HC12 Example: Addition of Two Values
USER_STACKTOP equ $0a00
org $0800
Main lds #USER_STACKTOP ;load stacktop
org $0900
FIRST dc.b #$01 ;first value to add
SECOND dc.b #$02 ;second value to add
ANSWER dc.b #$00 ;addition result
EECC250 - Shaaban
#44 Lec # 20 Winter99 2-9-2000
HC12 Loop Example
USER_STACKTOP equ $0a00
org $0800
org $0900
ITER dc.b #$08 ;Number of loop iterations to perform
COUNT dc.b #$00 ;Number of loop iterations performed
EECC250 - Shaaban
#45 Lec # 20 Winter99 2-9-2000
HC12 Data Table Example
; This program takes a table of data, and creates a new table
; which is the original table divided by 2
org data
;initialize table1 (COUNT bytes long)
table1: dc.b $07,$ae,$4a,$f3,$6c,$30,$7f,$12,$67,$cf
table2: ds.b count ;reserve count bytes for table2.
EECC250 - Shaaban
#46 Lec # 20 Winter99 2-9-2000