Title: EGR 277 – Digital Logic
1Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- Microprocessors
- A microprocessor is essentially a computer on a
single chip. It is also an example of - a complex finite state machine or clocked
sequential circuit. - The first microprocessor was introduced around
1970. - By 1974 the 8-bit Intel 8080 and Motorola 6800
were introduced - By 1978 the 16-bit Intel 8086 and Motorola 68000
were introduced. - Microprocessors have continued to develop to
include current powerful Pentium and other
microprocessors.
Microprocessors versus Microcontrollers Microproce
ssors have continued to develop along two
lines 1) Performance modern computers are
based on powerful microprocessors where the focus
is on speed and processing and storage of large
amounts of data. The general public is most
familiar with this type of microprocessor (such
as Pentiums). 2) Integration smaller
microprocessors that include built-in memory and
interface circuitry, or microcontrollers, are
often integrated into applications, such as
appliances, vehicles, equipment, etc. The focus
here is reduced size, reduced cost, and a reduced
chipset (onboard memory, for example, rather than
separate memory chips). The general public is
less familiar with microcontrollers, although ten
times more microcontrollers are sold than
microprocessors!
2Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- Microcontroller evolution
- Microcontrollers have continued to evolve. Using
Motorola as an example - Recall that in 1974 the Motorola 6800 was
introduced - Later versions included the Motorola 6801, 6802,
and 6808. - In 1985 the Motorola 68HC11 was introduced
(including several versions) - In 1996 the Motorola 68HC12 was introduced.
- July 2004 the Motorola microcontroller division
broke off into a new company Freescale
Semiconductor, Inc
- 68HC11-based applications just to name a few
- Chrysler transmission and engine control modules
- Ford digital instrument cluster
- Jeep Cherokee drive and emissions control
- Chevrolet engine control modules
- Canon cameras
- Motorola phone systems
- AIM portable gas detectors
- StairMasters exercise machines
3Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Freescale Semiconductor, Inc a few words from
their web site (www.freescale.com) Freescale
Semiconductor, Inc. is a global leader in the
design and manufacture of embedded semiconductors
for the automotive, consumer, industrial,
networking and wireless markets. The
privately-held company is based in Austin, Texas,
and has design, research and development,
manufacturing or sales operations in more than 30
countries. Freescale is one of the world's
largest semiconductor companies with 2006 sales
of 6.4 billion (USD). Pervasive
Innovation Freescale may be one of the largest
companies that people touch every day, but have
never heard of. It has shipped more than 17
billion semiconductors, which can be found in
everyday name brands Motorola cell phones
Sony electronics Whirlpool appliances
Logitech keyboards and mice Lifefitness
cardiovascular and strength training equipment
Cisco routers Bose Acoustic Wave radios
Trane heating and cooling equipment
Mercedes, BMW, Ford, Hyundai and General Motors
vehicles Market Leadership Freescale is a leader
in many markets it serves No. 1 in automotive
semiconductors Gartner No. 1 in communications
processors Gartner No. 2 in overall
microcontrollers Gartner No. 2 in digital
signal processors Forward Concepts No. 4 in
wireless handset radio frequency microprocessors
iSuppli Freescale has design, research and
development (RD), manufacturing or sales
operations in more than 30 countries. We have
seven wholly-owned wafer fabs, two assembly and
test sites and a 300-millimeter pilot line and
RD center in Crolles, France, jointly owned with
STMicroelectronics and Philips. Freescale invests
1 billion annually in RD and has 5,500 patent
families. A New Life After more than 50 years as
part of Motorola, Freescale started a new life as
a stand-alone company in July 2004. Since then,
under the leadership of Chairman and CEO Michel
Mayer, the company has focused on improving
financial performance, reenergizing the culture
and building a global brand.
4Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- Microcontroller boards
- Microcontrollers are often available on circuit
boards for learning and building - prototypes of designs. Microcontroller boards
might contain - Microcontroller
- Crystal clock generator
- Power supply (or regulator)
- Input/output connections for downloading
programs, reading keyboard inputs, and displaying
outputs - Connection points the microcontrollers input and
output pins - Additional memory
- 68HC11 Microcontroller Boards just to name a
few - M68HC11EVBU (Motorola Evaluation Board)
- 68HC11F1 by Allen Systems, Inc.
(www.allen-systems.com) - Handy Board developed and licensed by MIT
(www.handyboard.com) - F68HC11 single chip evaluation board by NewMicros
(www.newmicros.com) - MicroStamp11 by Technological Arts, Inc.
(www.technologicalarts.com) used in EGR262 and
in this course
5Lecture 16 EGR 270 Fundamentals of
Computer Engineering
MicroStamp11 The MicroStamp11 is a
microcontroller or microprocessor. It is built
by Technological Arts and is based on the
Motorola 68HC11 microcontroller.
Technological Arts states that the MicroStamp11
is the worlds smallest microcontroller module.
The MicroStamp11 is about the size of a postage
stamp!
6Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- MicroStamp11 Breadboard Setup
- The MicroStamp 11 is easily used on a breadboard
with two modules - MicroStamp11 Module fitted with a 20-pin
connector that plugs into a breadboard - USB-to-MCU Interface Module allows for serial
communication using a USB port on a computer.
The USB connection can also be used to provide
power (5V) to the breadboard. A few wires are
required as shown below.
MicroStamp11 Module
USB-to-MCU Interface Module
7Lecture 16 EGR 270 Fundamentals of
Computer Engineering
MicroStamp11 Features (reference
www.technologicalArts.com)
8Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- Microcontroller Architecture
- A microcontroller includes the following key
elements - CPU (Central Processing Unit)
- Memory
- I/O (input/output) Devices
- These elements communicate with each other via
buses. - Bus - essentially a group of parallel wires like
a parallel cable
9Lecture 16 EGR 270 Fundamentals of
Computer Engineering
More detail is added to each element of
microcontroller as illustrated below
10Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Register a temporary place to store data (to
transfer data, manipulate data, etc.). An 8-bit
register can be easily formed using 8
flip-flops. Special Registers Program Counter
(PC), Stack Pointer (SP), Index Register (IR),
Memory Address Register (MAR), Condition Code
Register (CCR), etc General Purpose Registers
Handy places to store values used in
computations ALU (Arithmetic Logic Unit) -
performs operations such as Add, Subtract, AND,
OR, XOR, complements, etc. The ALU typically has
special registers (sometimes called accumulators)
associated with it. RAM (Random Access Memory)
used as a scratchpad to store variables during
the execution of a program. Data stored in RAM
is lost when the microcontroller is powered down.
ROM (Read Only Memory) - used to store
permanent programs and data. Data stored in ROM
is not erased when the microcontroller is powered
down, so programs that you save will still be in
memory the next time you use the device.
11Lecture 16 EGR 270 Fundamentals of
Computer Engineering
68HC11 Architecture (simplified)
- Notes
- A and B registers (or accumulators) used in
arithmetic operations - Control unit connected to each element via
control bus - External clock connected to each element
12Lecture 16 EGR 270 Fundamentals of
Computer Engineering
68HC11 Registers
Condition Code Register (CCR) Bits in the CCR are
checked for carries, overflows, signs,
interrupts, etc. More on this later. C Carry
from MSB V 2s complement overflow error Z
Zero N Negative I I-Interrupt H Half-Carry
from Bit 3 X X-Interrupt S Stop Disable
13Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Assembly Language Microcontrollers are programmed
by using a precise set of instructions available
in their instruction set. The 68HC11, for
example, has an instruction set that contains
about 150 different instructions (see the
instructors web page for a table that includes
the complete list). Op Code each instruction
has a particular binary code called an op code
that is used to execute the instruction.
Programs written using op codes are written in
machine code. Assembly language programs
written in assembly language use symbols or
letters (mnemonics) to represent op codes so that
they are more readable. Assemblers convert
assembly language programs into machine
code. Example The assembly language instruction
LDAA is used to load the A Accumulator. LDAA
is a mnemonic that represents the op code 86. In
the example below, the hexadecimal number 43 is
loaded into Accumulator A.
14Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Example High-Level Language (HLL) versus
Low-Level Language (LLL) Suppose that we wanted
to store the decimal constants 10, 20, and 30 and
find their sum.
C program A 10 B 20 C 30 Sum A B
C
68HC11 program LDAA 0A Load hexadecimal
0A into register A STAA 01 Store in memory
location M01 LDAA 14 STAA 02 LDAA 1E STAA
03 ADDA 01 Add the contents of M01 to
A ADDA 02 Add the contents of M02 to A STAA
04
15Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Format for 68HC11 instructions In the last
example, each 68HC11 instruction had two parts
the mnemonic for the op code and the operand.
Actually, different 68HC11 instructions may
require 0, 1, or 2 operands. The general form for
any instruction is ltLabelgt op code
lt0, 1, or 2 operandsgt ltcommentgt where lt gt is
used to indicate an optional item. Examples Label
op code operand(s) comments ABA add A and
B and store results in A LDAA 0A load
hexadecimal 0A to contents of reg.
A L1 BRA L1 infinite loop (branch to
L1) STAA 00 FF store A at extended
(2-byte) address M00FF
16Lecture 16 EGR 270 Fundamentals of
Computer Engineering
68HC11 Addressing Modes The operand(s) following
an op code can have different meanings, depending
upon the type of addressing used. There are six
addressing modes for the 68HC11, but we will only
focus on two of them.
Immediate addressing Useful for working with
constants The symbol is used before the
constant Examples LDAA 05 A?05 ADDA 05 A
?A 05
Direct addressing Useful for working with
variables that are stored in memory. Examples LDA
A 05 A?M05 ADDA 05 A ?A M05
17Lecture 16 EGR 270 Fundamentals of
Computer Engineering
68HC11 Instructions The instruction set for the
68HC11 includes about 150 instructions
(mnemonics). Additionally, each mnemonic may be
translated into different op codes by the
assembler depending upon the type of addressing
used. Since the focus of this course is to only
briefly introduce assembly language programming,
we will focus on just a few instruction as listed
below. See the instructors web page for a table
containing the full instruction set.
Only these instructions are needed for
assignments, labs, and tests
Addition ABA, ADDA, ADDB, ABX, ABY Subtraction
SBA, SUBA, SUBB Loading registers LDAA, LDAB,
LDX, LDY Clear registers CLRA, CLRB Storing
register values in memory STAA, STAB, STX,
STY Branching BRA,BEQ,BNE,BGE,BGT,BLE,BLT,BMI,BP
L,BCC,BCS Incrementing values in registers
INCA, INCB, INX, INY Decrementing values in
registers DECA, DECB Logical operations ANDA,
ANDB, ORAA, ORAB 1s complement COMA, COMB 2s
complement (negate) NEGA, NEGB Compare to
memory CMPA, CMPB
18Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Instruction ABA Description Add the contents
of accumulators A and B and store the result in
A Notation A ? A B Example ABA
Instruction ADDA dd or ADDA
aa Description Add the constant dd or the
contents of memory address aa to the current
contents of accumulator A. Notation A ? A dd
or A ? A Maa Examples ADDA 05 A ?
A 05 ADDA 05 A ? A M05 Similar
examples using accumulator B ADDB 06 B ? B
06 ADDB 06 B ? B M06
Instruction SBA Description Subtract the
contents of accumulator B from the contents of
accumulator A and store the result in
A. Notation A ? A - B Example SBA
19Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Instruction SUBA dd or SUBA
aa Description Subtract the constant dd or the
contents of memory address aa from the current
contents of accumulator A. Notation A ? A - dd
or A ? A - Maa Examples SUBA 05 A ?
A - 05 SUBA 05 A ? A - M05 Similar
examples using accumulator B SUBB 06 B ? B
- 06 SUBB 06 B ? B - M06
Instruction LDAA dd or LDAA
aa Description Load the constant dd or the
contents of memory address aa into accumulator
A. Notation A ? dd or A ? Maa
Examples LDAA 05 A ? 05 LDAA 05 A ?
M05 Similar examples using accumulator
B LDAB 06 B ? 06 LDAB 06 B ? M06
20Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Instruction STAA aa Description Store the
current contents of accumulator A at memory
address aa. Notation Maa ? A Examples STAA
05 M05 ? A Similar example using
accumulator B STAB 06 M06 ? B
Instruction INCA Description Increment the
contents of accumulator A Notation A ? A
1 Example INCA
Instruction INCB Description Increment the
contents of accumulator B Notation B ? B
1 Example INCB
Instruction DECA Description Decrement the
contents of accumulator A Notation A ? A -
1 Example DECA
21Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Example Write a program to swap the values
stored in memory locations M10 and M11.
22Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Example Write a program to rotate the values
stored in memory locations M10, M11, and
M12. In other words M10 ? M11 M11
? M12 M12 ? M10
23Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Branching (conditional structures) Branching is
much cruder in assembly language programming than
with high-level languages such as C. Branching
is generally accomplished based on the results of
the Condition Code Register (CCR), which is
called the status register in some
microcontrollers. Bits of the CCR may be set or
cleared based on the results of the last
instruction executed.
Notes on the Condition Code Register (CCR) Some
instructions may explicitly set or clear
condition code bits. We will only focus on
three bits in the CCR Z 1 if the result was
zero, Z 0 otherwise N 1 if the result was
negative, N 0 otherwise C 1 if the result
generated a carry or borrow, C 0 otherwise
24Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Example Determine the values of Z, N, and C as
well as the contents of register A for each case
below after executing the last instruction.
25Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Instruction BRA ltlabelgt Description Branch
Always - Branch always to the label
indicated Example 1 L1 BRA L1 infinite
loop Example 2 L2 ltfirst instruction of main
loopgt ltadditional instructionsgt BRA L2 keep
executing main loop
Instruction BNE ltlabelgt Description Branch
if not equal to zero - Branch to the label
indicated if Z0 in the CCR Example LDAA 00
initialize x to 0 LDAB 05 initialize y to
5 L3 ABA add x and y, store in x DECB
decrement y BNE L3 loop if not
done L4 BRA L4 all done (infinite loop)
So what are the final values in A and B in the
program above? Trace (single step) through the
program to see. Use the table on the following
page.
26Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Trace through the program below using the table
provided LDAA 00 initialize x to 0 LDAB
05 initialize y to 5 L3 ABA add x and y,
store in x SUBB 01 decrement y BNE L3
loop if not done L4 BRA L4 all done (infinite
loop)
27Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Instruction BEQ ltlabelgt Description Branch
if equals 0 - Branch to the label indicated if
Z1 in the CCR Example LDAA 00 initialize x
to 0 LDAB 05 initialize y to 5 L1 ABA
add x and y, store in x SUBA 01 decrement
y BEQ L2 loop to L2 if done BRA
L1 branch always to L1 L2 BRA L2 all
done (infinite loop)
Other branching commands BCC ltlabelgt branch
to label if carry cleared, C 0 BCS ltlabelgt
branch to label if carry set, C 1 BMI ltlabelgt
branch to label if negative (minus), N 1 BPL
ltlabelgt branch if positive (plus), N 0 BGT
ltlabelgt branch if greater than zero BGE
ltlabelgt branch if greater than or equal to
zero BLT ltlabelgt branch if less than zero BLE
ltlabelgt branch if less than or equal to zero
28Lecture 16 EGR 270 Fundamentals of
Computer Engineering
Example Form a simple loop in assembly
language to perform some operation 10 times.
This might be equivalent to the following in
C for (int j 9 j gt0 j--)
// perform operation
29Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- Example Write an assembly language program to
form the sum -
- This could be done easily in C as follows
- int Sum 0
- for (int j A j ltB j) Sum j
- Assume that
- A positive value for A is stored in memory
location M10 - A positive value for B is stored in memory
location M11 - A lt B (i.e., M10 lt M11)
- The result is to be stored in memory location
in M12.
30Lecture 16 EGR 270 Fundamentals of
Computer Engineering
- Example Write an assembly language program to
determine the larger of two numbers. - This could be done easily in C as follows
- if (A gt B) X A
- else X B
- Assume that
- A is stored in memory location M24
- B is stored in memory location M25
- The larger of the two values should be stored
in M26.