EMBEDDED SYSTEMS By: Nikhil Parashar 1
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 1/51
EMBEDDED SYSTEMS
By: Nikhil Parashar
1
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 2/51
Course Contents
• Introduction to HC12 family, Processor Core
Architecture, MC9S12C32 Features, Block
Diagrams, Programming Models, Pin outs and
Signals, System Clock.
• Register Blocks and Memory Mapping, Modes
of Operation
• Addressing Modes and Assembly Language
Programming
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 3/51
Programming Model
• Two index registers (X and Y)
• 16-bit stack pointer (SP)
•
16-bit program counter (PC)• 8-bit condition code résister (CCR)
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 4/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 5/51
Data Types
The CPU12 uses these types of data:
• Bits
• 5-bit signed integers
•8-bit signed and unsigned integers
• 8-bit, 2-digit binary-coded decimal numbers
• 9-bit signed integers
• 16-bit signed and unsigned integers
• 16-bit effective addresses
• 32-bit signed and unsigned integers
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 6/51
Addressing Modes
Addressing modes determine how the central
processor unit (CPU) accesses memory locations to
be operated upon.
•Inherent
• Immediate
• Direct
• Extended
• Relative
• Indexed
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 7/51
Inherent AM
• No operands or all operands are in internal
CPU registers.
• Eg.
NOP ;this instruction has no operands
INX ;operand is a CPU register
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 8/51
Immediate AM
• Eg.
LDAA #$55
LDX #$1234LDY #$67
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 9/51
Direct AM
Sometimes called zero-page addressing
Eg.
LDAA $55LDX $20
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 10/51
Extended AM
The full 16-bit address of the memory location
Eg.
•
LDAA $F03B ; The value from address; $F03B is loaded into the
; A accumulator.
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 11/51
Relative AM
• The relative addressing mode is used only by branchinstructions.
• Short conditional branch instructions
• long conditional branch instructions
• Short branch instructions consist ofan 8-bit opcode and a signed 8-bit offset contained in the
byte that follows the opcode.
• Long branch instructions consist of
an 8-bit prebyte, an 8-bit opcode, and a signed 16-bitoffset contained in the two bytes that follow theopcode.
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 12/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 13/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 14/51
Index AM
Indexed addressing modes use a 16-bit CPU register and
additional information to create an effective address.
• 5-Bit Constant Offset Indexed Addressing
•
9-Bit Constant Offset Indexed Addressing• 16-Bit Constant Offset Indexed Addressing
• 16-Bit Constant Indirect Indexed Addressing
• Auto Pre/Post Decrement/Increment Indexed
Addressing• Accumulator Offset Indexed Addressing
• Accumulator D Indirect Indexed Addressing
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 15/51
Bit Manipulation Instructions
• combination of two or a combination of three
addressing modes.
• BCLR
• BSET
• BRCLR
•
BRSET
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 16/51
Addressing More than 64 Kbytes
• Some M68HC12 devices supports addressing a largermemory space than the standard 64 Kbytes.
• Uses fast on-chip logic to implement a transparentbank-switching scheme.
• HC12 system requires no external glue logic.• Interrupts do not need to be disabled during switching
because switching tasks are incorporated in specialinstructions that greatly simplify program access toextended memory.
• MCUs with expanded memory treat the 16 Kbytes ofmemory space from $8000 to $BFFF as a programmemory window.
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 17/51
• Expanded-memory architecture includes an 8-bitprogram page register (PPAGE), which allows up to 25616-Kbyte program memory pages to be switched intoand out of the program memory window. This provides
for up to 4 Megabytes of paged program memory.• The CPU12 instruction set includes call subroutine in
expanded memory (CALL) and return from call (RTC)instructions, which greatly simplify the use ofexpanded memory space. These instructions also
execute correctly on devices that do not haveexpanded-memory addressing capability, thusproviding for portable code.
Addressing More than 64 Kbytes
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 18/51
• $0000 - $03FF I/O PORTS
• $3800 - $3FFF INTERNAL RAM
•
$4000 - $7FFF INTERNAL EEPROM• $8000 - $9FFF EXTERNAL RAM
• $C000 - $FFFF INTERNAL EEPROM
Addressing More than 64 Kbytes
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 19/51
Instruction Set• Data Transfer Instruction
1. Load & Store Instruction
2. Transfer & Exchange• Arithmetic Instruction
1. Addition & Subtraction
2. BCD Operation
3. Increment/Decrement
4. Multiplication/Division
• Logical Instruction
1. Boolean Logical Instruction
2. Bit Manipulation
3. Shift & Rotate
4. Compare & Test Instructions
• Branch Instruction1. Short conditional branches
2. Long conditional branches
3. Bit-condition branches
4. Loop Primitives
5. Jumps
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 20/51
• Fuzzy Logic Instruction
1. Fuzzy Logic Membership Instruction
2. Fuzzy Logic Rule Evaluation Instructions3. Fuzzy Logic Weighted Average Instruction
• Maximum and Minimum Instructions
• Multiply and Accumulate Instruction
• Table Interpolation Instructions
• Index Manipulation Instructions
• Stacking Instructions
•
Pointer and Index Calculation Instructions• Stop and Wait Instructions
• Background Mode and Null Operations
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 21/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 22/51
• Transfer & Exchange Instructions
MOV Instruction
• AM for MOV Instruction are immediate,extended, and indexed addressing modes.
• The operand of an immediate mode instruction
is data, not an address.
• the operand of an immediate mode instruction is
data, not an address
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 23/51
Transfer & Exchange Instructions
• MOVB ; Move a Byte of Data from
;One Memory Location to Another
• MOVW ; Move a Word of Data from
;One Memory Location to Another
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 24/51
Addition & Subtraction
• ABA ; Add Accumulator B to
;Accumulator A
• ABX ; Add Accumulator B to Index
;Register X
• ABY ; Add Accumulator B to Index
;Register Y
• ADCA ; Add with Carry to A
• ADCB ; Add with Carry to B
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 25/51
• ADDA ; Add without Carry to A
• ADDB ; Add without Carry to B
•
ADDD ; Add Double Accumulator• SBA ;Subtract Accumulators
Addition & Subtraction
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 26/51
BCD OPERATION
• To add binary-coded decimal (BCD) operands,
use addition instructions that set the half-
carry bit in the CCR, then adjust the result
with the decimal adjust A (DAA) instruction.
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 27/51
Increment/Decrement
M lti li ti /Di i i
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 28/51
Multiplication/Division
• Signed and Unsigned 8- and 16-bit multiplication
L i l I t ti
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 29/51
Logical Instructions• Boolean Logical Instructions
The Boolean logic instructions perform a logicoperation between an 8-bit accumulator or
the CCR and a memory value.
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 30/51
Bit Manipulation Instructions
• These uses a mask value to test or change the
value of individual bits in A or in M.
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 31/51
Shift & Rotate Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 32/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 33/51
Compare & Test Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 34/51
Maximum & Minimum Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 35/51
Branching OperationsBranch instructions cause execution flow to change when specific pre-
conditions exist and the changes are categorized as
• Resets,
• Interrupts,
• Subroutine calls,
• Conditional branches, and
• Jumps.
Branch operations can be of the types• Short conditional branches
• Long conditional branches
• Bit-condition branches
Types
Short BranchLong Branch
Bit Condition Branch
Loop Primitives
Jumps
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 36/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 37/51
• BSR and JSR are used to access subroutines in
the normal 64-Kbyte address space.
• The CALL instruction is intended for use in
MCUs with expanded memory capability.
Branching Operations
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 38/51
Short Branch:
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 39/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 40/51
Long Branch
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 41/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 42/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 43/51
Bit Conditional Branch Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 44/51
Loop primitive
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 45/51
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 46/51
Interrupt Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 47/51
Condition Code Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 48/51
Stop & Wait Instructions
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 49/51
Background Mode & Null
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 50/51
• TExaS= Test EXecute & Simulate
8/13/2019 Embedded System Day 6
http://slidepdf.com/reader/full/embedded-system-day-6 51/51
Assembler Directives
Group A Group B Group C Meaning
ORG ORG .ORG Origin of Memory
= EQU Define a constant Symbol
SET Define a constant Symbol
DC.B FCB .BYTE Allocate byte of storage with initialized valueFCC Create an ASCII string
DC.W FDB .WORD Allocate word of storage with initialized value
DC.L .LONG Allocate 32-bitlong word of storage with initialized value
DS.B RMB .BLKB Allocate byte of storage without initialization
DS.W .BLKW Allocate word of storage without initialization
DS.L .BLKL Allocate 32-bit word of storage without initialization
END END .END End of the source code