chapter 1
chapter 1
TO
MICROCONTROLLERS and MICROPROCESSOR
Connect to the world
The microprocessor and its offspring, the microcontroller, were
destined to infiltrate every country, every means of production, and
almost every home in the world.
But what are these microcontroller and microprocessor we are talking
about?
What are their difference?
Why not just use a normal processor and add all necessary
Microprocessor(processor):
microprocessors are integrated circuit (IC) which have only CPU (central processing unit)
inside them.
They don’t have ROM, RAM, Timers, I/O pins etc. they designed to add them externally to
make them functional.
The processor find in applications where tasks are unspecific(or for general tasks) like
developing software, games, website, photo editing, creating documents( ppt, txt, etc.), hence
the relationship between input and output is not defined.
A microprocessor cannot be operated stand-alone, at the very least it requires some memory
and an input and output device to be useful.
They use high amounts resources like; RAM, ROM, I/O pins.
The clock speed of processor is quite high compared to that of microcontrollers i.e. MC from few
MHz to 50MHz, MP operates above 1GHz as they perform complex tasks.
They consist of ALU, control unit and register array to performs all arithmetic and logical operations,
to manage and hands the flow of instructions through the systems, and to store the data from
memory for fast access respectively.
Its applications are desktop, PC’s, laptops, smart phones, etc
A microprocessor is a very small electronic circuit typically 1⁄2 inch (12 mm) across.
To provide electrical connections directly to the circuit would be impractical owing to the size and
consequent fragility, so connecting pins are molded into the case and the microprocessor then plugs
into a socket on the main circuit board.
The size, shape and number of pins on the microprocessor depend on the amount of data that it is
designed to handle.
Microcontroller:
• The microcontroller includes a CPU, RAM, ROM, I/O ports, and timers all embedded on a
single chip like a standard computer which are allow it to operate stand alone, but because
they are designed to execute only a single specific task to control a single system, they are
much smaller and simplified.
• It is brain of computer system which contains enough circuitry to perform specific task that
requires certain degree of control such as TV remote, LED display panel, smart watches,
vehicles, traffic light control, washing machine, etc.
• A microcontroller is an integrated chip that is often part of an embedded system.
• In a microcontroller all that you have to do is to make proper connections of the pins and then
feed a computer program into it.
• After that your microcontroller responds in accordance with the program that has been fed
into it.
• It is more power full, complete computer for specific tasks and requires very small amounts of
RAM, ROM, I/O, etc.
Basic layout of a microcontroller.
Microcontroller Vs Microprocessor
• Both MP and MC are IC(integrated circuit).
• They share many common features
• They found in different versions from (4-100) pins today.
• Both are designed for real-time operations
• Cannot distinguish by looking them
• Comparing MP and MC in terms of cost is not justified, undoubtedly MC is far cheaper than
processor.
• However microcontroller cannot be used in place of microprocessor and using microprocessor
is not advised in place of microcontroller as it makes applications quit costly.
EMBEDDED SYSTEM
An embedded computer is frequently a computer that is implemented for a particular purpose.
Embedded systems usually only have a single task, or a very small number of related tasks that
Automobiles Mouse
Micro
The word micro is used in electronics and science generally, to mean ‘one-millionth’ or 1x10–6.
It has also entered general language to mean something very small like a very small processor
or microprocessor.
Microcontroller Components
1. Processor Core
The processor core (CPU) is the main part of any microcontroller.
It consists of the data path, which executes instructions, and of the control unit, which
basically tells the data path what to do, arithmetic logic unit (ALU), which is used to perform
computations (AND, ADD, INC, . . . ).
Several control lines select which operation the ALU should perform on the input data.
CPU is the brain of the computer system, administers all activity in the system and performs
all operations on data.
It continuously performs two operations: fetching and executing instructions. It understand
and execute instructions based on a set of binary codes called the instruction set.
Basic CPU architecture.
THE BUSES: ADDRESS, DATA, AND CONTROL
A BUS is a collection of wires carrying information with a common purpose.
For each read or write operation, the CPU specifies the location of the data or instruction by
placing an address on the address bus, then activates a signal on the control bus indicating
whether the operation is read or write.
READ OPERATIONS retrieve a byte of data from memory at the location specified and place it
on the data bus. CPU reads the data and places it in one of its internal registers.
WRITE OPERATIONS put data from CPU on the data bus and store it in the location specified
ADDRESS BUS carries the address of a specified location. For n address lines, 2n locations can be
accessed. E.g., A 16-bit address bus can access 216 = 65,536 locations or 64K locations (210 = 1024
= 1K, 26 = 64).
Assume a 24 bit address bus, able to access 16M location. (Note this is not necessarily 16MByte
of memory. Why not?)
The PC, SP, and MAR in our cpu will therefore be 24 bits wide.
DATA BUS –
It carries information between the CPU and memory or between the CPU and I/O devices.
Microcontrollers have data bus widths of 4 bits, 8-bits, 16-bits and 32-bits, while the most
advanced PCs use 64 bits.
If memory width is 16 bits wide means each locations can store 2 bytes data, then the MBR
and AC registers and ALU on the data side has 16 bits size.
If the address bus has been chosen to be 24 bits wide, so the address space is from
0x0 to 224 -1 or 0xFFFFFF in hex.
The data bus is 16 bits wide, and so the contents width is 16 bits. In Fig. for
Example, the contents of address 4 are 0x01FF. The largest (unsigned) integer
number that can be held is 216 -1 or 0xFFFF.
The IR is special. The IR (opcode) part should be wide enough to take the largest
opcode.
We assume the opcode is a fixed 8 bits wide, allowing 256 different instructions
— which is plenty enough.
The IR (address) part has to have the same width as the address bus, 24 bits. So
the whole IR is 32 bits wide.
CPU Registers
MAR -The Memory Address Register is used to store the address to access memory.
MBR -The Memory Buffer Register stores information that is being sent to, or received from, the
memory along the bidirectional data bus.
AC- The Accumulator is used to store data that is being worked on by the ALU, and is the key
register in the data section of the cpu. Notice that the memory can’t access the AC directly. The
MBR is an intermediary.
PC -Connected to the internal address bus, the Program Counter holds the address in memory
of the next program instruction. Notice that it doesn’t connect directly to the memory, but must
go via the MAR. (The PC is special in that it is both a register and a counter).
IR -When memory is read, the data first goes to the MBR. If the data is an
instruction it gets moved to the Instruction Register. The IR has two parts:
1. IR (opcode)- The most significant bits of the instruction make up the opcode.
• This the genuine instruction part of the instruction, that tells the cpu what to do.
The instruction in IR (opcode) gets decoded and executed by the control unit.
2. IR (address)- The least significant bits of the instruction are actually data.
• They get moved to IR (address). As the name suggests they usually form all or
part of an address for later use in the MAR. (However, in immediate addressing
they are sent to the AC.)
CONTROL BUS carries control signals supplied by the CPU to synchronize
the movement of information on the address and data bus
CONTROL DEVICES are outputs, or actuators, that can affect the world
around them when supplied with a voltage or current.
Step 1: The address in the program counter is moved to the memory address register(MAR), as this
is the only register which is connected to address lines of the system bus.
Step 2: The address in MAR is placed on the address bus, now the control unit
issues a READ command on the control bus, and the result appears on the data bus
and is then copied into the memory buffer register(MBR).
Program counter is incremented by one, to get ready for the next instruction.
(These two action can be performed simultaneously to save time)
Step 3: The content of the MBR is moved to the instruction register(IR)
Thus, a simple Fetch Cycle consist of three steps and four micro-operation.
Symbolically, we can write these sequence of events as follows
Executing an instruction
• During the instruction fetch, an opcode is put into the IR (opcode), and is
decoded by the control unit.
• The CU now “knows” which instruction it should execute, and can therefore
output a sequence of Levels and Pulses to set up paths and effect the desired the
register transfers.
Example of LDA x fetch and execute.
• Example of the Fetch and execute of the LDA x instruction with x=5
and starting with PC =2. The steps follow a,b,c, ...,i.
2. Memory
Based on the way the memory is used.
Based on physical properties of the electronic parts the memory is made of.
1. Volatile memory. In this context, volatile means that the contents of the memory are lost as soon
as the system’s power is switched off. Volatile memory can be static or dynamic,
2. Non-volatile memory types:
Unlike volatile memory, non-volatile memories retain their content even when power is cut.
Then why should you use volatile memory at all, when non-volatile memory is readily available?
The problem here is that non-volatile memory is usually a lot slower, more involved to work
with, and much more expensive.
While the volatile memory in your PC has access times in the nanosecond range, some types
of non-volatile memory will be unavailable for milliseconds after writing one lousy byte to
them.
Compare and contrast the following memories in accordance to their functions and
applications
• SRAM (Static Random Access Memory)
• DRAM (Dynamic Random Access Memory)
• ROM (Read Only Memory)
• PROM (Programmable Read Only Memory)
• EPROM (Erasable Programmable ROM)
• EEPROM (Electrically Erasable and Programmable ROM)
• Flash
3. I/O PORTS
Digital I/O
I/O pins are grouped into ports
2. Port Register (PORT): This register is used to control the voltage level of output pins.
Assuming a pin has been configured to output, then if its bit in the PORT register is set, the pin
will be high; if the bit is cleared, the pin will be low.
For output pins, reading the register returns the value you have written.
For input pins, the functionality depends on the controller.
Some controllers allow you to read the state of input pins through the port register.
Other controllers, e.g. the ATmega16, use the port bits for other purposes if the corresponding
pins are set to input, so here you will read back the value you have written to the register.
3. Port Input Register (PIN): The PIN register is generally read-only and contains the current state
(high or low) of all pins, whether they are configured as output or as input.
It is used to read the state of input pins, but it can also be used to read the state of output
pins to verify that the output was taken over correctly.
A write to this register generally has no effect.
Classification of microcontrollers
1. Classification of MCs by architecture.
The single instruction can be executed during one machine cycle using the MC based on
the Harvard architecture.
Most MC families are created using Harvard architecture.
Harvard architecture block diagram
Von-neuman architecture block diagram
2. Classification of MCs by instruction set.
The MCs are divided into two groups by instruction set.
There are MCs that belong to the reduced instruction set computer (RISC) group and MC that
belong to the complex instruction set computer (CISC) group.
Majority of Microcontrollers are based on the RISC ideology.
CISC ideology is mostly used in microprocessors.
RISC: The RISC architecture has simple, hard-wired instructions which often take only one or a
few clock cycles to execute.
RISC machines feature a small and fixed code size with comparatively few instructions and few
addressing modes.
As a result, execution of instructions is very fast, but the instruction set is rather simple.
CISC: The CISC architecture is characterized by its complex micro coded instructions which take
many clock cycles to execute.
The architecture often has a large and variable code size and offers many powerful instructions
and addressing modes. but the instruction set is more powerful.
3. Classification of MCs by family (ideology).
According to ideology MC are distributed into the families.
The most popular families of 8-bit MCs are:
1. 8051 family (Intel ideology);
2. 68HC05 family (Motorola ideology);
3. AVR family (Atmel ideology);
4. PIC family (Microchip ideology).
IDEOLOGY. INSTRUCTION SET ARCHITECTURE MANUFACTURER