0% found this document useful (0 votes)
54 views

Microcomputer Lecture Note

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Microcomputer Lecture Note

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 144

MICROCOMPUTER HARDWARE

AND SOFTWARE TECHNIQUES


Course content
Elements of digital computer design; Comparison of hardwired versus
programmable digital systems; Block diagram of digital computer and description of
its components , Microcomputer systems: the CPU, memory organization, I/O, and
bus organization and addressing schemes . Microcomputer Systems Architecture:
the Von-Neuman and Harvard Architectures, bus control, instruction execution and
addressing modes . Memory system: static, dynamic, VRAM, and applications.
Memory interfacing and address decoding . Machine codes, assembly language and
high-level language programming, Micro-processors as state machines .
Microprocessor instruction set, format and addressing mode . Microcomputer
interfacing: Input/output, interrupt systems and direct memory access; interfacing
to analogue systems and applications to D/A and A/D converters. System
development tools: simulators, EPROM programming, assemblers and loaders .
Microcontrollers (8051 based, PIC, AVR, Ardiuno, etc.), microcontroller
programming and interfacing, application of microcontrollers in embedded
systems.
Lecture Organization
Lecture 1: Elements of digital computer design
Lecture 2: Microcomputer systems
Lecture 3: Microcomputer Systems Architecture
Lecture 4: Memory systems
Lecture 5: Machine, assembly and high-level programming languages
Lecture 6: Microprocessor instruction set, format and addressing mode
Lecture 7: Microcomputer interfacing
Lecture 8: System development tools
Lecture 9 to 12: Application of microcontrollers in embedded systems
Lecture 1: Elements of Digital Computer Design
What is a digital computer? A digital computer is any device capable of
manipulating binary numbers to produce a desired result. Hence a
number of todays electronic devices and systems could pass for a
digital computer. Example of such are:

Clocks and watches Printers

Music set
Lecture 1: Elements of Digital Computer Design
Calculators
Laptops, i-pads, PDAs,
Smartphones

Car dashboard Airplane cocktail Electric cars


Lecture 1: Elements of Digital Computer Design

• Robots
Lecture 1: Elements of Digital Computer Design
BASIC BUILDING BLOCKS OF A DIGITAL COMPUTER
The digital computer is basically made up of logic gate devices and flip-flops
and their derivatives.

LOGIC GATES DERIVATIVE DIGITAL DEVICES


• AND gate • Adders
• NAND gate • Comparators
• OR gate • Decoders
• NOR gate
• Encoders
• NOT gate
• Multiplexers/Demultiplexers
• EX-OR gate
• EX-NOR gate • Counters
• Registers
Lecture 1: Elements of Digital Computer Design
How are computers built—hardwired or programmable?
Generally, computers are built in two basic ways, either by wired network of
combinational and sequential logic devices, or by the use of program code in a
programmable device.
Hardwired: When functions of a Programmable: When the functions
system are achieved by of a system are achieved by defining
manually wiring hardware them as program code in a
devices together, we say such a programmable device, we refer to
system is “hardwired”. A such a system as programmable. The
hardwired system performs functions of such a system can be
fixed functions that cannot be changed at anytime without
changed without altering the alteration to the hardware design
design.
Lecture 1: Elements of Digital Computer Design
Advantages of hardwired systems Disadvantages of hardwired systems
Functions are not susceptible to Faults are difficult to fix due to
unwanted variations. wiring complexity
Components devices only need They are usually bulky
to be replaced to fix a function They require manual professional
service to fix any error.
They consumes much power
They are expensive to build and
maintain
They occupy large circuitry spaces
Lecture 1: Elements of Digital Computer Design
Merits of a programmable systems Demerits of a programmable system
The hardware are simple to build. Requires experience in
Functions can be changed by programming to build and fix
redefinition in program code. They are susceptible to unwanted
They are not bulky and do not functional changes.
require complex wiring.
They are easily miniaturized
They consume less energy
They are less expensive
Lecture 1: Elements of Digital Computer Design
Designing a Hardwired Digital Clock
Lecture 1: Elements of Digital Computer Design

A divide by 60 logic
Lecture 1: Elements of Digital Computer Design

Hour hand logic


Lecture 1: Elements of Digital Computer Design
Designing a Programmable Digital Clock
Lecture 1: Elements of digital computer design
What are the various components of a digital computer system?
Computer Hardware: Computer hardware refers to all of the physical
components within the system.
This hardware includes all
circuit components in a
computer such as the
memory devices, registers,
and finite state machines.
Lecture 1: Elements of digital computer design
PROGRAM MEMORY
The instructions that are executed by a
computer are held in program memory.
Program memory is treated as read only
memory during execution in order to
prevent the instructions from being
overwritten by the computer. Some
computer systems will implement the
program memory on a true ROM device
(MROM or PROM), while others will use
a EEPROM that can be read from during
normal operation but can only be written
to using a dedicated write procedure.
Lecture 1: Elements of digital computer design
DATA MEMORY
Computers also require data memory, which can
be written to and read from during normal
operation. This memory is used to hold
temporary variables that are created by the
software program. This memory expands the
capability of the computer system by allowing
large amounts of information to be created and
stored by the program. Additionally,
computations can be performed that are larger
than the width of the computer system by
holding interim portions of the calculation (e.g.,
performing a 128-bit addition on a 32-bit
computer). Data memory is implemented with
R/W memory, most often SRAM or DRAM
Lecture 1: Elements of digital computer design
INPUT/OUTPUT PORTS
The term port is used to
describe the mechanism to
get information from the
output world into or out of
the computer. Ports can be
input, output, or
bidirectional. I/O ports can be
designed to pass information
in a serial or parallel format.
Lecture 1: Elements of digital computer design
CENTRAL PROCESSING UNIT
The central processing unit (CPU) is considered
the brains of the computer. The CPU handles
reading instructions from memory, decoding
them to understand which instruction is being
performed, and executing the necessary steps
to complete the instruction. The CPU also
contains a set of registers that are used for
general purpose data storage, operational
information, and system status. Finally, the
CPU contains circuitry to perform arithmetic
and logic operations on data.
Lecture 2:
Microcomputer systems
Lecture 2: Microcomputer systems
• The microcomputer or invariably,
the microcontroller is a system of
advanced technologies interfaced
together for data manipulation in
programable solutions.
• The microcontroller is organized
with the microprocessor as its
CPU, a program memory (ROM), a
data memory (RAM), I/Os and
other peripheral interfaces.
• All components are
interconnected in a system bus
Lecture 2: Microcomputer systems
In more details, the CPU is fired
by a continuous clock signal
generator (oscillator). The
oscillator kickstart the sequence
operations directed by the
program flow or algorithm.
However, the system architecture
differs for different chip
technologies
Intel 8051 architecture
Lecture 2: Microcomputer systems

