MIcrocontroller Based Embedded System E - Contents
MIcrocontroller Based Embedded System E - Contents
UNIT-1
Introduction:
UNIT-2
2. 8051 Architecture
Interrupts: Interrupts is a sub-routine call that given by the microcontroller when some other
program with high priority is request for acquiring the system buses the n interrupts occur in current
running program.
Interrupts provide a method to postpone or delay the current process, performs a sub-routine task and
then restart the standard program again.
Memory: For operation Micro-controller required a program. This program guides the
microcontroller to perform the specific tasks. This program installed in microcontroller required some
on chip memory for the storage of the program.
Microcontroller also required memory for storage of data and operands for the short duration. In
microcontroller 8051 there is code or program memory of 4 KB that is it has 4 KB ROM and it also
comprise of data memory (RAM) of 128 bytes.
Bus : Bus is a group of wires which uses as a communication canal or acts as means of data transfer.
The different bus configuration includes 8, 16 or more cables. Therefore, a bus can bear 8 bits, 16 bits
all together.
Oscillator: As the microcontroller is digital circuit therefore it needs timer for their operation. To
perform timer operation inside microcontroller it required externally connected or on-chip oscillator.
Microcontroller is used inside an embedded system for managing the function of devices. Therefore,
8051 uses the two 16 bit counters and timers. For the operation of this timers and counters the
oscillator is used inside microcontroller.
Pins 1 – 8:
Port1 uses the Pins 1 to 8. Each pin is bidirectional Input /Output with internal pull – up resistors.
Pin 9:
It is a reset input Pin which used to reset the 8051 microcontrollers. It is an active HIGH Pin i.e. if we
apply a high pulse to this pin, the microcontroller will reset and terminate all activities.
Note: All value of the register will be lost after activating a power-on reset.
Pins 10-17:
Port3 uses the Pins 10 to 17. Each pin is bidirectional Input /Output with internal pull – up resistors.
Besides the Input /Output, each pin has some special functionality. In the below table, I have
described the other functionality of Port-3.
Pin 18 and 19 are used for interfacing an external crystal oscillator to get the system clock. We should
use the ceramic capacitor with an external crystal oscillator.
Pin 20 (GND):
Pins 21 -28:
Port2 uses the Pins 21 to 28. Each pin is bidirectional Input /Output with internal pull – up resistors.
Besides the Input /Output, when external memory is interfaced, PORT 2 pins act as the higher-order
address byte.
Pin 29 (PSEN):
Pin 29 is the Program Store Enable Pin (PSEN). It is an output pin and using this pin, external
Program Memory can be read.
Pin 30 (ALE/PROG):
Pin 30 is the Address Latch Enable Pin. It is an output pin and using this Pin, external address can be
separated from data (as they are multiplexed by 8051).
Pin 31 (EA/VPP):
Pin 31 is the External Access Enable Pin i.e. allows external Program Memory. It is an input pin and
must be connected from VCC or GND. If you want to access the code from external program
memory, it must be connected with GND. If you want to use on-chip memory, it must be high
(connected with VCC).
Pins 32–39:
Port0 uses the Pins 32 to 39. Each pin is bidirectional Input /Output but without internal pull – up
resistors. So we need to use an external pull-up before using Port0 as Input /Output.
Pin 40 (VCC):
Pin 40 is the power supply pin of the 8051 Microcontroller. It should be +5V.
8051 illator and Clock The oscillator is formed by the crystal, capacitors and an on-chip
inverter. Circuitry that generates the clock pulses by which all internal operations
are synchronized. Frequency- 1mHz to 16 mHz Minimum frequencies imply that
some internal memories are dynamic and must always operate above a minimum
frequency or data will be lost. The time to execute an instruction is found by •
Tinst = ( C x 12d ) / Crystal Frequency • Where C – number of machine cycle.
PC does not have an internal address. Program instruction bytes are fetched from
locations in memory that are addressed by the PC. DPTR register is made up of two 8
bit registers, named DPH and DPL, which are used to furnish memory addresses for
internal and external code access and external data access. DPTR does not have a single
internal address; DPH and DPL are each assigned an address.
Data pointer in the 8051 microcontrollers is one of the storage registers. Other storage
registers in an 8051 microcontroller are the accumulator, the stack pointer (SP), R register, B
register and the program counter (PC). The Data Pointer in 8051 microcontrollers in short form
DPTR is the only 2-byte register a user can access. Other registers like the B register and
accumulator are 1-byte register. This data pointer just like the name implies is for data pointing.
With it, the 8051 can access memory outside the system.
2.4 A & B CPU registers.
A and B CPU register 8051 contains 34 general purpose or working registers. Two of these
registers A and B, hold results of many instructions, particularly math and logical operations,
of the CPU. Other 32 register are arranged as part of internal RAM in four banks. ‘A’
register:
• Is most versatile of the two registers.
• It is used for many operations (arithmetical, logical and bit manipulations).
• Used for all data transfers between the 8051 and any external memory. ‘B’ register:
• Used with A register for multiplication and division operations
• No other function other than as a location where data may be stored.
CY (carry flag):
This flag is set whenever there is a carry out from the D.7 bit
This flag bit is affected after 8 bit addition or subtraction
It can also be set to 1 or 0 directly by an instruction such as " SET BC" and "CLRC"
AC(Auxiliary flag):
If there is a carry from D3 to D4 during ADD or SUB operation this bit is set otherwise it is
cleared
This flag is used by instruction that perform BCD (binary coded decimal) arithmetic
P (parity flag):
The parity flag reflect the number of 1's in the A (accumulator) register only
if the A register contains an odd number of 1's then p=1 therefore p=0 if A has an even
number 1's.
OV (overflow flag):
This flag is set whenever the result of a signed number operation is too large causing the high
order bit to overflow into the sign bit
the carry flag is used to detect error in unsigned arithmetic operations
the overflow flag is only used to detect error in signed arithmetic operations.
1. Internal ROM
2. Internal RAM
128 Byte RAM There are 128 bytes of RAM in the 8051.
• Assigned addresses 00 to 7FH The 128 bytes are divided into 3 different groups as follows:
1. A total of 32 bytes from locations 00 to 1F hex are set aside for register banks.
2. A total of 16 bytes from locations 20H to 2FH are set aside for bit-addressable read/write
memory.
3. A total of 80 bytes from locations 30H to 7FH are used for read and write storage, called
scratch pad.
8051 Stack and Stack pointer The stack is a section of RAM used by the CPU to store
information temporarily.
• This information could be data or an address . The register used to access the stack is called
the SP (stack pointer) register.
• The stack pointer in the 8051 is only 8 bit wide, which means that it can take value of 00 to
FFH.
• When the 8051 is powered up (i.e.,) reset, the SP register contains value 07
• RAM location 08 is the first location begin used for the stack by the 8051.
• This is different from many microprocessors Loading the contents of the stack back into a
CPU register is called a POP
• With every pop, the top byte of the stack is copied to the register specified by the instruction
and the stack pointer is decremented once.
2.7 Input/output ports.
8051 microcontrollers have 4 I/O ports each of 8-bit, which can be configured as input or output.
Hence, total 32 input/output pins allow the microcontroller to be connected with the peripheral
devices.
Pin configuration, i.e. the pin can be configured as 1 for input and 0 for output as per the
logic state.
o Input/Output (I/O) pin − All the circuits within the microcontroller must be
connected to one of its pins except P0 port because it does not have pull-up resistors
built-in.
o Input pin − Logic 1 is applied to a bit of the P register. The output FE transistor is
turned off and the other pin remains connected to the power supply voltage over a
pull-up resistor of high resistance.
PORT 0:
Port-0 can be used as a normal bidirectional I/O port or it can be used for address/data interfacing for
accessing external memory. When control is ‘1’, the port is used for address/data interfacing. When
the control is ‘0’, the port can be used as a bidirectional I/O port.
PORT 1:
The structure of a port-1 pin is shown in fig below.It has 8 pins (P1.1-P1.7) .
P1 is a true I/O port as it doesn’t have any alternative functions as in P0, but this port can be
configured as general I/O only. It has a built-in pull-up resistor and is completely compatible with
TTL circuits.
PORT 2:
The structure of a port-2 pin is shown in fig. below. It has 8-pins (P2.0-P2.7) .
Port-2 we use for higher external address byte or a normal input/output port. The I/O operation is
similar to Port-1. Port-2 latch remains stable when Port-2 pin are used for external memory access.
Here again due to internal pull-up there is limited current driving capability.
PORT 3:
When port 3 is used as an input port ‘1’ must be written to the corresponding port 3 latch bit this
cause the FET to turn off pin & input to pin buffer are pulled to logic high by internal pull up load.
Timer Counter
The register incremented for every The register is incremented considering 1 to 0 transition at
machine cycle. its corresponding to an external input pin (T0, T1).
Maximum count rate is 1/12 of the Maximum count rate is 1/24 of the oscillator frequency.
oscillator frequency.
A timer uses the frequency of the A counter uses an external signal to count pulses.
internal clock, and generates delay.
Computers must be able to communicate with other computers in modern multiprocessor distributed
systems. One cost-effective way to communicate is to send and receive data bits serially. The 8051
has a serial data communication circuit that uses register SBUF to hold data. Register SCON controls
data communication, register PCON controls data rates, and pins RXD (P3.0) and TXD (P3.1)
connect to the serial data network.
SBUf is physically two registers. One is write only and is used to hold data to be transmitted out of
the 8051 via TXD. The other is read only and holds received data from external sources via RXD.
Both mutually exclusive registers use address 99h.
There are four programmable modes for serial data communication that are chosen by setting the
SMX bits in SCON. Baud rates are determined by the mode chosen.
2.11 Interrupts
Interrupts are of different types like software and hardware, maskable and non-maskable, fixed and
vector interrupts, and so on.
The 8051 microcontroller can recognize five different events that cause the main program to interrupt
from the normal execution. These five sources of interrupts in 8051are:
Interrupt Enable (IE) Register: This register is responsible for enabling and disabling the interrupt.
It is a bit addressable register in which EA must be set to one for enabling interrupts. The
corresponding bit in this register enables particular interrupt like timer, external and serial inputs. In
the below IE register, bit corresponding to 1 activates the interrupt and 0 disables the interrupt.
Interrupt Priority Register (IP): It is also possible to change the priority levels of the interrupts by
setting or clearing the corresponding bit in the Interrupt priority (IP) register as shown in the figure.
This allows the low priority interrupt to interrupt the high-priority interrupt, but prohibits the
interruption by another low-priority interrupt. Similarly, the high-priority interrupt cannot be
interrupted. If these interrupt priorities are not programmed, the microcontroller executes in
predefined manner and its order is INT0, TF0, INT1, TF1, and SI.
TCON Register: In addition to the above two registers, the TCON register specifies the type of
external interrupt to the 8051 microcontroller, as shown in the figure. The two external interrupts,
whether edge or level triggered, specify by this register by a set, or cleared by appropriate bits in it.
And, it is also a bit addressable register.
B.K.N GOVT POLYTECHNIC NARNAUL
DEPARTMENT- INSTRUMENTATION AND CONTROL
ENGINEERING
Unit-3
Addressing Modes & Instructions:
3.1 Instructions set of 8051
The instructions of 8051 Microcontroller can be classified into five different groups. These groups are
like below
Data Transfer Group
Arithmetic Group
Logical Group
Program Branch Group
Bit Processing Group
This Bit-Processing group is also known as Boolean Variable Manipulation.
Like 8085, some instruction has two operands. The first operand is the Destination, and the second
operator is Source.
3.2 Arithmetic instructions
Arithmetic Instructions are the instructions which perform basic arithmetic operations such as
addition, subtraction and a few more.
The ADD instruction adds a byte variable with the accumulator, leaving the result in the accumulator:
The carry flag is set if there is an overflow from bit 7 and cleared otherwise. The AC flag is set to the
carry-out from bit 3 for use by the DA instruction described later. ADDC adds the previous contents
of the carry flag with the two byte variables, but otherwise is the same as ADD:
The SUBB (subtract with borrow) instruction subtracts the byte variable indicated and. the contents of
the carry flag together from the accumulator, and puts the result back in the accumulator. The carry
flag serves as a “Borrow required” flag during subtraction operations when a greater value is
subtracted from a lesser value (as in subtracting 5 from 1) requiring a borrow into the highest order
bit, the carry flag is set; otherwise it is cleared.
DIV AB” divides the unsigned eight-bit integer in the accumulator by the unsigned eight-bit integer in
the B-register. The integer part of the quotient is returned in the accumulator, the remainder in the B
register. If the B-register originally contains OOH then the overflow flag will be set to indicate a
division error, and the values returned will be undefined. Otherwise OV is cleared.
The divide instruction is also useful for purposes such as radix conversion or separating bit fields of
the accumulator. A short subroutine can convert an eight-bit unsigned binary integer in the
accumulator (between 0 and 255) to a three-digit (two byte) BCD representation. The hundred’s digit
is returned in one register (HUND) and the ten’s and one’s digits returned as packed BCD in another
(TENONE).
Jump Instructions – The jump instruction transfers the program sequence to the memory address
given in the operand based on the specified flag. Jump instructions are 2 types: Unconditional Jump
Instructions and Conditional Jump Instructions.
The CALL instruction interrupts the flow of a program by passing control to an internal or external
subroutine. An internal subroutine is part of the calling program. An external subroutine is another
program.
CALL is used to call a subroutine. • Subroutines are often used to perform tasks that need to be
performed frequently. • This makes a program more structured in addition to saving memory
space. • There are two instructions:
LCALL (long call) and ACALL (absolute call).
Deciding which one to use depends on the target address.
LCALL (long call) • 3-byte instruction, the first byte is the op-code and the second and
third bytes are used for the address of the target subroutine
LCALL can be used to call subroutines located anywhere within the 64K-byte address
space of the 8051
To make sure that after execution of the called subroutine the 8051 knows where to come back to,
the processor automatically saves on the stack the address of the instruction immediately below the
LCALL.
• When a subroutine is called, control is transferred to that subroutine, and the processor
saves the PC (program counter) on the stack and begins to fetch instructions from the new
location.
• After finishing execution of the subroutine, the instruction RET (return) transfers control
back to the caller. Every subroutine needs RET as the last instruction.
3.4.1 Differences between CALL and JUMP instructions.
By using JUMP, the program control transfers to a By using CALL instruction, the program control
location which is also a part of the main program transfers to a location which is not a part of main
program.
Here the addressing mode is Immediate Here the addressing mode is Immediate and Register
Indirect.
We do not need to initialize the Stack Pointer (SP) We have to initialize the Stack Pointer (SP) before
to perform the JUMP instruction. using some CALL instruction.
The program counter value is not Pushed into The value of program counter is pushed into stack
Stack before going to the pointed location.
No return instruction is needed after JUMP After CALL, it enters into a subroutine, to come back
instruction. from subroutine we need return instruction.
JUMP Instruction CALL instruction
The value of stack pointer remain unchanged The value of Stack Pointer is decremented by 2.
10 T-States are required to perform JUMP 18 T-States are required to perform CALL instruction.
instruction
3 Machine cycles are needed for JUMP 5 Machine cycles are needed for CALL.
Instructions that store and retrieve an item on a stack. Push enters an item on the stack,
and pop retrieves an item, moving the rest of the items in the stack up one level.
3.6 Addressing modes of 8051
MOVA, #0AFH;
MOVR3, #45H;
MOVDPTR, #FE00H;
In these instructions, the # symbol is used for immediate data. In the last instruction, there is DPTR.
The DPTR stands for Data Pointer. Using this, it points the external data memory location. In the first
instruction, the immediate data is AFH, but one 0 is added at the beginning. So when the data is
starting with A to F, the data should be preceded by 0.
Register addressing mode
In the register addressing mode the source or destination data should be present in a register (R0 to
R7). These are some examples of RegisterAddressing Mode.
MOVA, R5;
MOVR2, #45H;
MOVR0, A;
In 8051, there is no instruction like MOVR5, R7. But we can get the same result by using this
instruction MOV R5, 07H, or by using MOV 05H, R7. But this two instruction will work when the
selected register bank is RB0. To use another register bank and to get the same effect, we have to add
the starting address of that register bank with the register number. For an example, if the RB2 is
selected, and we want to access R5, then the address will be (10H + 05H = 15H), so the instruction
will look like this MOV 15H, R7. Here 10H is the starting address of Register Bank 2.
Direct Addressing Mode
In the Direct Addressing Mode, the source or destination address is specified by using 8-bit data in the
instruction. Only the internal data memory can be used in this mode. Here some of the examples of
direct Addressing Mode.
MOV80H, R6;
MOVR2, 45H;
MOVR0, 05H;
The first instruction will send the content of registerR6 to port P0 (Address of Port 0 is 80H). The
second one is forgetting content from 45H to R2. The third one is used to get data from Register R5
(When register bank RB0 is selected) to register R5.
MOV0E5H, @R0;
MOV@R1, 80H
In the instructions, the @ symbol is used for register indirect addressing. In the first instruction, it is
showing that theR0 register is used. If the content of R0 is 40H, then that instruction will take the data
which is located at location 40H of the internal RAM. In the second one, if the content of R1 is 30H,
then it indicates that the content of port P0 will be stored at location 30H in the internal RAM.
MOVXA, @R1;
MOV@DPTR, A;
In these two instructions, the X in MOVX indicates the external data memory. The external data
memory can only be accessed in register indirect mode. In the first instruction if the R0 is holding
40H, then A will get the content of external RAM location40H. And in the second one, the content of
A is overwritten in the location pointed by DPTR.
Indexed addressing mode
In the indexed addressing mode, the source memory can only be accessed from program memory
only. The destination operand is always the register A. These are some examples of Indexed
addressing mode.
MOVCA, @A+PC;
MOVCA, @A+DPTR;
The C in MOVC instruction refers to code byte. For the first instruction, let us consider A holds 30H.
And the PC value is1125H. The contents of program memory location 1155H (30H + 1125H) are
moved to register A.
UNIT 4
Types of RTOS
The soft real-time operating system has certain deadlines, may be missed and they will take the
action at a time t=0+. The soft real-time operating system is a type of OS and it does not contain
constrained to extreme rules. The critical time of this operating system is delayed to some extent.
The examples of this operating system are the digital camera, mobile phones and online data etc.
This is also a type of OS and it is predicted by a deadline. The predicted deadlines will react at a
time t = 0. Some examples of this operating system are air bag control in cars, anti-lock brake,
and engine control system etc.
In the firm real-time, an operating system has certain time constraints, they are not strict and it
may cause undesired effects. Examples of this operating system are a visual inspection in
industrial automation.
Embedded operating system:- An embedded operating system (OS) is a specialized
operating system designed to perform a specific task for a device that is not a computer. An embedded
operating system's main job is to run the code that allows the device to do its job.
The most common examples of embedded operating system Symbian (cell phones) and Linux.
This is the very basic type of operating system that performs only a single function at a time.
This is still not clear that such a simple operating system could be an embedded operating
system. Because generally operating systems perform multiple tasks to manage the system
resource.
This type of operating system can perform multiple tasks at a time. The multiple tasks can run
simultaneously. The operating system can keep track of each task and can switch between it
without losing the information.
In multitasking actually, the overall time of a problem is divided into small tasks. Each divided
subtask gets the CPU time based on a fixed interval.
Only current executing process get the entire CPU time. The remaining task executing in a
virtual environment. Where they get a register, program counter(PC), stack memory and a stack
pointer. The task is executing in a virtual environment. This all goes in runtime. When a higher
priority task is coming to the currently executing task is saved into memory.
In this type of operating system, a rate monotonic priority algorithm is used in real-time
operating systems(RTOS). It is a priority-based scheduling algorithm. In this operating system,
the scheduling is preemptive. Means the task gets interrupted or suspended by another task with
a short period.
The execution time of the task is set in such a way that all task gets an equal amount of execution
time or at least the task get the chance to execute when it is expected to run. This type of
operating system always gives the shorter task a higher priority.
4. Preemptive Operating System
In this type of operating system, the currently executing task may be interrupted by the other
higher priority task and can be resumed later.
The system has a scheduler that receives the interrupt that is received from the external calls.
Once the interrupt is received scheduler pause the running task and start the higher priority task.
The control of the CPU passes from one task to another. This is called preemption.
The main concept here is to manage the higher priority task that is more important and critical.
Power Supply
The power supply is an essential part of any embedded systems circuits. An embedded system
may need a supply of 5 volts or if it is low power then maybe 3.3 or 1.8v. The supply may be
provided with the help of battery or we can use any wall adapter. It will depend on the
application need.
The power supply circuit can be designed with the help some little knowledge of electronics. For
that, we need a bridge rectifier circuit, capacitor as a filter and a voltage regulator that provides
constant output supply.
Processor
A processor is the main brain inside any embedded systems. This is a major factor that affects
the performance of the system. There are different processors available in the market. An
embedded system may use microprocessor or microcontroller.
The processor comes in different architecture like 8-bit, 16-bit and 32-bit. The 8-bit processor is
generally used in a small application where we need some basic computation like input and
output no heavy processing.
For higher-end application where performance matters and need some graphical user interface,
we use 16 or 32-bit processor.
Speed
Unit Price
Packaging
Performance
Peripheral Set
Timer on the Chip
Operating Voltage
Number of I/O Pins
Power Consumption
Amount of RAM and ROM
Specialized Processing Units
Architecture 8-bit, 16-bit, or 32-bit
Availability of Supplier for a given core
Easy to upgrade to higher or lower power consumption mode
Availability of Software tools like assembler, debugger, compiler, emulator and technical
support
Memory
If we are using a microcontroller like AT89s51, AT89s52 or ATmega. The memory is available
on-chip. We generally talk about two types of memory in the embedded systems
Read-Only memory(RAM)
Random Access Memory(ROM)
Electrically Erasable Programmable Read-Only Memory (EEPROM)
RAM memory is volatile memory and used for temporary storage of the data. And the selection
of it depends on the user need and the application.
The ROM memory or Code Memory. This is used for the storage of the program. Once system
powered, the system fetches the code from the ROM memory.
The EEPROM is a unique memory. The content can be erased and reprogrammed by a high
voltage pulse input. This is used to store the data by the program itself. Suppose we have a
temperature data logger. And it needs to store the data every one hour. It means we need the data
at runtime after the system is started.
The system will read temperature and store in the EEPROM memory. And it will be permanent.
And you can retrieve the data later.
So an embedded system developer decide which memory to use for its application.
Timers-Counters
If you are working in embedded systems you must have heard about
In some application, we need to generate some delay. Like for blinking an LED, we need a
delay. For making square pulse we need a delay.
But there is some issue when we generate the delay from the normal coding style by making any
loop running for a particular time. Definitely, this will give you some delay but the code after
this loop remains in waiting for state and delayed.
So it is not the best approach to generate the delay. For such kind of application where we need a
delay for a specific time interval without affecting the normal code execution, we use timer and
counter.
By setting some register for timer and counter using the programming we get the desired delay.
The amount of delay depends on the system frequency and crystal oscillator.
Communication Ports
Embedded systems hardware has different types of communication ports to communicate with
the other embedded devices.
UART
CAN
SPI
I2C
USB
Ethernet
RS-232
RS-423
RS-485
But for a small level of embedded systems microcontroller has on-chip communication ports.
For example, popular Arduino UNO board has ATmega328 IC and it has following
communication port:
UART
I2C
SPI
For sending data from one board to other we can use these serial protocols. But for that, we need
to program it.
To interact with the embedded systems we need input. The input may be provided by the user or
by some sensor. Sometimes some systems need more input or output. So the processor selection
will be based on I/O.
These input and output are generally divided into ports like P0, P1, P2 and P3 in
8051microcontrollersr. And PA, PB, PC and PD in ATmega series of the microcontroller.
The I/O need to be configured for input or output based on the provided register. And for that,
we need to refer the datasheet of the manufacturer.
Some hardware components are common while designing the embedded systems. But some are
different and depends on the application need. Like a temperature sensor need a temperature
sensor for sensing the temperature. While others hand an alcohol detector has a sensor to detect
the alcohol level.
Power Supply
Processor
Display Device
Buzzer for Alert
2.Software Components
Once the hardware is completed we need to build the software for the embedded devices. There
are different software tools for programming and coding. These software tools are referred to as
software components.
We need a program written in assembly or in embedded c language. And then we compile it.
This compiled code converted into HEX code. This hex code is programmed or burned into the
ROM of the system using some programmer.
These are the tools that are generally used in embedded system development
Assembler
Emulator
Debugger
Compiler
Assembler
When you program in assembly language. This assembly language program is converted into the
HEX code using this utility. Then using some hardware called as a programmer we write the
chip.
Emulator
An emulator is hardware or software tool that has a similar functionality to the target system or
guest system. It enables the host system to execute the functionality and other components. It is a
replica of the target system. And used for debugging the code and issues.
Once program or code is fixed at the host system. It is transferred to the target system.
Debugger
Sometimes we are not getting expected results or output due to errors or bug. There are certain
tools that are specifically used for the debugging process. Where we can see the controls flow
and register value to identify the issue.
Compiler
A compiler is a software tool that converts one programming language into target code that a
machine can understand. The compiler basically used for translating the high-level language into
the low-level language like machine code, assembly language or object code.
Examples of embedded system
Some examples of embedded systems are MP3 players, mobile phones, video game consoles,
digital cameras, DVD players, and GPS. Household appliances, such as microwave ovens, washing
machines and dishwashers, include embedded systems toprovide flexibility and efficiency.
With the rise of the Internet of Things (IoT), the primary focus of developers and manufacturers
is on security. In 2019, advanced technologies for embedded security will emerge as key
generators for identifying devices in an IoT network, and as microcontroller security solutions
that isolate security operations from normal operations.
Getting embedded industrial systems connected to the internet and cloud can take weeks and
months in the traditional development cycle. Consequently, cloud connectivity tools will be an
important future market for embedded systems. These tools are designed to simplify the process
of connecting embedded systems with cloud-based services by reducing the underlying hardware
complexities.
A similar yet innovative market for low-energy IoT device developers is Bluetooth mesh
networks. These solutions can be used for seamless connectivity of nearby devices while
reducing energy consumption and costs.
A key challenge for developers is the optimization of battery-powered devices for low power
consumption and maximum uptime. Several solutions are under development for monitoring and
reducing the energy consumption of embedded devices that we can expect to see in 2019. These
include energy monitors and visualizations that can help developers fine-tune their embedded
systems, and advanced Bluetooth and Wi-Fi modules that consume less power at the hardware
layer.
Developers currently lack tools for monitoring and visualizing their embedded industrial systems
in real time. The industry is working on real-time visualization tools that will give software
engineers the ability to review embedded software execution. These tools will enable developers
to keep a check on key metrics such as raw or processed sensor data and event-based context
switches for tracking the performance of embedded systems.
5. Deep Learning Applications
Deep learning represents a rich, yet unexplored embedded systems market that has a range of
applications from image processing to audio analysis. Even though developers are primarily
focused on security and cloud connectivity right now, deep learning and artificial intelligence
concepts will soon emerge as a trend in embedded systems.
5.1 Only brief general architecture of AVR, PIC and ARM microcontroller
AVR is a family of microcontrollers developed since 1996 by Atmel, acquired by Microchip Technology in 2016.
Automatic Voltage Regulator (AVR) is a device used in the electrical power field to obtain the stability and good
regulation of the electric system.
Basic of AVR
AVR MCUs are extremely popular MCUs used in various application specially in project prototyping and
embedded devices. AVR is a 8-bit RISC architecture (Reduced Instruction Set Computing) microcontroller in
market since 1996 which is having on-chip programmable flash memory, SRAM, IO data space & EEPROM.
AVR is the first MCU in market which has on-chip flash storage.
According to the datasheet, the block diagram of its architecture is this (look below) :
Data BUS 8 bit : Its an 8-bit parallel data lines by which the data travels inside the MCU (NOTE: this is the reason
why AVR is an 8-bit MCU).
ALU: Arithmetic Logic Unit, the core/heart of the entire system where typically all commands get
executed.
Data SRAM: It basically pretty similar to the RAM (Random access memory) we see inside our
computers.
EEPROM: (Electrically Erasable Programmable Read Only Memory) its very similar to another
component in our computer namely HardDisk, i.e. a permanent storage.
I/O lines: These are the bunch of registers which is used as a switches or controls for different features of AVR.
32X8 GPR (General Purpose Registers): This are 32 registers each having 8-bit which is a general storage space for
data. But, remember, SRAM is also a temporary storage but these registers have
some specialty among all.
Status & Control : A couple of registers which are very special to the MCU & to us also.
Program Counter: This is a register which has a responsibility to track the position of the program that is currently
executing.
Flash Memory: It is also a permanent storage but its only for storing the program we write to it.
Instruction Register & Decoder: These are import for the MCU .
Flash memory:
The last digits of the name of the MCU (32 in case of Atmega32A) signifies the amount of flash memory it
contains (in K Bytes). So, Atmega32A has 32 KB flash memory (more than enough for a standard application
program).
This memory is organized in a different manner. As it can be seen from the image below that the 32K X 8B (32768
Bytes) flash is organized in 16K X 16B (32768 Bytes). So the flash memory is having 16 bits (2 bytes) as the
smallest unit, which can be addressed via 0 through 16383. In this context, I would like to introduce you to the
Program Counter also. Because of the highest address of the flash memory is 16383 (11111111111111 in binary), a
PC (which stores address of the currently executing location of the flash) of 14 bits is sufficient. To be a bit more
clear, an address 'X' of the flash memory denotes 2 bytes of data, where 'X' ranges from 0 to 16383 (Remember,
these numbers are often written in HEX format,
i.e. 0x3FFF/ $3FFF. A dollar sign in front of the HEX number is a convention followed by Atmel
assembler to denote memory address while coding in low level assembly language).
Btw, the entire flash memory is logically divided into 2 sections namely "Boot loader" section &
"Application" section.
GPRs, I/O Space & SRAM memory space:
These memories are organized in another manner than the flash. These memories are different in nature but
having a continuous space (logically) inside the MCU. Let's look at the diagram first.
GPRs (General Purpose Registers) are 32 in number each of them being an 8-bit storage, take address from
$0000 upto $001F. These are general purpose storage for data. We often use these registers for storing
variables and other data while programming the MCU. These registers have special names as R0 upto R31
(Look at the diagram above for more clarification). Now one thing
to mention that the last 6 register in this series of registers (R26 upto R31) have special names XL, XH, YL,
YH, ZL & ZH (They are pointed in the diagram by red dashes) & also special purposes. So, as an example,
$001E is nothing but R30 which is the 31st GPR.
I/O Space is a collection of 64 registers each register having totally different names according to their purposes
e.g. DDRA, PINB, EEAR, etc. Those who already know embedded C programming, may recognize these
names. Apart from their names, they have their usual memory addresses from $20 through $5F . One thing to
note that these registers are called usually by their names not by their addresses.
SRAM is a volatile memory of temporary storage which is actually the main "Memory" of an MCU. In the
diagram as well as in discussion, I have considered Atmega32A which has 2KB of SRAM, which means 2048
cells of 8-bit each, address ranging from $60 upto $85F. These SRAM locations usually accessed via their
memory addresses as they don't have special names.
Some special Registers are Status Register (SREG), Program Counter (PC). Status register refers to that
special register of MCU which keeps track of of the status of the MCU as well as the last arithmetic operation
completed on ALU. The PC is a pointer to the memory address (flash memory) of the next command that will
be executed. PC is a 14 bit register to hold any address ranging from $0000 to $3FFF (The last address of flash
memory).
Program Execution & Clock:As you probably know, a program always coverts down to assembly/ machine
code which is nothing but a bunch of binary numbers, regardless of what programming language you use. So,
the machine code gets uploaded to the flash memory of the MCU in a particular location (not necessarily at
$0000, depends on some settings I'll talk about later). After that, the PC is set to the starting address of the
program & its starts executing. The PC is increased by 1 after completion of the previous command (Actually
the amount of increment depends of the command also, but for now, forget about this).
Another very important component inside the MCU is a pulse generator or a "Clock" which simply generates
square pulses in a constant frequency. The purpose of the Clock is to create a rhythm inside the MCU so that it
can make sure about the concurrent processing of each & every module.
During a single clock pulse, the following things happen:
Step 1. Fetches the command/Instruction at the address of the flash memory pointed by PC.
Step 2. The binary machine code then gets decoded by a "Instruction Decoder".
Step 3. After figuring out the command/Instruction, the ALU starts performing the operation corresponding to
the machine code. (Different machine codes correspond to different tasks)
Step 4. The ALU increases the PC by 1 (it actually depends on the instruction, but for now, simplest case can
be considered).
Step 5. Go to Step 1.
The above cycle continues till the MCU is properly powered.
PIC MICROCONTROLLER ARCHITECTURE: PIC stands for Peripheral Interface Controller. PIC
microcontroller was developed by microchip technology in 1993. It was developed for supporting PDP
computers to control its peripheral devices and that’s why it was named Peripheral Interface Controller. PIC
microcontrollers are of low cost, very fast and easy for the programming and execution of program. Their
interfacing with other peripherals is also very easy. PIC Microcontrollers from Microchip Company are
divided into 4 large families. In this PIC MICROCONTROLLER ARCHITECTURE
ARCHITECTURE:
PIC Microcontroller architecture is based on Harvard architecture and supports RISC architecture (Reduced
Instruction Set Computer). PIC microcontroller architecture consists of memory organization (ram, rom,
stack), CPU, timers, counter, ADC, DAC, serial communication, CCP module and I/O ports. PIC
microcontroller also supports the protocols like CAN, SPI, UART for interfacing with other peripherals .
PIC MICROCONTROLLER ARCHITECTURE block diagram
ALU is used for arithmetic operations and for logical decisions. Memory is used for storing the
instructions after processing. Control unit is used to control the internal and external peripherals
which are connected to the CPU and accumulator is used for storing the results.
2. MEMORY ORGANIZATION:
PIC microcontroller memory module consists of mainly 3 types of memories:
PROGRAM MEMORY:
It contains the written program after we burned it in microcontroller. Program Counter executes
commands stored in the program memory, one after the other. Pic microcontroller can have 8K
words x 14 bits of Flash program memory that can be electrically erased and
reprogrammed. Whenever we burn program into the micro, we erase an old program and write a
new one.
DATA MEMORY:
It is a RAM type which is used to store the data temporarily in its registers. The RAM memory is
classified into banks. Each bank extends up to 7Fh (128 bytes). Number of banks may vary
depending on the microcontroller. PIC16F84 has only two banks. Banks contain Special
Function Registers (SFR) and General Purpose Registers (GPR). The lower locations of each
bank are reserved for the Special Function Registers and upper locations are for General Purpose
Registers.
These registers don’t have any special function. These are used for general purpose for
multiplying, addition or subtraction and then storing the results in other registers. CPU can easily
access the data in these registers.
These registers are used for special purposes and they cannot be used as normal registers. Their
function is set at the time of manufacturing. They perform the function assigned to them and user
cannot change the function of SFR. Three important SFRs for programming are:
DATA EEPROM:
This memory allows storing the variables as a result of burning the written program. It is
readable and writable during normal operation (over the full VDD range). This memory is not
directly mapped in the register file. It is indirectly addressed through the SFRs. There are six
SFRs which are used to read and write to this memory (EECON1, EECON2, EEDATA,
EEDATH, EEADR, EEADRH).
3. SERIAL COMMUNICATION:
The transfer of one bit of data at time consecutively over a communication channel is called
Serial Communication. There are three protocols of serial communication:
SPI Protocol: SPI stands for Serial Peripheral Interface. It is used to send data between
PIC microcontrollers and other peripherals like sensors, shift registers and SD cards.
Three wire SPI communications is supported in PIC microcontroller between two devices
on a common clock source. SPI protocol has greater data handling capability than that of
the USART.I2C Protocol: I2C stands for Inter Integrated Circuit, and this protocol is
used to connect low speed devices like microcontrollers, EEPROMS and A/D converters.
PIC microcontroller support two wire Interface or I2C communication between two
devices which can work as both Master and Slave device.
Serial Communication
4. INTERRUPTS:
There are 20 internal interrupts and three external interrupt sources in PIC microcontrollers
which are related with different peripherals like ADC, USART, Timers, and CCP etc.
5. I/O PORTS:
Let us take PIC16 series, it consists of five ports, such as Port A, Port B, Port C, Port D and Port
E.
Port A:This port is 7-bit wide and can be used for both input and output. The status of
TRISA register decided whether it is used as input or output port.
Port B:It is an 8-bit port. This port also can be used as input and output. Moreover in
input mode four of its bits are variable according to the interrupt signals.
Port C:It is also an 8-bit port and can be used as both input and output port which is
determined by the status of the TRISC register.
Port D:This 8-bit port, unlike Port A, B and C is not an input/output port, but is used as
acts as a slave port for the connection to the microprocessor When in I/O mode Port D
all pins should have Schmitt Trigger buffers.
Port E:It is a 3-bit port which is used as the additional feature of the control signals to
the A/D converter.
6. CCP MODULE:
Capture Mode: In this mode time is captured when a signal is arrived, or we can say
that, when the CCP pin goes high it captures the value of the Timer1.
Compare Mode: It works same as an analog comparator, which means that when timer
1’s value reaches some reference value it will give an output signal.
PWM Mode: This mode provides a 10 bit resolution pulse and duty cycle that is
programmable.
Timers:
Timers and counters are important as timers can tell the time and count. PIC microcontroller can
have up to four timers (depending upon the family) Timer0, Timer1, Timer2 and Timer3. Timer0
and Timer2 are of 8-bits while the Timer1 and Timer3 are of 16-bits, which can also be used as
a counter. These timers work according to the selected modes.
8. D/A CONVERTER:
There are no analog outputs in PIC Microcontroller. To get analog output we have to use
external Digital-to-Analog Converter (DAC). It can convert 8 bits of digital number from the
eight digital outputs of PIC microcontroller.
9. A/D CONVERTER:
It converts the analog voltage levels to digital voltage values. In PIC Microcontroller, ADC has
8-channels and has resolution of 10-bit, which means that if we have to convert an analog
voltage between 0V to 5V the converter will divide it to 2^10 levels (1024 levels). The special
function registers ADCON0 and ADCON1 control the operation of ADC. The converter stores
the lower 8 bits in ADRESL register and the upper bits in the ADRESH register. Reference
voltage of 5V is required for the operation of the converter.
ARM Architecture
The ARM Adjustable-Rate Mortgage (ARM) architecture processor is an advanced reduced instruction
set computing [RISC] machine and it’s a 32bit reduced instruction set computer (RISC)
microcontroller. It was introduced by the Acron computer organization in 1987. This ARM is a
family of microcontroller developed by makers like ST Microelectronics,Motorola, and so on.
The ARM architecture comes with totally different versions like ARMv1, ARMv2, etc., and,
each one has its own advantage and disadvantages.
ARM Architecture
The ARM cortex is a complicated microcontroller within the ARM family that has ARMv7
design. There are 3 subfamilies within the ARM cortex family :
The ARM processor conjointly has other components like the Program status register, which
contains the processor flags (Z, S, V and C). The modes bits conjointly exist within the program
standing register, in addition to the interrupt and quick interrupt disable bits; Some special
registers: Some registers are used like the instruction, memory data read and write registers
and memory address register.
Priority encoder: The encoder is used in the multiple load and store instruction to point
which register within the register file to be loaded or kept .
Multiplexers: several multiplexers are accustomed to the management operation of the
processor buses. Because of the restricted project time, we tend to implement these components
in a very behavioral model. Each component is described with an entity. Every entity has its own
architecture, which can be optimized for certain necessities depending on its application. This
creates the design easier to construct and maintain.
The ALU has two 32-bits inputs. The primary comes from the register file, whereas the other
comes from the shifter. Status registers flags modified by the ALU outputs. The V -bit output
goes to the V flag as well as the Count goes to the C flag. Whereas the foremost significant bit
really represents the S flag, the ALU output operation is done by NORed to get the Z
flag. The ALU has a 4-bit function bus that permits up to 16 opcode to be implemented.
The multiplier factor has 3 32-bit inputs and the inputs return from the register file. The
multiplier output is barely 32-Least Significant Bits of the merchandise. The entity
representation of the multiplier factor is shown in the above block diagram. The multiplication
starts whenever the beginning 04 input goes active. Fin of the output goes high when
finishing.
Booth Algorithm
Booth algorithm is a noteworthy multiplication algorithmic rule for 2’s complement numbers.
This treats positive and negative numbers uniformly. Moreover, the runs of 0’s or 1’s within the
multiplier factor are skipped over without any addition or subtraction being performed, thereby
creating possible quicker multiplication. The figure shows the simulation results for the
multiplier test bench. It’s clear that the multiplication finishes only in16 clock cycle.
Barrel Shifter
The barrel shifter features a 32-bit input to be shifted. This input is coming back from the
register file or it might be immediate data. The shifter has different control inputs coming back
from the instruction register. The Shift field within the instruction controls the operation of the
barrel shifter. This field indicates the kind of shift to be performed (logical left or right,
arithmetic right or rotate right). The quantity by which the register ought to be shifted is
contained in an immediate field within the instruction or it might be the lower 6 bits of a register
within the register file.
The shift_val input bus is 6-bits, permitting up to 32 bit shift. The shifttype indicates the needed
shift sort of 00, 01, 10, 11 are corresponding to shift left, shift right, an arithmetic shift right and
rotate right, respectively. The barrel shifter is especially created with multiplexers.
Control Unit
For any microprocessor, control unit is the heart of the whole process and it is responsible for the
system operation,so the control unit design is the most important part within the whole design.
The control unit is sometimes a pure combinational circuit design. Here, the control unit is
implemented by easy state machine. The processor timing is additionally included within the
control unit. Signals from the control unit are connected to each component within the processor
to supervise its operation.
The final thing that must be explained is how the ARM will be used and the way in which the
chip appear. The various signals that interface with the processor are input, output or supervisory
signals which will be used to control the ARM operation.
ARM Functional Diagram
APPLICATION OF MICROCONTROLLER IN
PROJECTS
The project shows resemblance as you are travelling in metro train. It will display three stations
at LCD and a stepper motor to rotate clock or anti-clock wise.
The voting system for four candidates with memory backup to restore the results to be viewed
with password. Now-a-days Electronic voting machines are being used effectively. The
confidence of the voter in its flawless working is gradually building up and these machines are
thus becoming quite popular throughout the country. Features of the electronic voting machine
include avoidance of invalid votes and reduction of counting time and the consequent
expenditure incurred on manpower deployment. By using the Microcontroller the voting
machine can be built up easily and it will make simple to operate.
The project comprises 30 keys to edit any message in English. One can restore the message in
memory IC. The 16 characters at a time can be view in running mode.
The project will operate the stepper motor in almost all modes viz. clock, anti -clock, speed
It can indicate the level and control the water pump at top level filling. The present concept
implements controlling of pump which pumps water from the sump (underground tank) to the
overhead tank, using 8951 microcontroller. The control panel, i.e. the main control unit of the
system which consists of the primary control switches, pump indicator, siren and level
indicators..
A simple stepper motor controller circuit with direction change only. A stepper motor (or step
motor) is a brushless, synchronous electric motor that can divide a full rotation into a large
number of steps. The motor’s position can be controlled precisely without any feedback
mechanism (see Open-loop controller), as long as the motor is carefully sized to the application.
Stepper motors are similar to switched reluctance motors (which are very large stepping motors
with a reduced pole count, and generally are closed-loop commutated.)
The circuit shows the demo of auto shifting of gears using stepper motor with the change in
speed of vehicle. One can change the speed of DC motor as actual vehicle running wheel.
Motorcycle is widely used around the world. The gear shifting system of the motorcycle is
conventionally manual. This paper covers development of an indigenous automatic gear
shifting/changing system for the standard motorcycle. By this system the manual mechanical
gear-shifting system will remain unchanged because an additional electro-mechanical system is
placed on the vehicle to shift the gear and for automatic controlling the clutch. So the system has
both the options manual as well as automatic. This system uses low-cost microcontrollers to
make the accurate decision for shifting the gear up and down by observing the speed, and it
controls the clutch transmission where necessary. The complete hardware and software has been
tested and the functioning of the automatic gear shifting system is verified.
The project is to read the rpm of an automobile and according to that it limits the speed as Speed
Governor. One can change the speed with variable control. This Project can be used with the
three phase Induction motors. The circuit will take the full control of the motor and it will protect
the motor from several faults such us over voltage and under voltage and the circuit will switch
on the motor under safety conditions. The circuit was fully controlled by the microcontroller and
the microcontroller wills continuously monitors the voltages of the three phases and if the
voltage goes abnormal then it will switch off the motor until they are normal. All the conditions
are displayed it over the LCD display. In our project we are using the popular 8 bit
microcontroller AT89S52. It is a 40 pin microcontroller.
Useful for Quiz games, dumb charades. It displays the player no. along with the beep for seven
players.
It will display the room temperature on LCD and one can set the desired value to indicate the
alarm or control at a desired temperature. It uses an ADC to interface with LM-35 sensor.
One can operate (on/off) four electrical devices with TV remote synchronized with circuit
independently.
It can resolve the time difference (may be few milliseconds) and indicate the correct ranking
between the individuals denoted A to H
13. MICROCONTROLLER AT-89C51 BASED AUTO SPEED
The project is to read the rpm of a automobile and according to that it limits the speed as Speed
Governor. One can change the speed with variable control.
A Robotic car that follows the black line at the floor area based on IR sensors with transmitters
and receivers.
A robotic car that follows his master who is sending an IR transmission always.
The project will show the names of person who had pressed the RFID key on LCD. One can use
DATA encoder/decoder circuit.
USING LCD:
The project will check the unknown frequency input up to 200 KHz. And display at LCD.
It can actually control traffic with lights and humanoid robot police man rotating in all directions
with hand movements for stop and go actions. This is a project comprises two stepper motors to
perform the action.
20. MICROCONTROLLER AT-89C2051 BASED IR WIRELESS
FREQUENCY COUNTER:
The project will check the unknown frequency input up to 200KHz. Coming from an IR source
and display at LCD.