physics 413 chapter 1 : introduction to the hcs 12 microcontroller

32
Physics 413 Chapter 1: Introduction to the HCS 12 Microcontroller

Upload: zoie

Post on 24-Feb-2016

33 views

Category:

Documents


3 download

DESCRIPTION

Physics 413 Chapter 1 : Introduction to the HCS 12 Microcontroller. Computer Architecture. What is a Digital Computer ? A computer is essentially a fast electronic calculating machine. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Physics 413Chapter 1: Introduction to the HCS 12 Microcontroller

Page 2: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Computer Architecture

• What is a Digital Computer ? A computer is essentially a fast electronic calculating machine.

• What is a program ? A program is a set of very simple instructions that a computer can understand. Examples of simple instructions are ADD two numbers, Is X > Y?, COPY A into the memory.

• What is Machine Language ? The set of exceedingly simple and primitive instructions that a computer can understand is called the Instruction Set or Machine Language.

Page 3: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Architecture and Organization

• Computer Architecture deals with the design of those components of a computer that are accessible to a programmer. For instance, the Motorola 6800 does not have a MUL instruction but the Pentium does.

• Computer Organization deals with the implementation of the architecture and may be transparent to the programmer. For instance, precisely how is MUL implemented in the hardware?

Page 4: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Levels of Abstraction

• L5 High‑level Language (C++, Java)

• L4 Assembly Language

• L3 Operating System

• L2 Instruction Set Architecture (ISA)

• L1 Microarchitecture Level

• L0 Digital Logic Level

• Transistors

Page 5: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

A Brief History of Computers

• First Generation ‑ Vacuum Tubes ‑ 1945‑1955 ENIAC (Electronic Numerical Integrator and Computer) had 18,000 Vacuum Tubes, 1500 relays and weighed 30 tons

• Second Generation ‑ Transistors ‑ 1955‑65 ‑ PDP ‑8 (DEC)

• Third Generation ‑ IC ‑ 1965‑80 ‑ IBM 360

• Fourth Generation ‑ VLSI ‑ Intel and AMD Processors

Page 6: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Moore’s Law

The number of transistors on a chip doubles every 18 months

Page 7: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

All about microprocessors and microcontrollers

• ROM is where the program that initializes the PC is stored.

• RAM access is fast

• ADDRESS BUS carries the address of RAM, ROM, and other peripherals

• HCS12 has 16 multiplexed address and data lines

• DATA BUS carries data back and forth between the microprocessor and RAM, ROM, and other peripherals.

Page 8: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Memory

• Big Endian: 4 bytes arranged as:0123 (32‑bit word)• Little Endian: 4 bytes arranged 3210 (32‑bit word)

• DRAM Organization• nxn matrix structure is popular for large memory sizes• RAS ‑ Row Address Strobe• CAS ‑ Column Address Strobe• RAS ‑ CAS strategy reduces the number of pins but slows down

access because two addressing cycles are required

• SRAM Fast for cache

Page 9: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

ROM

• ROM

• PROM

• EPROM ‑ UV erasable

• EEPROM ‑ Electrically erasable byte at a time

• FLASH ‑ electrical block erasable ‑ digital film ‑ more like RAM!

Page 10: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

HCS12 Data Sheet

http://www.freescale.com/files/microcontrollers/doc/data_sheet/HCS12DFAMILYPP.pdf

Page 11: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

HCS12 Architecture

X

BA

CCR

PC

SP

A + B = D

Y

Page 12: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Straight-line Programming

In Paris they simply stared when I spoke to them in French ; I never did succeed in making those

idiots understand their own language

Mark Twain , The Innocents Abroad, 1869

Page 13: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

My First Program

CLRA Clears accumulator A ( A = 0 ) INC A This instruction does this: A + 1 A SWI Stop (software interrupt)

Page 14: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Op-codes

Assembly Language Memory Location Op-codes

CLRA 2000 87INCA 2001 42SWI 2002 3F

