Microcontrollers and Embedded systems
Department of Telecommunication
Hazara University
Instructor: Mir Muhammad Wasiq
MICROCONTROLLER
A microcontroller is a small computer on a single integrated circuit containing a processor core,
memory, and programmable input/output peripherals. Program memory in the form of
Ferroelectric RAM, NOR flash or OTP ROM is also often included on chip, as well as a
typically small amount of RAM.
A microcontroller is a small computer on a single integrated circuit containing a processor core,
memory, and programmable input/output peripherals. Program memory in the form
of Ferroelectric RAM, NOR flash or OTP ROM is also often included on chip, as well as a
typically small amount of RAM. Microcontrollers are designed for embedded applications, in
contrast to the microprocessors used inpersonal computers or other general purpose applications.
Microcontrollers are used in automatically controlled products and devices, such as automobile
engine control systems, implantable medical devices, remote controls, office machines,
appliances, power tools, toys and other embedded systems. By reducing the size and cost
compared to a design that uses a separate microprocessor, memory, and input/output devices,
microcontrollers make it economical to digitally control even more devices and processes. Mixed
signal microcontrollers are common, integrating analog components needed to control non-
digital electronic systems.
Some microcontrollers may use four-bit words and operate at clock rate frequencies as low as 4
kHz, for low power consumption (single-digit milliwatts or microwatts). They will generally
have the ability to retain functionality while waiting for an event such as a button press or other
interrupt; power consumption while sleeping (CPU clock and most peripherals off) may be just
nanowatts, making many of them well suited for long lasting battery applications. Other
microcontrollers may serve performance-critical roles, where they may need to act more like
a digital signal processor (DSP), with higher clock speeds and power consumption.
1.1 What are microcontrollers and what are they used for?
Like all good things, this powerful component is basically very simple. It is made by mixing
tested and high- quality "ingredients" (components) as per following receipt:
1. The simplest computer processor is used as the "brain" of the future system.
2. Depending on the taste of the manufacturer, a bit of memory, a few A/D converters, timers,
input/output lines etc. are added
3. All that is placed in some of the standard packages.
4. Simple software able to control it all and which everyone can easily learn about has been
developed.
On the basis of these rules, numerous types of microcontrollers were designed and they quickly
became man's invisible companion. Their incredible simplicity and flexibility conquered us a
long time ago and if you try to invent something about them, you should know that you are
probably late, someone before you has either done it or at least has tried to do it.
The following things have had a crucial influence on development and success of the
microcontrollers:
Powerful and carefully chosen electronics embedded in the microcontrollers can
independently or via input/output devices (switches, push buttons, sensors, LCD
displays, relays etc.), control various processes and devices such as industrial
automation, electric current, temperature, engine performance etc.
Very low prices enable them to be embedded in such devices in which, until recent time
it was not worthwhile to embed anything. Thanks to that, the world is overwhelmed
today with cheap automatic devices and various “smart” appliences.
Prior knowledge is hardly needed for programming. It is sufficient to have a PC (software
in use is not demanding at all and is easy to learn) and a simple device (called the
programmer) used for “loading” raedy-to-use programs into the microcontroller.
So, if you are infected with a virus called electronics, there is nothing left for you to do but to
learn how to use and control its power?
How does the microcontroller operate?
Even though there is a large number of different types of microcontrollers and even more
programs created for their use only, all of them have many things in common. Thus, if you learn
to handle one of them you will be able to handle them all. A typical scenario on the basis of
which it all functions is as follows:
1. Power supply is turned off and everything is still…the program is loaded into the
microcontroller, nothing indicates what is about to come…
2. Power supply is turned on and everything starts to happen at high speed! The control logic
unit keeps everything under control. It disables all other circuits except quartz crystal to
operate. While the preparations are in progress, the first milliseconds go by.
3. Power supply voltage reaches its maximum and oscillator frequency becomes stable. SFRs
are being filled with bits reflecting the state of all circuits within the microcontroller. All
pins are configured as inputs. The overall electronis starts operation in rhythm with pulse
sequence. From now on the time is measured in micro and nanoseconds.
4. Program Counter is set to zero. Instruction from that address is sent to instruction decoder
which recognizes it, after which it is executed with immediate effect.
5. The value of the Program Counter is incremented by 1 and the whole process is
repeated...several million times per second.
1.2 What is what in the microcontroller?
As you can see, all the operations within the microcontroller are performed at high speed and
quite simply, but the microcontroller itself would not be so useful if there are not special circuits
which make it complete. In continuation, we are going to call your attention to them.
Read Only Memory (ROM)
Read Only Memory (ROM) is a type of memory used to permanently save the program being
executed. The size of the program that can be written depends on the size of this memory. ROM
can be built in the microcontroller or added as an external chip, which depends on the type of the
microcontroller. Both options have some disadvantages. If ROM is added as an external chip, the
microcontroller is cheaper and the program can be considerably longer. At the same time, a
number of available pins is reduced as the microcontroller uses its own input/output ports for
connection to the chip. The internal ROM is usually smaller and more expensive, but leaves
more pins available for connecting to peripheral environment. The size of ROM ranges from
512B to 64KB.
Random Access Memory (RAM)
Random Access Memory (RAM) is a type of memory used for temporary storing data and
intermediate results created and used during the operation of the microcontrollers. The content of
this memory is cleared once the power supply is off. For example, if the program performes an
addition, it is necessary to have a register standing for what in everyday life is called the “sum” .
For that purpose, one of the registers in RAM is called the "sum" and used for storing results of
addition. The size of RAM goes up to a few KBs.
Electrically Erasable Programmable ROM (EEPROM)
The EEPROM is a special type of memory not contained in all microcontrollers. Its contents may
be changed during program execution (similar to RAM ), but remains permanently saved even
after the loss of power (similar to ROM). It is often used to store values, created and used during
operation (such as calibration values, codes, values to count up to etc.), which must be saved
after turning the power supply off. A disadvantage of this memory is that the process of
programming is relatively slow. It is measured in miliseconds.
Special Function Registers (SFR)
Special function registers are part of RAM memory. Their purpose is predefined by the
manufacturer and cannot be changed therefore. Since their bits are physically connected to
particular circuits within the microcontroller, such as A/D converter, serial communication
module etc., any change of their state directly affects the operation of the microcontroller or
some of the circuits. For example, writing zero or one to the SFR controlling an input/output port
causes the appropriate port pin to be configured as input or output. In other words, each bit of
this register controls the function of one single pin.
Program Counter
Program Counter is an engine running the program and points to the memory address containing
the next instruction to execute. After each instruction execution, the value of the counter is
incremented by 1. For this reason, the program executes only one instruction at a time just as it is
written. However…the value of the program counter can be changed at any moment, which
causes a “jump” to a new memory location. This is how subroutines and branch instructions are
executed. After jumping the counter resumes even and monotonous automatic counting +1, +1,
+1…
Central Processor Unit (CPU)
As its name suggests, this is a unit which monitors and controls all processes within the
microcontroller and the user cannot affect its work. It consists of several smaller subunits, of
which the most important are:
Instruction decoder is a part of the electronics which recognizes program instructions
and runs other circuits on the basis of that. The abilities of this circuit are expressed in
the "instruction set" which is different for each microcontroller family.
Arithmetical Logical Unit (ALU) performs all mathematical and logical operations upon
data.
Accumulator is an SFR closely related to the operation of ALU. It is a kind of working
desk used for storing all data upon which some operations should be executed (addition,
shift etc.). It also stores the results ready for use in further processing. One of the SFRs,
called the Status Register, is closely related to the accumulator, showing at any given
time the "status" of a number stored in the accumulator (the number is greater or less
than zero etc.).
A bit is just a word invented to confuse novices at electronics. Joking aside, this word in practice
indicates whether the voltage is present on a conductor or not. If it is present, the approprite pin
is set to logic one (1), i.e. the bit’s value is 1. Otherwise, if the voltage is 0 V, the appropriate pin
is cleared (0), i.e. the bit’s value is 0. It is more complicated in theory where a bit is referred to as
a binary digit, but even in this case, its value can be either 0 or 1.
Input/output ports (I/O Ports)
In order to make the microcontroller useful, it is necessary to connect it to peripheral devices.
Each microcontroller has one or more registers (called a port) connected to the microcontroller
pins.
Why do we call them input/output ports? Because it is possible to change a pin function
according to the user's needs. These registers are the only registers in the microcontroller the
state of which can be checked by voltmeter!