Microchip
PIC12F617 architecture
Lecture 2: Microcomputer systems
• The CPU
The CPU contains a variety of
registers that are necessary to
execute instructions and hold
status information about the
system
Lecture 2: Microcomputer systems
• Instruction Register (IR)
The instruction register holds the
current binary code of the
instruction being executed. This
code is read from program
memory as the first part of
instruction execution. The IR is
used by the control unit to decide
which states in its FSM to traverse
in order to execute the instruction.
Lecture 2: Microcomputer systems
• Program Counter
The program counter holds the
address of the current instruction
being executed in program memory.
The program counter will increment
sequentially through the program
memory reading instructions until a
dedicated instruction is used to set it
to a new location.
If an instruction is one byte
instruction, then the program
counter will be updated by one (i.e.
PC = PC + 1). Similarly, for two and
three byte instructions, the program
counter will be updated by two (i.e.
PC = PC + 2) or three (i.e. PC = PC +
3) locations respectively.
Lecture 2: Microcomputer systems
• Memory Address Register (MAR)
The memory address register is used to
hold the current address being used to
access memory. The MAR can be loaded
with addresses in order to fetch
instructions from program memory or
with addresses to access data memory
and/or I/O ports.
Lecture 2: Microcomputer systems
• Arithmetic Logic Unit (ALU)
The arithmetic logic unit is the
system that performs all
mathematical (i.e., addition,
subtraction, multiplication, and
division) and logic operations (i.e.,
and, or, not, shifts, etc.). This
system operates on data being held
in CPU registers. The ALU has a
unique symbol associated with it to
distinguish it from other functional
units in the CPU.
Lecture 2: Microcomputer systems
• A deeper look at the ALU
Lecture 2: Microcomputer systems
• Accumulator
The accumulator is an 8 bit buffer register
extensively used in arithmetic, logic, load,
store and input and output operations. All
the arithmetic and logical operations are
performed on the accumulator contents;
i.e. one of the operand is always taken
into the accumulator.

• Control Logic
The control logic acts on the decoded
instructions to generate action signals
for a specified operation.
Lecture 2: Microcomputer systems
• Program Status Word (PSW)
This is a special function register used to hold the various
operational status of the microcomputer.
Lecture 2: Microcomputer systems
Memory Organization
• Data memory (RAM)
The RAM is organized into three
basic sections as shown.
Lecture 2: Microcomputer systems

• Special Function Registers (SFR)


These are a group of registers or
memory locations dedicated for
some special operations.
Lecture 2: Microcomputer systems

• Program memory (ROM)


Depending on the specific
device, the microcontroller
comes with a certain size of
internal ROM (EEPROM,
UVPROM, Flash) and a
mechanism to add external
ROM or use only external
ROM
Lecture 2: Microcomputer systems
• Microcomputer I/O
The microcomputer supports a number
of I/O interfaces to connect external
devices. These I/O are generally referred
to as ports.
Lecture 2: Microcomputer systems
• Microcomputer bus organization
To communicate data round the computer and with other external devices is
the bus. The bus is grouped into data bus, address bus and control bus.

These bus are organized in some


ways depending on the device
technology.
Lecture 2: Microcomputer systems
Lecture 2: Microcomputer systems
Data transfer scheme:
There are several ways to
communicate data in a
computer system. Each of
the method used will fall
under either parallel
transfer, in which a number
of data bits are sent as a
group or under a serial data
transfer mode in which
single bits are streamed at a
very high rate.
Lecture 3:
Microcomputer Systems
Architecture
Lecture 3: Microcomputer Systems Architecture
The Von-Neumann The Von Neumann architecture was first proposed
Architecture by a computer scientist John von Neumann. In this
architecture, one data path or bus exists for both
instruction and data. As a result, the CPU does one
operation at a time. It either fetches an instruction
from memory, or performs read/write operation on
data. So an instruction fetch and a data operation
cannot occur simultaneously, sharing a common bus.
Thus, the instructions are executed sequentially
which is a slow process. To increase the speed,
parallel processing of computer have been
developed in which serial CPU’s are connected in
parallel to solve a problem.
Lecture 3: Microcomputer Systems Architecture
• Single memory to be
shared by both code and
data.
• Processor needs to fetch
code in a separate clock
cycle and data in another
clock cycle. So it requires
two clock cycles.
• Slower in speed, thus
more time-consuming.
• Simple in design.
Lecture 3: Microcomputer Systems Architecture
Advantages and disadvantages of Von Neumann Architecture
Advantages Disadvantages
Less physical space is required than Harvard Shared memory - a defective program can overwrite
another in memory, causing it to crash