Page 15: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

My Second Program

LDAA # $ 12ADDA # $ 15

SWI

Page 16: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Object Code . . . Program # 2

Assembly Language Memory Location Op-codes

LDAA # $ 12 2000 862001 12

ADDA # $ 15 2002 8B2003 15

SWI 2004 3F

Page 17: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Addressing Modes

Inherent (implied) : Simplest with no operand. One-byte op-code. Examples: INCA and CLRA

Immediate : Operand specified is immediate (no memory access). Examples: LDAA # $ 12 and ADDA # $ 15

Page 18: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Immediate and Direct Modes

Immediate LDAA # $ 12 Load the hex number 12 op-code 86 12

Direct LDAA $ 12 Load from memory location 0012 op-code 96 12

Page 19: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

My Third Program

Assembly Language Memory Location Op-codes

LDAA # $ 04 STAA $ 15 LDAA # $ 08 ? ? ADDA $ 15 SWI

Page 20: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

My Third Program

Assembly Language Memory Location Op-codes

LDAA # $ 04 2000 86 04 STAA $ 15 2002 97 15 LDAA # $ 08 2004 86 08 ADDA $ 15 2006 9B 15 SWI 2008 3F

Page 21: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Extended Addressing Mode

The extended addressing mode becomes indispensable when memory locations beyond the zero page must be addressed. [This is the case for the HCS12 on the Dragon12 Board in the lab]

Here, as always, an example is worth a thousand words:

LDAA $3C5E Load A from memory location 3C5E

Op-codes B6 3C 5E

Page 22: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Three Trick Questions

What is the outcome of B6 00 2A ?

What is the outcome of LDAA # $ 3C5E ?

What is the outcome of STAB $3C44 ?

Page 23: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Trick Questions . . . Answered!

What is the outcome of B6 00 2A ? Legal but not very smart.

What is the outcome of LDAA # $ 3C5E ? Not Legal

What is the outcome of STAB $3C44 ? O.K. and op-code is F7 3C 44

Page 24: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Index Register

X is a 16-bit register

How are the following three instructions different?

LDX # $ 5C42

LDX $ 5C42

LDX $ 5C

Page 25: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Index Register

LDX #$ 5C42 The number 5C42 is loaded into X

LDX $ 5C42 Numbers from 5C43 and 5C42 loaded

LDX $ 5C Numbers from 005D and 005C loaded

Page 26: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Indexed Addressing Mode

LDAA 0,X loads accumulator A with the contents of the memory location pointed to by the index register X.

LDAA 4,X loads accumulator A with the contents of the memory location pointed to by X+4

Page 27: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Transfer and Exchange!

TFR D,X transfers the contents of D to X

TFR X, B transfers bits 0-7 of X to B

EXG A,B swaps A and B

Page 28: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Move it!

Memory to memory transfer

movb $1000,$2000 copies the (8-bit)contents of memory location $1000 to the memory location $2000

movw 0,X,0,Y copies the 16-bit word pointed to by X to the memory location pointed to by Y.

Page 29: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Examples Galore

ADDA The outcome is A + M A

ADDA # $ 2B 8B 2B

ADDA $ 3C 9B 3C

ADDA $ 5B24 AB 5B 24

Page 30: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Carry Bit in CCR

ADCA The outcome is A + M + C A

Use this instruction when expecting a carry. Incidentally, CLC will clear the carry bit.

Page 31: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

Indexed Addressing Mode

LDX # $ 0050LDAA 0,XADDA 1,X

SWI

Program adds two numbers stored in memory locations 0050 and 0051

Page 32: Physics 413 Chapter 1 :  Introduction to the HCS 12 Microcontroller

D-bug12 Assembler

ASM 2000 Begin assembly at address 2000

End Assembly

LOAD Load S-Records into memory

MD Memory Display

MM Modify Memory

RD Display CPU registers

RM Modify CPU Register Contents

PC 2000 loads 2000 into PC

T Trace (single-step)