EEE447 Introduction to Microprocessors

bendembarrassΗλεκτρονική - Συσκευές

2 Νοε 2013 (πριν από 3 χρόνια και 10 μήνες)

185 εμφανίσεις

EEE447 Introduction to
Microprocessors

Week 1

Course overview and introduction

Microprocessor, microcontroller
and programming basics

Course objectives


to develop an in
-
depth understanding of


the operation of microprocessors and
microcontrollers


machine language programming


microprocessor interfacing techniques



to be able to use Motorola 68HC11
microcontroller competently


Course objectives


to be able to design and implement
microprocessor
-
based systems in both
hardware and software



Ultimate goal
: to be able to apply this
knowledge to more advanced structures

What we expect of you ...


a desire to learn about microprocessors and
microcontrollers

and their applications



to do some work:


Print the weekly lecture material and read it once
(
www.eee.metu.edu.tr/~cb/eee347
)


Attend the classes and study regularly



Attend
2 mid
term

exams


Attend a f
inal exam


Do the l
aboratory assignments



Outline



Microcontroller

Basics

and

Programming

Concepts




Programming

Model,

Addressing

Modes

and

Instruction

Set



Programming

examples




The

Stack,

Subroutines,

Interrupts

and

Resets



Memory

Concepts

and

Address

Decoding

Outline



Interfacing

Concepts



Parallel

Input/Output



Serial

Communications



Timer

Operations



Analog

to

Digital

Conversion



Data

acquisition

and

control

examples

Common computer organization
(simplified view)




ALU

(Arithmetic

Logic

Unit)

is

a

circuitry,

which

is

capable

of

doing

various

operations

(for

example

ADD,

SHIFT,

AND,

OR,

etc)

on

certain

on
-
chip

registers
.



CPU

(Central

Processing

Unit)

is

the

combination

of

the

control

logic,

associated

registers

and

the

arithmetic

logic

unit
.

Common computer organization
(simplified view)

Memory

Input/Output

(I/O)

ALU

Control

CPU

Common computer organization (1/2)

Common computer organization (2/2)

Computer Buses


Address bus
: carries the address of a
unique memory or input/output (I/O)
device



Data bus
: carries data stored in memory
(or an I/O device) to the CPU or from
the CPU to the memory (or I/O device)



Control bus
: is a collection of control
signals that coordinate and synchronize
the whole system


Block diagram of a typical CPU

CPU Structure


The main functions are


data transfer


arithmetic and logic operations


decision making (instructional flow control)


The register array consists of at least
one accumulator, program counter and
stack pointer


The control unit controls all the
operations in a CPU and basically it
puts the CPU in one of the
fetch
and
execution

phases

Memory (1/2)


The memory in a computer system
stores the data and instructions of the
programs.

Adress
decoder



Storage


Area



Adress
bus

Data
bus

Other signals
(Vcc,Gnd,
CS, etc.)

Memory (2/2)

Main memory types


ROM (read
-
only memory)


programmed permanently at the factory,
cannot be altered


RAM (random
-
access memory)


read and write memory


EPROM (erasable programmable ROM)


nonvolatile, written electrically but erased
optically


EEPROM (electrically ROM)


nonvolatile, both written and erased
electrically

Operation of the CPU (1/2)


Fetch cycle (phase):


The CPU puts the address of the
instruction to be executed on the address
bus. The address info comes from the
program counter (PC) maintained by the
control unit.


The control bus holds the info. for reading
the memory location and the data bus
holds the instruction from the memory
which is stored into the instruction register
(IR)


PC is updated to point to the next
instruction.


Operation of the CPU (2/2)


Execute cycle (phase):


Instruction in the IR is decoded


The required data transfer and the required
logical and arithmetic operation are
performed


The result is written back either to one of
the registers or memory or I/O device


Common operations performed in ALU
are:


addition, subtraction,


logical AND, OR, XOR, NOT


increment, decrement, shift, clear, etc.

Operation of the CPU (2/2)

Detailed Block Diagram

Microcomputer (1/2)


CPU on a single IC microprocessor
(µP)
.


the terms CPU, µP and MPU (microprocessor
unit) are synonymous
.



CPU is the combination of the ALU and
control unit of
any

computer
.


When the CPU is a single IC; it is called a µP
and is
also
referred to as the MPU
.



When the MPU ‘s connected to memory and
I/O, the arrangement becomes a
MICROCOMPUTER
.

Microcomputer (2/2)


Many different MPUs are produced by many
different IC vendors (e.g., Motorola, Intel,
Texas Instruments, Zilog, National
Semiconductors, etc.
).



Major differences are in



word size
,


the number and types of instructions that can be
performed
,


the types of external control signals available
,


the amount of memory that can be addressed
.


Microcontroller


A microcontroller unit (MCU) contains an
MPU, memory, and I/O circuitry on a single
chip.



Such a chip can perform control operations
without the need for any external circuitry.



e.
g.
Motorola
MC68HC11



(
a
lso

a microprocessor in the expanded
multiplexed mode)



e.
g.
Intel 8051

Microprocessor vs microcontroller (1/3)


Microprocessors: high performance, general