Handling just one memory block is simpler and easier Low performance compared to Harvard architecture
to achieve

It is cheaper than Harvard architecture Data bus speed - the CPU is much faster than the data
bus, meaning it often sits idle (Von Neumann
bottleneck)

Memory organization is in the hands of the Serial instruction processing does not allow parallel
programmer execution of program.
Data from memory and from devices are accessed in Fetch rate - data and instructions share the same data
the same way. bus, even though the rate at which each needs to be
fetched is often very different.
Lecture 3: Microcomputer Systems Architecture
Harvard Architecture
The Harvard architecture offers separate
storage and buses for instructions and
data. This architecture has data storage
entirely contained within the CPU, and
there is no access to the instruction
storage as data. The Harvard computer
model have separate memory areas for
program instructions and data using
internal data buses, allowing
simultaneous access to both instructions
and data.
Lecture 3: Microcomputer Systems Architecture

• Separate memories for


code and data
• Single clock cycle is
sufficient, as separate
buses are used to access
code and data.
• Higher speed, thus less
time consuming
• Complex in design.
Lecture 3: Microcomputer Systems Architecture

Comparative View
Lecture 3: Microcomputer Systems Architecture
Advantages and disadvantages of Harvard Architecture

Advantages Disadvantages
The CPU can both read and instruction and The separate buses for instruction and data
perform a data memory access at the same time, fetching lead to more design complexities.
even without cache.

Easier to pipeline, so high performance can be Occupy more circuit space


achieved.
No memory alignment problems. It has a comparative high cost compared to the
Von Neumann
Since data memory and program memory and
stored in different locations, no chances for
accidental corruption of program memory.
Lecture 3: Microcomputer Systems Architecture

Harvard Architecture Systems Von Neumann Architecture


• PIC microcontrollers Systems
• AVR • Intel 8051 series
• ARM
Lecture 3: Microcomputer Systems Architecture
Busses Master Slave °°°

Control Lines
Address Lines
Data Lines
• Fundamental tool for designing and building computer based systems
• divide the problem into independent components operating against a well defined interface
• compose the components efficiently
• Shared collection of wires
• command, address, data
• Communication path between multiple subsystems
• Inexpensive
• Limited bandwidth
• Layers of a bus specification
• mechanical, electrical, signaling, timing, transactions
Lecture 3: Microcomputer Systems Architecture
Processor

A Multi-Bus System NorthBridge Processor Memory Bus


Memory

SouthBridge
Bus
Adaptor I/O Bus
• Separate sets of pins for different functions
Bus I/O Bus
• Memory bus
Adaptor
• Graphics bus (for fast frame buffer)
• I/O buses are connected to the backplane bus
• Advantage:
• Buses can run at different speeds
• Much less overall loading!
Lecture 3: Microcomputer Systems Architecture

What defines a bus?


Transaction Protocol

Timing and Signaling Specification

Bunch of Wires

Electrical Specification

Physical / Mechanical Characterisics


– the connectors
Lecture 3: Microcomputer Systems Architecture
Synchronous and Asynchronous Bus
• Synchronous Bus:
• Includes a clock in the control lines
• A fixed protocol for communication that is relative to the clock
• Advantage: involves very little logic and can run very fast
• Disadvantages:
• Every device on the bus must run at the same clock rate
• To avoid clock skew, they cannot be long if they are fast
• Asynchronous Bus:
• It does not require clock matching
• It can accommodate a wide range of devices
• It can be lengthened without worrying about clock skew
• It requires a handshaking protocol
Lecture 3: Microcomputer Systems Architecture

Asynchronous handshaking
process to transfer the data
from the microprocessor to I/O
device.

Asynchronous handshaking
process to transfer the data
from the I/O device to
microprocessor
Lecture 3: Microcomputer Systems Architecture

Bus Transaction

• Arbitration: Who gets the bus


• Request: What do we want to do
• Action: What happens in response
Lecture 3: Microcomputer Systems Architecture
Arbitration: Obtaining Access to the Bus
Control: Master initiates requests
Bus Bus
Data can go either way
Master Slave
• One of the most important issues in bus design:
• How is the bus reserved by a device that wishes to use it?
• Chaos is avoided by a master-slave arrangement:
• Only the bus master can control access to the bus: It initiates and controls all bus
requests
• A slave responds to read and write requests
• The simplest system:
• Processor is the only bus master
• All bus requests must be controlled by the processor
• Major drawback: the processor is involved in every transaction
Lecture 3: Microcomputer Systems Architecture
ADDRESSING MODES
This specifies:
 Where operand is located
 How to reach the operand
location
The operand may be located
as:
• Immediate data as part of
the instruction
• Data stored in one of the
registers
Data stored in memory
Lecture 4:
Memory systems
Lecture 4: Memory systems
Memory Array: Memory cells
are arranged in rows and
columns forming a group of
cells or an array
Lecture 4: Memory systems
• Memory Address and Capacity
The number of bits that a semiconductor
memory chip can store is called chip
capacity. It can be in units of Kbits
(kilobits), Mbits (megabits), and so on

