Introducing the 68HC12 Chapter 1

Download Report

Transcript Introducing the 68HC12 Chapter 1

Introducing the 68HC12
Chapter 1
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Introducing the 68HC12
•
•
•
•
From Microprocessors to Microcontrollers
The 68HC12 Registers
Writing Programs for the 68HC12
Addressing Modes
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
A microprocessor (CPU)
connected to external memory
Data
Bus
RAM
CPU
ROM
(registers)
I/O
Address
Bus
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
The 68HC11
RAM
CPU
ROM/
EPROM
EEPROM
68HC11
A/D
TIMER
PARALLEL
I/O
SPI
SCI
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Selected 68HC11 Parts
Part No.
68HC11A8
68HC11D0
68HC711D3
68HC711E9
68HC711K4
ROM/EPROM
8K
0
4K
12K
24K
RAM
256
192
192
512
768
EEPROM
512
0
0
512
640
I/O
38
14
32
38
62
Timer
3 IC, 5 OC
3/4 IC, 4/5 OC
3/4 IC, 4/5 OC
3/4 IC, 4/5 OC
3/4 IC, 4/5 OC
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
A/D
Yes
No
No
Yes
Yes
68HC11 Applications
Consumer
Televisions
VCRs
Cable Boxes
Camcoders
Cameras
Security Systems
Office Automation
Modems
Typewriters
Smart Furniture
Hard Disk Drives
Communications
Handheld Radios
Cellular Telephones
Cordless Telephones
Digital Telephones
Home Video Game Systems
Compact Disc Players
Digital Audio Systems
Digital Radio
Appliances
Tape Drives
Monitors
Keyboards
Scanners
Telephone Switching
Analog Telephones
Answering Machines
Pagers
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
68HC11 Applications
Industrial Control and Instrumentation
Elevators
Traffic Control
Meter Reading
ATM Machines
Vending Machines
Card Readers
Bar Code Readers
Manufacturing Tracking
Process Control
Automotive
Instrument Displays
Injection Systems
Emission Control
Engine Control
Climate Control
Fire Control
Security Systems
Lighting Control
Noise Control
Gas Furnaces
Blood Pressure Monitors
Blood Analyzers
Glucose Monitors
Gas Analyzers
Cruise Control
Active Suspension
Anti-lock Braking Systems (ABS)
Air Bags
Automatic Seat Belts
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Introducing the 68HC12
•
•
•
•
From Microprocessors to Microcontrollers
The 68HC12 Registers
Writing Programs for the 68HC12
Addressing Modes
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
The 68HC12 Registers
Accum ulator A
A
B
Accum ulator D
D
Inde x register X
IX
Inde x register Y
IY
Sta ck Pointer
SP
Pro gra m counter
PC
S XH IN ZV C
Accum ulator B
C ondition code register
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
The 68HC12 Accumulators
Load and Store Instructions:
LDAA
Load A from memory
LDAB
Load B from memory
LDD
Load D from memory
STAA
Store A to memory
STAB
Store B to memory
STD
Store D to memory
Transfer and Exchange Instructions:
TAB
Transfer A to B
TBA
Transfer B to A
EXG A,B
Exchange A and B
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Addition and Subtraction Instructions:
ABA
Add B to A
ADDA
Add memory to A
ADDB
Add memory to B
ADCA
Add memory with carry to A
ADCB
Add memory with carry to B
ADDD
Add memory to D
SBA
Subtract B from A
SUBA
Subtract memory from A
SUBB
Subtract memory from B
SBCA
Subtract memory with borrow from A
SBCB
Subtract memory with borrow from B
SUBD
Subtract memory from D
Decrement and Increment Instructions:
DECA
Decrement A
DECB
Decrement B
INCA
Increment A
INCB
Increment B
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Compare and Test Instructions:
CBA
Compare A to B
CMPA
Compare A to memory
CMPB
Compare B to memory
CPD
Compare D to memory
TSTA
Test A for zero or minus
TSTB
Test B for zero or minus
Boolean Logic Instructions:
ANDA
AND A with memory
ANDB
AND B with memory
EORA
Exclusive OR A with memory
EORB
Exclusive OR B with memory
ORAA
OR A with memory
ORAB
OR B with memory
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Shift and Rotate Instructions:
LSLA
Logic shift left A
LSLB
Logic shift left B
LSLD
Logic shift left D
LSRA
Logic shift right A
LSRB
Logic shift right B
LSRD
Logic shift right D
ASLA
Arithmetic shift left A
ASLB
Arithmetic shift left B
ASLD
Arithmetic shift left D
ASRA
Arithmetic shift right A
ASRB
Arithmetic shift right B
ROLA
Rotate left A through carry
ROLB
Rotate left B through carry
RORA
Rotate right A through carry
RORB
Rotate right B through carry
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Stacking Instructions:
PSHA
Push A
PSHB
Push B
PSHD
Push D
PULA
Pull A
PULB
Pull B
PULD
Pull D
Clear, Complement, and Negate Instructions:
CLRA
Clear A
CLRB
Clear B
COMA
One's complement A
COMB
One's complement B
NEGA
Two's complement A
NEGB
Two's complement B
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Index Registers, X and Y
Load and Store Instructions:
LDX
Load X from memory
LDY
Load Y from memory
STX
Store X to memory
STY
Store Y to memory
LEAX
Load effective address into X
LEAY
Load effective address into Y
Transfer and Exchange Instructions:
EXG X,Y
Exchange X and Y
XGDX
Exchange D with X
XGDY
Exchange D with Y
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Addition and Subtraction Instructions:
ABX
Add B to X
ABY
Add B to Y
Decrement and Increment Instructions:
DEX
Decrement X
DEY
Decrement Y
INX
Increment X
INY
Increment Y
Compare and Test Instructions:
CPX
Compare X to memory
CPY
Compare Y to memory
Stacking Instructions:
PSHX
Push X
PSHY
Push Y
PULX
Pull X
PULY
Pull Y
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Stack Pointer, SP
Load and Store Instructions:
LDS
Load SP from memory
STS
Store SP to memory
LEAS
Load effective address into SP
Transfer and Exchange Instructions:
TSX
Transfer SP to X
TSY
Transfer SP to Y
TXS
Transfer X to SP
TYS
Transfer Y to SP
EXG X,SP
Exchange X and SP
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Decrement and Increment Instructions:
DES
Decrement SP
INS
Increment SP
Compare and Test Instructions:
CPS
Compare SP to memory
CPY
Compare Y to memory
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Condition Code Register
7
6
5
4
3
2
1
0
S X H I N Z V C
Sto p di sab le
X - Interrup t ma sk
Half ca rry
In terrup t m ask
Carry
Overflow
Ze ro
Nega tive
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Introducing the 68HC12
•
•
•
•
From Microprocessors to Microcontrollers
The 68HC12 Registers
Writing Programs for the 68HC12
Addressing Modes
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
; Example 1 - Chapter 1
SUM
DIFF
ORG $800
DW
0
DW
0
ORG $810
EX1
LDD
ADDD
STD
LDD
SUBD
STD
END
#1234
#5678
SUM
#5678
#1234
DIFF
;add 1234+5678
;subtract 5678-1234
as12 chap1a.asm >chap1a.lst
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
chap1a.lst
; Example 1 - Chapter 1
0800
0800 00 00
SUM
0802 00 00
DIFF
0810
EX1
0810 cc 04 d2
0813 c3 16 2e
0816 7c 08 00
0819 cc 16 2e
081c 83 04 d2
081f 7c 08 02
ORG $800
DW
0
DW
0
ORG $810
LDD
ADDD
STD
LDD
SUBD
STD
END
#1234
#5678
SUM
#5678
#1234
DIFF
;add 1234+5678
;subtract 5678-1234
chap1a.s19
S014000046696C653A206368617031612E61736D0A6A
S107080000000000F0
S1130810CC04D2C3162E7C0800CC162E8304D27CC2
S10508200802C8
S9030000FC
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Downloading a .S10 file
using HOST.EXE
C:\WHYP\WHYP12\ASM>host
Terminal host...9600 baud
(Press F10 to check/change COM port)
(Press F6 to download .S19 file)
(Press F4 to download .S19 file with * handshake)
(Press <Esc> to exit HOST)
>load
Enter .s19 filename to download: chap1a.s19
Getting data...
S014000046696C653A206368617031612E61736D0A6A
S107080000000000F0
S1130810CC04D2C3162E7C0800CC162E8304D27CC2
S10508200802C8
S9030000FC
.
Finished downloading...*
>
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
D-Bug12 commands
>md 800 820
0800
0810
0820
00 00 00 00 - 52 00 80 02 - 09 00 28 18 - 90 00 83 00
CC 04 D2 C3 - 16 2E 7C 08 - 00 CC 16 2E - 83 04 D2 7C
08 02 00 00 - 0C 00 40 00 - 42 00 08 00 - 10 00 0C 08
....R.....(.....
......|........|
[email protected].......
>rd
PC
0000
>rm
SP
0A00
X
0000
Y
0000
D = A:B
11:5C
CCR = SXHI NZVC
1001 0000
X
0000
Y
0000
D = A:B
11:5C
CCR = SXHI NZVC
1001 0000
PC=0000 810
SP=0A00 .
>rd
PC
0810
>
SP
0A00
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
>t
PC
0813
0813
>t
SP
X
0A00 0000
C3162E
Y
D = A:B
0000
04:D2
ADDD #$162E
CCR = SXHI NZVC
1001 0000
PC
0816
0816
>t
SP
X
0A00 0000
7C0800
Y
D = A:B
0000
1B:00
STD
$0800
CCR = SXHI NZVC
1001 0000
PC
0819
0819
>t
SP
X
0A00 0000
CC162E
Y
D = A:B
0000
1B:00
LDD
#$162E
CCR = SXHI NZVC
1001 0000
PC
081C
081C
>t
SP
X
0A00 0000
8304D2
Y
D = A:B
0000
16:2E
SUBD #$04D2
CCR = SXHI NZVC
1001 0000
PC
081F
081F
>t
SP
X
0A00 0000
7C0802
Y
D = A:B
0000
11:5C
STD
$0802
CCR = SXHI NZVC
1001 0000
PC
SP
X
Y
D = A:B
CCR = SXHI NZVC
0822 0A00 0000 0000
11:5C
1001 0000
0822 00
BGND
>
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
sum
difference
>mdw 800 810
0800
0810
1B00 115C - 5200 8002 - 0900 2818 - 9000 8300
CC04 D2C3 - 162E 7C08 - 00CC 162E - 8304 D27C
...\R.....(.....
......|........|
>
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Introducing the 68HC12
•
•
•
•
From Microprocessors to Microcontrollers
The 68HC12 Registers
Writing Programs for the 68HC12
Addressing Modes
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Pre-decrement indexed addressing
Before
After
1232
X
56
78
X
1234
MOVW 0,X,2,-X
56
78
56
78
1232
1234
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell
Table 1.3 68HC12 Addressing Modes
Addressing Mode
Inherent
Description
Data location is inherent in instruction
Immediate
Data immediately follows the opcode
Direct
Data is on page zero given by an 8-bit
address ($00-$FF)
Data is in memory given by a
16-bit address ($0000-$FFFF)
Opcode is followed by an 8-bit or 16-bit
relative offset from PC
5-bit, 9-bit, or 16-bit constant offset
from X, Y, SP, or PC
Auto pre-decrement X, Y, or SP
by 1 - 8
Auto pre-increment X, Y, or SP
by 1 - 8
Auto post-decrement X, Y, or SP
by 1 - 8
Auto post-increment X, Y, or SP
by 1 - 8
Add contents of A, B, or D to
X, Y, SP, or PC
Address of data located at 16-bit
constant offset from X, Y, SP, or PC
Address of data located at X, Y, SP, or
PC plus the value in D
Extended
Relative
Indexed
(constant offset)
Indexed
(pre-decrement)
Indexed
(pre-increment)
Indexed
(post-decrement)
Indexed
(post-increment)
Indexed
(accumulator offset)
Indexed-Indirect
(16-bit offset)
Indexed-Indirect
(D accumulator offset)
Examples
INX
DECB
LDAA #$2C
LDD #$1234
STAA $FC
STD $34
STAB $1234
STX $0848
BNE -$2B
LBEQ $0452
LDD -2,X
JSR 0,Y
STAA 1,-X
MOVW 0,X,2,-X
LDAB 1,+Y
STD 2,+X
STD 2,XLDAA 4,YLDD 2,X+
STAA 1,X+
ADDA B,X
STX D,Y
LDAA [0,Y]
JSR [0,Y]
ADDA [D,X]
JSR [D,Y]
Design of Embedded Systems Using 68HC12(11) Microcontrollers - R. E. Haskell