purpose “brains” for PCs and workstations


Instruction decode and control, arithmetic/logic

operations, registers, timing, external control


Typical cost: $75
--

$500


Annual demand: 10s of millions


Microcontrollers: devices with high levels of

integration for embedded control


Microprocessor functions plus on
-
chip memory
and

peripheral functions (e.g. ports, timers)


"Swiss army knife" of microprocessor technology


Typical cost: $1
--

$25


Annual demand: billions!

Microprocessor vs microcontroller (2/3)

ALU

Control

Memory

I/O

Peripheral

functions


Address

Data

Control

Microprocessor

Microcontroller

Microprocessor vs microcontroller (3/3)

Not always a clear distinction
:
today’s
m
P

may be
tomorrow’s

m
C


Microprocessor


Includes memory management unit
,
lots of cache


Performance is the most important feature

(cost is
important, but secondary)


Used mainly in desktop machines


Microcontroller


Integrated RAM and ROM
,
no cache


Includes lots of peripherals


Used mainly in “embedded” applications


Often involves real
-
time control


Important features include
:
low cost
,
low power
consumption
,
number of integrated peripherals
,
interrupt response time
,
amount of RAM and ROM

Bottom
-
up view of microcontroller
systems (1/3)

Bottom
-
up view of microcontroller
systems (2/3)

Bottom
-
up view of microcontroller
systems (3/3)

History (1/4) Intel Family


Intel series

History (2/4) Intel Family

History (3/4) Intel Family

4 decades of development and evolution


Intel 4004 (introduced in early 1970s)


4
-
bit words, 4 KB memory address space


2,000 transistors



Clock speed < 1 MHz


Alpha 21264 (late 90’s)


15.2 million transistors


Clock speed near 700 MHz


Pentium III (late 90’s)


64
-
bit data with gigabit memories


28 million transistors


Clock speeds up to 1 GHz

History (4/4) MotorolaFamily

Microcontrollers



Microprocessors

MC6800




68000


16
-
bit

MC6801




68020

MC6805

8
-
bit



68030


32
-
bit

68HC08




68040

68HC11




68060


68HC12

16
-
bit

68HC16


68300


32
-
bit


Microcontroller Use

Microcontroller Applications (1/2)


Pocket pagers

(low
-
power, interprets characters, user interface)


Cameras

(low
-
power, exposure and focus control, user
interface)


"Levelmeter“

(measures angle, audible and visual user
interface)


Keyboard controllers

(scanning, debounce, autorepeat,
diagnostics)


Modems

(one for data transmission, on for command
processing)


Plotters (command interpretation, encoders, motor control)


Color copiers (paper positioning, color exposure, sensors)


Charge card pay phones

(card reading, dialing, carrier access)


Lawn sprinkler controller

(timer, valve control, user interface)


Instrumentation

(user interface, GPIB interface, compute values)


Closed
-
loop engine control

(fuel/air mixture, ignition, pressure
sensing, etc.)


Antilock braking system control

(monitors traction, controls
brake)


Dynamic ride control (adjusts suspension)

Applications (2/2) : Emergency
control system

Comparison


M
otorola HC11


The HC11 family includes a large number of variations, ranging from
single
-
chippers to larger

micros with bank
-
switching support.


Motorola HC12


The HC12 family is the next step up from the HC11, offering better
performance, better memory

management, and more features.


Motorola 6805


The 6805 family is the next step down from the HC11, with more
single
-
chip variations, smaller packages, and lower cost.


Microchip PIC


The devices are readily available, reasonably priced, very fast, and
come in lots of variations. However, the architecture itself is awkward
to say the least, with small memory maps, poor support for compilers,
and byzantine assembly language.


Intel 8051


The 8051 was one of the first microcontroller families, and remains
one of the most commonly

used. The devices are available from
multiple sources, are cheap, have decent tools, and offer a
nice upgrade path to larger and more capable part.

What will you study in EEE347?



MC68HC11 is the MPU choice in EE
E3
47



You will be studying


how it is combined with memory and I/O devices
to produce a 68HC11 based microcomputer, and


how it is programmed to perform various
operations



Note that


most of what you learn about the 68HC11 can be
applied to any other MPU or microcomputer you
may encounter later.

MC68HC11 detailed block diagram

MC68HC11 detailed block diagram

Major features (1/2)


HCMOS Technology (low power / high
speed)



On
-

chip RAM, ROM, EEPROM



Basic core functions of MC6801


improved

instruction set functionality



2 operating modes and 2 test modes



On
-
chip counter / timer



On
-
chip analog
-

to
-

digital conversion



On
-
chip parallel and serial ports



Improved interrupt capabilities than earlier
products

--

supports 21 interrupt vectors

Major features (2/2)


Some fault detection capability for major
errors

(power, illegal instruction, hung
processor)


Available in at least 25 different versions


Different pin counts and packaging


Different amounts/ types of memory


RAM size (192 to 1.25K bytes)


ROM size (4K to 32K bytes)


EEPROM (512 to 2K bytes)


ROM, EPROM, or EEPROM program memory

Memory maps vary from version to version!


Different I/ O capabilities