This must be distinguished from the storage capacity of


computer systems. While the memory capacity of a
memory IC chip is always given bits, the memory capacity of
a computer system is given in bytes
 16M of memory in a chip – 16 megabits
 A computer comes with 16M memory – 16 megabytes
Lecture 4: Memory systems
• A memory chip contain location, where x is the number of address pins.
• Each location contains y bits, where y is the number of data pins on the
chip.
• The entire chip will contain × y bit
One of the most important characteristics of a memory chip is the speed at
which its data can be accessed.
To access the data, the address is presented to the address pins, the READ
pin is activated, and after a certain amount of time has elapsed, the data
shows up at the data pins.
The shorter this elapsed time, the better, and consequently, the more
expensive the memory chip.
The speed of the memory chip is commonly referred to as its access time
Lecture 4: Memory systems

Class work
1. A given memory chip has 12 address pins and 4 data pins. Find: (a)
The organization, and (b) the capacity.
2. A 512K memory chip has 8 pins for data. Find: (a) The organization,
and (b) the number of address pins for this memory chip.
Lecture 4: Memory systems
Basic Memory Operation
A memory cell is an a
semiconductor device that
can hold a “0” or a “1” as a
bit. This bit can be stored
or retrieved from the cell
by applying a “Write” or
“Read” control signal while
activating it with a “Select”
signal.
Lecture 4: Memory systems
The Read/Write action can be
applied to a group of cells at a
time.
Lecture 4: Memory systems
Types of Semiconductor Memory
Lecture 4: Memory systems
Lecture 4: Memory systems
• RAM - Random Access Memory: As the names suggest,
the RAM is a form of semiconductor memory technology
that is used for reading and writing data in any order as it
is required.
• It is used for such applications as the computer or
processor memory where variables and other stored and
are required on a random basis. Data is stored and read
many times to and from this type of memory.
• Random access memory is used in huge quantities in
computer applications as current day computing and
processing technology requires large amounts of
memory to enable them to handle the memory hungry
applications used today.
Lecture 4: Memory systems
• Types of RAM
• SRAM
- Asynchronous RAM
- Synchronous Burst RAM
• DRAM
-Fast Page Mode DRAM
- Extended Data Out DRAM
- Burst EDO DRAM
- Synchronous DRAM
Lecture 4: Memory systems
Static Random Access Memory (SRAM)
• Static Random Access Memory. This form of semiconductor memory
gains its name from the fact that data stored does not need to be
refreshed dynamically.
• These semiconductor devices are able to support faster read and write
times typically 10ns, and in addition its cycle time is much shorter
because it does not need to pause between accesses.
• However SRAM chips consume more power, they are less dense and
more expensive than DRAM. As a result of this SRAM is normally used
for caches, while DRAM is used as the main semiconductor memory
technology.
Lecture 4: Memory systems
SRAM basics
• There are two key features to SRAM:
1. The data is held statically: This means that the data is held in the
semiconductor memory without the need to be refreshed as long as the
power is applied to the memory.
2. SRAM memory is a random access memory: A random access memory is
one in which the locations in the semiconductor memory can be written
to or read from in any order, regardless of the last memory location that
was accessed.
The circuit for an individual SRAM memory cell comprises typically four
transistors configured as two cross coupled inverters. In this format the
circuit has two stable states, and these equate to the logical "0" and "1"
states.
The transistors are MOSFETs because the amount of power consumed by
MOS circuit is considerably less than that
Lecture 4: Memory systems

• Static RAM (SRAM)


Lecture 4: Memory systems
• Dynamic RAM is a form of random access memory.
DRAM uses a capacitor to store each bit of data, and
the level of charge on each capacitor determines
whether that bit is a logical 1 or 0.
• However these capacitors do not hold their charge
indefinitely, and therefore the data needs to be
refreshed periodically.
• DRAM is the form of semiconductor memory that is
often used in equipment including personal computers
and workstations where it forms the main RAM for the
computer.
Lecture 4: Memory systems
• Dynamic RAM (DRAM)
In simple terms, the DRAM bit consist of
capacitor that is charged or discharged through a
semiconductor transistor.
Lecture 4: Memory systems

• Main memory is stored in DRAM cells that have much


higher storage density

• DRAM cells lose their state over time – must be refreshed


periodically, hence the name Dynamic

• DRAM access suffers from long access time and high


energy overhead

• Since the pins on a processor chip are expected to not


increase much, we will hit a memory bandwidth wall

72
Lecture 4: Memory systems
ROM - Read Only Memory:
• A ROM is a form of semiconductor memory technology
used where the data is written once and then not
changed. In view of this it is used where data needs to
be stored permanently, even when the power is
removed
• As a result, this type of semiconductor memory
technology is widely used for storing programs and data
that must survive when a computer or processor is
powered down. For example the BIOS of a computer will
be stored in a ROM.
• As the name implies, data cannot be easily written to
ROM. Depending on the technology used in the ROM,
writing the data into the ROM initially may require
special hardware. Although it is often possible to change
the data, this gain requires special hardware to erase
the data ready for new data to be written in.
Lecture 4: Memory systems
Types of ROM
Lecture 4: Memory systems
Mask ROM
Mask ROM is a type of read-only memory, or ROM, that is
masked off during production. "Mask" refers to parts of an
integrated circuit, a thin electronic circuit for processing
data, that is covered with opaque plates called photomasks.
These plates contain transparencies, or holes, to allow light
in certain areas while blocking light in others to create
distinctive patterns.
Mask work, comprising a process known as
photolithography, primarily serves as a sort of intellectual
property protection, reserving reproduction of the product
to the integrated circuit manufacturer.
Data stored in a Mask ROM cannot be altered by the user. If
it can, the process would be difficult or slow. Thus, Mask
ROM is primarily distributed as firmwire—software, or
coded instructions—permanently stored in ROM.
Lecture 4: Memory systems
Programmable Read Only Memory (PROM)
• Programmable Read Only Memory is a form of
semiconductor memory which can only have data
written to it once - the data written to it is permanent.
These memories are bought in a blank format and
they are programmed using a special PROM
programmer.
• Typically a PROM will consist of an array of fuseable
links some of which are "blown" during the
programming process to provide the required data
pattern.
Lecture 4: Memory systems
Erasable Programmable ROM (EPROM or UVPROM)
• Erasable Programmable Read Only Memory devices
can be programmed and then erased at a later time.
This is normally achieved by exposing the
semiconductor device itself to ultraviolet light.
• When the UVPROM is in use, this window is normally
covered by a label, especially when the data may
need to be preserved for an extended period. These
devices are not widely used at present as more
convenient forms of semiconductor memory are now
available.
Lecture 4: Memory systems
Electrically Erasable Programmable Read Only Memory,
EEPROM
• Electrically Erasable Programmable Read Only Memory is a
form of semiconductor memory where data can be written
to the memory device and it can be erased using an
electrical voltage. This erase voltage is typically applied to a
special erase pin on the chip.
• Like other types of PROM, EEPROM retains the contents of
the memory even when the power is turned off. Also like
other types of ROM, EEPROM is not as fast as RAM.
Lecture 4: Memory systems
Flash memory
• Flash memory is a particularly widespread form of
semiconductor memory. It is used in memory cards, and
increasingly for computer solid state hard drives and similar
applications.
• Flash memory may be considered as a development of
EEPROM technology. Data can be written to it and it can be
erased, although only in blocks, but data can be read on an
individual cell basis.
• To erase and re-programme areas of the chip, programming
voltages at levels that are available within electronic
equipment are used. It is also non-volatile, and this makes it
particularly useful. As a result Flash memory is widely used in
many applications including USB memory sticks, compact
Flash memory cards, SD memory cards and also now solid
state hard drives for computers and many other applications.
Lecture 4: Memory systems

Interfacing a RAM to a
microcontroller
• For more data space.
• Better operational speed.
• To process information faster
Lecture 4: Memory systems

Interfacing an external
ROM/EPROM to a
microcontroller
• To increase program space.
• To store more information
permanently
Lecture 4: Memory systems

Interfacing both external data and program memories


Lecture 4: Memory systems

Code interface
Addressing
instruction
Lecture 4: Memory systems
Lecture 5:
Machine, assembly and high-level
programming languages
Lecture 5: Machine, assembly and high-level
programming languages
Computer Program

A computer program is a sequence