(number of timers, chip
selects, DMA channels,

A/ D types, etc.)


Modes of operation (1/3)


2 operating modes and 2 test modes


Operating modes



Single chip


No external address and data bus functions


CPU can only access on
-
chip memory


Ports B and C are general purpose parallel I/ O


All software needed to control MCU must be in

internal memory


On reset, execution begins at address $E000


Located in ROM


Modes of operation (2/3)


Expanded multiplexed


External memory and peripheral devices can
be

accessed by time
-
multiplexed address
-

data
bus


Port B used for high byte of address (output)


Port C provides low byte of address (output)
and 8
-
bit data (bi
-
directional)


External address latch is required


Execution begins at address $E000


Modes of operation (3/3)


Test modes


Special bootst
r
ap


On power up or reset, the program in the

bootstrap ROM is executed


CPU waits for a 256
-
byte program segment to

be downloaded through the serial link and

stored starting at address $0000


Execution then begins at address $0000


Permits wide variety of programs to be

downloaded



Special test


Primarily a testing mode for the manufacturer


Overrides some automatic protection
mechanisms
--

risky!


I/O ports



Port A
(8 bits)


Also used for timer



Port D
(6 bits)


Also used for asynchronous (SCI) and
synchronous

serial (SPI) I/O



Port E
(8 bits)


Also used for A/D converter



Port B
(8 bits)


Also used as address in expanded mode


Port C
(8 bits)


Also used as data/ address in expanded mode

Programming languages


Applications programs


User “runs” an existing software package
,
Limited flexibility outside
intended

application


Examples: Excel, Netscape, Word, . . .


High
-
level language (HLL)


User writes programs to perform task(s)


Very flexible, easy to use (once language is learned!)


Examples: C, C++, Java, Fortran


Assembly language


Harder to use than HLLs


Machine and configuration dependent


Requires detailed knowledge of the
m
p
itself and its instruction set


Still used where extremely high performance
,
short

programs are
required


Machine code


Native language of the processor itself


Programs are the actual bytes as stored in memory


Not intended for human consumption

Programming procedure

Source file

Listing file

Object file

Programmer’s model


What features of the processor are
most important to the assembly
-

language programmer?


Register set


Memory organization


Instruction set


Addressing modes

Register set (1/2)


Accumulators


A: 8
-

bit general purpose accumulator


B: 8
-

bit general purpose accumulator


D: Double accumulator (concatenation of A and B
for 16
-

bit operations)



Index registers


X: 16
-

bit index register


Y: 16
-

bit index register


SP: 16
-

bit stack pointer

Stack may be
anywhere in the 64 Kbyte address space

Register set (2/2)


PC: 16
-

bit Program Counter


CCR: 8
-

bit Condition Code Register


H, N, Z, V, C: Arithmetic status bits


S: Stop bit disabled


I: Interrupt mask


X: XIRQ interrupt mask

Register set


Memory (1/4)


On chip memory


ROM (12K bytes)


Factory programmed
,
Special bootstrap ROM




RAM (512 bytes)


Data, stack


Can be used for downloaded code


Low
-
power standby mode


EEPROM (512 bytes)


Programmed and erased on
-
chip


Calibration storage, diagnostic log, critical data

logging, security
data


Can also be used for downloaded code


Off
-
chip memory


EPROM


For prototype development


Windowed and one
-
time programmable

versions

Memory

Map for

HC11E9

(2/4)

Memory (3/4)


Memory map

Memory (4/4)


Example

Instruction set (1/2)


The instruction set specifies the kinds of data transfers and
transformations that can occur in the machine


Instructions can be grouped into 5 broad categories


Data transfers
: instructions that move data to and between
registers


Logical
: instructions that perform logic operations on data
--

AND,
OR, etc.


Arithmetic
: addition, subtraction, increment, etc.


Flow control
: instructions that change the sequence of execution
of a program
--

conditional and unconditional branches, stack
operations, etc.


Input / Output
operations



An instruction generally consists of an opcode and some
operand( s)


HC11 instructions are of different lengths (1
-
5 bytes)

Instruction set (2/2)

Opcodes


1
-

byte opcodes


Most opcodes use just 1 byte


Downward compatible with 6800


2
-

byte opcodes


Most 2
-

byte instructions deal with register Y, which
was not present in the 6800 processor


It takes longer to fetch and execute 2
-

byte opcodes


New instructions use a "pre
-

byte", which signals that
another opcode byte follows:


$18, $1A, or $CD


Ex.


INX $08


INY $18 $08

Instruction format


An instruction is made up of an opcode and a
set of operands


Opcode may be one or two bytes


Instructions may use 0, 1, 2, or 3 operands


Operands may be 1 or 2 bytes


Instruction lengths range from 1 to 5 bytes


Example (assume this is stored at address
$E000):


LDAA #$ FF ; load ACCA with the value $FF


Machine code:


$E000 $86


$E001 $FF

Fetch/execute operation (1/2)

Fetch/execute operation (2/2)

Adressing modes


How does the instruction specify the
location of the data?


6 different addressing modes


Inherent addressing


Immediate addressing


Extended addressing


Direct addressing


Indexed addressing


Relative addressing