of instructions written for the
computer to follow in order to
perform a task.
These instructions appear to the
computer in their binary form which
the computer can interpret.
Lecture 5: Machine, assembly and high-level
programming languages
Programming Languages
Like human instructions, computer
instructions are coded in different
languages.
Computer programming languages
exist in some hierarchy that spell how
close it is to the computer hardware.
Lecture 5: Machine, assembly and high-level
programming languages
Language Level
Programming languages are
literarily grouped into low-
level and high-level languages.
Low-level languages are closer
to the computer hardware but
communicate poorly with
human interface.
High-level languages are more
human friendly but abstract
the hardware from the
programmer.
Lecture 5: Machine, assembly and high-level
programming languages
Machine Language
Is a collection of binary digits or
bits that the computer reads and
interprets. Machine language is
the only language a computer
can understand.
Machine language structure
differs from one device
architecture to another.
Lecture 5: Machine, assembly and high-level
programming languages
An example of a machine code
program for adding 1234 and
4321 is shown 
Machine language is a direct
manipulation of computer
hardware.
Lecture 5: Machine, assembly and high-level
programming languages
Advantages of ML Disadvantages of ML
• The machine language does not • The main drawback of machine
language is difficulty in developing,
need to be translated since it is learning, and algorithms translation.
already written in binary.
• It is time-consuming to fix flaws and
• The CPU directly executes the mistakes in codes and programs.
machine language instructions. • Machine language coding requires a
• Machine language programs significant amount of time.
and code run very fast because • It is difficult to change.
they are in binary format. • It's hard to recall instructions in
numerical form, resulting in mistakes.
• In machine language, directives
and instructions are given using • The machine language codes are
unique and cannot be reused.
a series of bits, where 0 denotes
a false, and 1 denotes a true. • Learning and using machine language
is a complicated programming task.
Lecture 5: Machine, assembly and high-level
programming languages
Assembly language
Uses mnemonics to represent
the machine code instructions
and other features.
An Assembly language program
consists of a series of lines of
Assembly language instructions.
Assembly language is referred
to as a low-level language as it
deals directly with the internal
structure of the CPU.
Lecture 5: Machine, assembly and high-level
programming languages
Program Conversion
Assembly language program
is written in mnemonics
which the computer do not
understand. Therefore there
is need to translate the
codes to machine code
which the computer can
read. A special program
called Assembler is use.
Lecture 5: Machine, assembly and high-level
programming languages
Advantages of ALP Advantages of ALP
• They generate small and compact • It is machine-dependent.
execution modules.
• The code can be lengthy in comparison
• They have more control over hardware to high-level languages.
in comparison to high-level languages.
• They generate executable modules and • The program code is error-prone (likely
run faster compared to high-level to generate errors).
languages. • Writing the program can take a lot of
• It is easier to read and remember time and can be complex.
compared to a machine language • The syntax is difficult to remember.
program.
• Efficient memory management. • Programs cannot be transferred
between computers of different
• It is not necessary to keep track of makes.
memory locations.
• It requires a special program to
• The speed is faster compared to high- translate the source code to machine
level languages. code.
• Oriented towards hardware, it is
hardware mapped.
Lecture 5: Machine, assembly and high-level
programming languages
High-level Language
High-level programming languages use human
language-like and mathematical operators to
instruct the computer instead of mnemonic,
making programming easily accessible to the
programmer.
High-level languages are either procedural or
object-oriented and have numerous advantages
over assembly and machine languages.
Examples of these languages are:
C/C++, Fortran, Java, Visual Basic, Python, and so
on
Lecture 5: Machine, assembly and high-level
programming languages
High-level Program Conversion
Compilation  Compiler
(Interpretation  Interpreter)
Assemble  Assembler
The source code is passed on to a special
software code converter to translate the
High-level code into an object code
(machine code) or an internal
representation.
The internal form of the source code is a
semblance of pseudocode (Assembly
code) and is further converted to its
object code (machine code) equivalent by
an assembler
Lecture 5: Machine, assembly and high-level
programming languages
Debugging:
Debugging is the process of detecting and
removing existing and potential errors
(called ‘bugs’) in a software code that can
cause the target system to behave
unexpectedly or crash. To prevent incorrect
operation of a system, debugging is used to
find and resolve bugs or defects.
When various subsystems or modules are
tightly coupled, debugging becomes harder
as any change in one module may cause
more bugs to appear in another.
When not properly carried out, it could take
more time to debug a program than to
write the code.
Lecture 5: Machine, assembly and high-level
programming languages
Microcontroller as a state machine
A Finite State Machine (FSM) is a
computational structure in which the
next state is determined only by the
previous state, the present inputs
and the transition model of the
machine.
Lecture 5: Machine, assembly and high-level
programming languages
• A FSM is a model to solve a complex
computational problem, and it
comprises a finite number of states.
States are nothing but different
conditions to be attained within the
solution scope.
• Since states are finite, there is a finite
number of transitions among the
states. Transitions are triggered by
the incidents or input events fed to
the state machine. An FSM is an
event-driven reactive system.
Lecture 5: Machine, assembly and high-level
programming languages
Advantages of FSM
• It models the lifecycle of a reactive object through interconnections of
states.
• FSMs are helpful in modelling complex problems into a set of simple
connected events.
• State machines are visualized through state machine diagrams in the form
of state charts, which helps to communicate between non-developers and
developers.
• FSM makes it easier to visualize and implement changes to
the behaviour of the system.
• Easy debugging and easy code maintenance.
• Scalable
Lecture 6:
Microprocessor instruction set,
format and addressing mode
Lecture 6: Microprocessor instruction set, format
and addressing mode
INSTRUCTION SET
• An instruction set is a group of commands for controlling a CPU in machine code.
The term can refer to all possible instructions for a CPU or a subset
of instructions to enhance its performance.
• All CPUs have instruction sets that enable directing the CPU to switch the
relevant transistors to perform certain tasks. Some instructions are
simple read, write and data transfer commands that direct data to different
hardware elements.
• The instructions are made up of a specific number of bits. For instance, The CPU's
instructions might be 8 bits, where the first 4 bits make up the operation code
that tells the computer what to do. The next 4 bits are the operand, which tells
the computer the data that should be used.
• The length of an instruction set can vary from as few as 4 bits to many hundreds.
Different instructions in some instruction set architectures (ISAs) have different
lengths. Other ISAs have fixed-length instructions.
Lecture 6: Microprocessor instruction set, format
and addressing mode
Types of instruction sets
The various types of instruction sets include the following:
• Complex instruction set computer (CISC): processors have an additional
microcode or microprogramming layer where instructions act as small programs.
Programmable instructions are stored in fast memory and can be updated. More
instructions are included in CISC instruction sets than in other types of instruction
sets.
A single instruction can initiate multiple actions by the computer, such as a
single Add command launching multiple memory access load and store
instructions.
• Reduced instruction set computer (RISC): architecture has hard-wired control. It
does not require microcode, but has a greater base instruction set. RISC also uses
a smaller and more compact instruction set with a fixed instruction format. RISC
processors are designed to process faster and more efficiently.
Lecture 6: Microprocessor instruction set, format
and addressing mode
The 8051 Microcontroller Instruction Set
The 8051 family of Microcontrollers are 8-bit processors, and the
Instruction Set is optimized for 8-bit control applications. As a typical 8-
bit processor, the 8051 Microcontroller instructions have 8-bit
Opcodes. As a result, the instruction set can have up to 28 = 256
Instructions.

Table 6.1 shows the 8051 Instruction Set Groups and Instructions in
each group. There are 49 Instruction Mnemonics in the 8051
Microcontroller Instruction Set and these 49 Mnemonics are divided
into five groups.
Lecture 6: Microprocessor instruction set, format
and addressing mode
DATA TRANSFER ARITHMETIC LOGICAL BOOLEAN PROGRAM
BRANCHING
MOV ADD ANL CLR LJMP
MOVC ADDC ORL SETB AJMP
MOVX SUBB XRL MOV SJMP
PUSH INC CLR JC JZ
POP DEC CPL JNC JNZ
XCH MUL RL JB CJNE
XCHD DIV RLC JNB DJNZ
DA A RR JBC NOP
RRC ANL LCALL
SWAP ORL ACALL
CPL RET
RETI
JMP
Lecture 6: Microprocessor instruction set, format
and addressing mode
Instruction Format
Let us see the structure of the 8051 Microcontroller Instruction. An 8051
Instruction consists of an Opcode (Operation – Code) followed by Operand(s) of
size Zero Byte, One Byte or Two Bytes.
The Op-Code part of the instruction contains the Mnemonic, which specifies the
type of operation to be performed. All Mnemonics or the Opcode part of the
instruction are of One Byte size.
The Operand part of the instruction defines the data being processed by the
instructions. The operand can be any of the following:
• No Operand
• Data value
• I/O Port
• Memory Location
• CPU register
Lecture 6: Microprocessor instruction set, format
and addressing mode
There can be multiple operands and the format of instruction is as
follows:

MNEMONIC {DESTINATION OPERAND}, {SOURCE OPERAND}

A simple instruction consists of just the opcode.


Example: NOP  no operand
Other instructions may include one or more operands.
Example: CPL A  one operand
Example: MOV R0,37h  two operand

Instruction can be one-byte instruction, which contains only opcode, or


two-byte instructions, where the second byte is the operand or three-byte
instructions, where the operand makes up the second and third byte.
Lecture 6: Microprocessor instruction set, format
and addressing mode
Addressing Modes
An Addressing Mode is a way to locate an Operand (target Data). The
8051 Family of Microcontrollers allows five types of Addressing Modes
for addressing the Operands. They are:
• Immediate Addressing
• Register Addressing
• Direct Addressing
• Register – Indirect Addressing
• Indexed Addressing
Lecture 6: Microprocessor instruction set, format
and addressing mode
• Immediate Addressing
In Immediate Addressing mode, the operand, which follows the Opcode, is a
constant data of either 8 or 16 bits. The name Immediate Addressing came
from the fact that the constant data to be stored in the memory immediately
follows the Opcode.
The constant value to be stored is specified in the instruction itself rather
than taken from a register. The destination register to which the constant
data must be copied should be the same size as the operand mentioned in
the instruction.
Example: MOV A, #30H
Here, the Accumulator is loaded with 30 (hexadecimal). The # in the operand
indicates that its a data and not the address of a Register.
Immediate Addressing is very fast as the data to be loaded is given in the
instruction itself.
Lecture 6: Microprocessor instruction set, format
and addressing mode
• Register Addressing
In the Memory Organization section,
we have seen the organization of RAM
and four banks of Working Registers
with eight Registers in each bank.
In Register Addressing mode, one of
the eight registers (R0 – R7) is
specified as Operand in the
Instruction.
Example: MOV A, R5
Here, the 8-bit content of the Register
R5 is moved to the Accumulator.
Lecture 6: Microprocessor instruction set, format
and addressing mode
• Direct Addressing
In Direct Addressing Mode, the address of
the data is specified as the Operand in the
instruction. Using Direct Addressing
Mode, we can access any register or on-
chip variable. This includes general-
purpose RAM, SFRs, I/O Ports, and Control
registers.

Example: MOV A, 47H

Here, the data in the RAM location 47H is


moved to the Accumulator.
Lecture 6: Microprocessor instruction set, format
and addressing mode
• Register Indirect Addressing
In the Indirect Addressing Mode or Register Indirect
Addressing Mode, the address of the Operand is
specified as the content of a Register. This will be
clearer with an example.

Example: MOV A, @R1

The @ symbol indicates that the addressing mode is


indirect. If the content of R1 is 56H, for example,
then the operand is in the internal RAM location
56H. If the contents of the RAM location 56H is 24H,
then 24H is moved into the accumulator.
Only R0 and R1 are allowed in Indirect Addressing
Mode. These registers in the indirect addressing
mode act as Pointer registers.
Lecture 6: Microprocessor instruction set, format
and addressing mode
• Indexed Addressing Mode
With Indexed Addressing Mode, the effective
address of the Operand is the sum of a base
register and an offset register. The Base
Register can be either Data Pointer (DPTR) or
Program Counter (PC) while the Offset register
is the Accumulator (A).
In Indexed Addressing Mode, only MOVC and
JMP instructions can be used. Indexed
Addressing Mode is useful when retrieving
data from look-up tables.

Example: MOVC A, @A+DPTR

Here, the address for the operand is the sum of


the contents of DPTR and Accumulator.
Lecture 7: Microcomputer
Interfacing
Lecture 7: Microcomputer Interfacing
• Interfacing with LEDs

a. Anode driven (interface 1)


Vp = Vd + IpR
 High (logic 1)
b. Cathode driven (interface 2)
Vcc = IpR + Vd
 Low (logic 0)
Lecture 7: Microcomputer Interfacing
• Interfacing with LEDs
The LED can be connected to any
I/O pin of the microcontroller.
However, depending on the
controller in use, some I/O pins may
require software configuration as an
output pin before use. This is
because some I/O pins of the
microcontroller are use for multiple
functions.
Lecture 7: Microcomputer Interfacing
• Interfacing with buttons
Buttons or switches are very handy when
building applications that requires external
input from a user. The button at as a unit
input point for Human-Machine Interface
(HMI). These mechanical devices comes in
different types as
Press-to-make
Press-to-release
Single-pole Single-Throw
Single-pole Double-Throw
Single-pole Multiple-Throw
Interfacing these devices may require hard
or soft debouncing to remove any
generated noise and shape the signal for
appropriate response.
Lecture 7: Microcomputer Interfacing
LED Matrix
• Interfacing with LED
Matrix
The LED matrix is a group of LEDs
connected in rows and columns
in which each LED in the matrix
can be powered by a unique
address. By presenting these
addresses at a very fast rate (a
representation of scanning in
CRT), different patterns can be
created on the matrix.
Lecture 7: Microcomputer Interfacing
Interfacing with LED Matrix
LED matrices can be cascaded to
make a larger matrix for more
information representation.
Lecture 7: Microcomputer Interfacing
• Interfacing with 7-Segment
Display
The 7-segment display is a common
device for the presentation of basically
Arabic numerals from 0 to 9. It is made
up of seven LEDs connected either in
common anode or common cathode
form.
The 7-segment can however be
configured to present few other
characters as desired
Lecture 7: Microcomputer Interfacing
• Interfacing with 7-Segment Display
A number of these devices can be connected and
accessed in a single bus to fit the desired application
Lecture 7: Microcomputer Interfacing
• Interfacing with a Relay device

• Relays are electromechanical devices that


enable the interfacing and control of high
current and voltage loads by small voltage
circuits such as a microcontroller.
Lecture 7: Microcomputer Interfacing
• Interfacing with the keyboard
The keyboard (or keypad) is a matrix of press-to-
make buttons and forms a very important HMI. Each
button in the matrix is used to generate a specific
code that can be read by the processor to perform
an assigned function. Standard keyboards come
with a decoder that helps to convert each button
press to its equivalent ASCII code.
Lecture 7: Microcomputer Interfacing
• Interfacing with the keyboard
Lecture 7: Microcomputer Interfacing
• Interfacing with an LCD
Liquid Crystal Display (LCD) is an
important HMI device that is used to
visualize operations and outputs of the
processing system.
The LCD comes in different shapes and
sizes used for alphanumerical and
graphical displays.
General alphanumeric LCDs present a
varying number of characters in a number
of lines. A 16 X 2 LCD for example can
present 16 characters in two separate
lines. There are also application-specific
LCDs targeted for a product.
Graphic LCDs are much more complex and
can be used to present any desired shape
of any size and in any position within the
screen space.
Lecture 7: Microcomputer Interfacing
• Interfacing with an LCD
Lecture 7: Microcomputer Interfacing

• Interfacing with a Programmable


Peripheral Interface (PPI)

Sometimes your application may


demand more I/O pins than what is
provided on the microcontroller. In
such a situation, a bus expander can
be used. The 8255 PPI chip can
expand one port of the
microcontroller into four I/O ports.
Lecture 7: Microcomputer Interfacing
Lecture 7: Microcomputer Interfacing
• Interfacing with an ADC (ADC0804)
When analogue signals are to be measured for the
purpose of control or process manipulation, an ADC
will be needed as the microcontroller is purely a
digital machine.
The ADC converts the analogue signal into its
equivalent digital measure depending on the
resolution of the ADC. This resolution is a function of
the number of bits supported by the ADC and its
reference input voltage.
Thus:

Resolution (R)

Where N = number of bits and Vref = reference input


voltage
Lecture 7: Microcomputer Interfacing
.
R

. .
= =
= 0.00502V
= 5.02mV
Therefore,
00000000 = 0V
00000001 = 5.02mV
00000010 = 10.04mV
11111111 = 1.28V
Lecture 7: Microcomputer Interfacing
• Interfacing with a DAC
Sometimes, digital data are
required to be presented in
their analogue form such as in
playing music from a memory
device.
Here, the DAC is applied to
convert the data bits to their
analogue form.
Lecture 7: Microcomputer Interfacing
• Interfacing with a DAC
Lecture 8:
System Development Tools
Lecture 8: System Development Tools
The development of microcomputer
applications requires a number of
tools. These tools are both in
hardware and software form and each
plays a role in the different stages of
the system development. The system
development span from its
abstraction level when the product is
conceived through its design layout,
prototype development, firmware
development, and testing and
validation
Lecture 8: System Development Tools

•Layout Design
Tools required at this level include:
Pen and Paper,
Spreadsheet, and
Graphic design applications such as:
Visio, Corel Draw, Autocad, and so on,
Lecture 8: System Development Tools

•Prototype development
Special digital circuit design and simulation
applications such as:
Proteus, Multisim, and so on are required.
PCB development software
Soldering and desoldering tools
Lecture 8: System Development Tools

•Firmware
Development
Code development and
Debugging IDE
Compiler or Interpreter
or Assembler
Programmer
UV Eraser
Lecture 8: System Development Tools

Programmers
This could be an outboard or onboard type
Lecture 8: System Development Tools

Circuit programming process


Lecture 8: System Development Tools
UV Eraser
This is used when developing with UV-programmable memory chips
Lecture 8: System Development Tools
• Testing and Validation
Logic probe
Logic Analyzer
Oscilloscope
Multimeter
Lecture 8: System Development Tools

Logic Analyzer
This applies when you
need to visualize data
patterns in a group of
I/Os. The analyzer is a
very vital tool in digital
system testing and
analysis.
Lecture 8: System Development Tools
Oscilloscope
This tool though can be used
to check the logic behaviour
of a data line, it is most
essential for analyzing the
analogue characteristic of
the signal.
Lecture 9 to 12:
Application of
microcontrollers in embedded
systems

You might also like