You are on page 1of 114

BSc Electronics, 6th Semester

6B13ELE:
EMBEDDED SYSTEMS BASICS

Dr Jinesh Mathew
MSc., MPhil., PhD, Post Doc
INTRODUCTION TO EMBEDDED SYSTEMS
An embedded system is an electronic/electro-mechanical system designed to perform
a specific function and is a combination of both hardware and firmware(software).
Every embedded system is unique, and the hardware as well as the firmware is highly
specialised to the application domain.
An embedded system is designed to run on its own without human intervention, and
may be required to respond to events in real time.
Application Areas
• TV
• stereo
• remote control
• phone / mobile phone
• refrigerator
• microwave
• washing machine
• electric tooth brush
• oven / rice or bread cooker
• watch
• alarm clock
• electronic musical instruments
• electronic toys (stuffed animals,handheld toys, pinballs, etc.)
• medical home equipment (e.g. blood
pressure, thermometer)
•…
• [PDAs?? More like standard computer system]

Consumer Products
Application Areas
• Medical Systems
– pace maker, patient monitoring systems,
– injection systems, intensive care units, …
• Office Equipment
– printer, copier, fax, …
• Tools
– multimeter, oscilloscope, line tester, GPS, …
• Banking
– ATMs, statement printers, …
• Transportation
– (Planes/Trains/[Automobiles] and Boats)
• radar, traffic lights, signalling systems, …
Application Areas
• Automobiles
– engine management, trip computer (fuel
cons. etc), cruise control, immobilizer
and keyless entry, car alarm,
– airbag, ABS, Electronic steering, …
• Building Systems
– elevator, heater, air conditioning,
lighting, key card entries, locks, alarm
systems, …
• Agriculture
– feeding systems, milking systems, …
• Space
– satellite systems, …
Categories of embedded systems
Components of an Embedded System
• An embedded system has three main components : Hardware,
Software and Real time operating system

i) Hardware:
• Power Supply
• Processor
• Memory
• Timers
• Serial communication ports
• Output/Output circuits
• System application specific circuits
Components of an Embedded System…
ii)Software: The application softwar

Software architecture
e is required to perform the series o
f tasks.

An embedded system has software


designed to keep in view of three co
nstraints
• Availability of System Memory
• Availability of processor speed
•The need to limit power dissipation
when running the system continuou
sly in
cycles of wait for events, run, stop a
nd wake up.
Components of an Embedded System…
iii) Real Time Operating System: (RTOS) It supervises the application software
and provides a mechanism to let the processor run a process as per scheduling an
d do the switching from one process (task) to another process.

What are the various embedded system requirements


• Types of requirements imposed by embedded applications:
• Functional requirements
• Temporal requirements
• Dependability requirements
• What are the temporal requirements?
• Tasks may have deadlines • Minimal latency jitter • Minimal error detection
latency • Timing requirements due to tight software control loops • Human
interface requirements.
Processors in embedded systems
• Embedded processors can be broken into two broad categories.
• Ordinary microprocessors (μP) use separate integrated circuits for memory and
peripherals.
• Microcontrollers (μC) have on-chip peripherals, thus reducing power consumption, size
and cost.
• In contrast to the personal computer market, many different basic CPU
architectures are used, since software is custom-developed for an
application and is not a commodity product installed by the end user.
• Both Von Neumann as well as various degrees of Harvard architectures are
used.
• RISC as well as non-RISC processors are found.
• Word lengths vary from 4-bit to 64-bits and beyond, although the most
typical remain 8/16-bit.
• Most architectures come in a large number of different variants and shapes,
many of which are also manufactured by several different companies.
• Numerous microcontrollers have been developed for embedded systems
use. General-purpose microprocessors are also used in embedded systems,
but generally require more support circuitry than microcontrollers.
Ready-made computer boards
• PC/104 and PC/104+ are examples of standards for ready-made computer boards
intended for small, low-volume embedded and ruggedized systems, mostly x86-based.
These are often physically small compared to a standard PC, although still quite large
compared to most simple (8/16-bit) embedded systems. They often
use DOS, Linux, NetBSD, or an embedded real-time operating system such
as MicroC/OS-II, QNX or VxWorks. Sometimes these boards use non-x86 processors.
• In certain applications, where small size or power efficiency are not primary concerns,
the components used may be compatible with those used in general purpose x86
personal computers. Boards such as the VIA EPIA range help to bridge the gap by being
PC-compatible but highly integrated, physically smaller or have other attributes making
them attractive to embedded engineers. The advantage of this approach is that low-
cost commodity components may be used along with the same software development
tools used for general software development. Systems built in this way are still
regarded as embedded since they are integrated into larger devices and fulfill a single
role. Examples of devices that may adopt this approach are ATMs and arcade
machines, which contain code specific to the application.
Ready-made computer boards
• However, most ready-made embedded systems boards are not PC-centered and do not
use the ISA or PCI buses. When a system-on-a-chip processor is involved, there may be
little benefit to having a standarized bus connecting discrete components, and the
environment for both hardware and software tools may be very different.
• One common design style uses a small system module, perhaps the size of a business
card, holding high density BGA chips such as an ARM-based system-on-a-
chip processor and peripherals, external flash memory for storage, and DRAM for
runtime memory. The module vendor will usually provide boot software and make
sure there is a selection of operating systems, usually including Linux and some real
time choices. These modules can be manufactured in high volume, by organizations
familiar with their specialized testing issues, and combined with much lower volume
custom mainboards with application-specific external peripherals.
• Implementation of embedded systems have advanced, embedded systems can easily
be implemented with already made boards which are based on worldwide accepted
platform. These platforms include, but are not limited to, Arduino and Raspberry Pi.
ASIC and FPGA solutions
• A common array for very-high-volume embedded systems is
the system on a chip (SoC) which contains a complete system
consisting of multiple processors, multipliers, caches and interfaces
on a single chip. SoCs can be implemented as an application-specific
integrated circuit (ASIC) or using a field-programmable gate
array (FPGA).
ARM processor
• An ARM processor is one of a family of CPUs based on the RISC (reduced
instruction set computer) architecture developed by Advanced RISC Machines
(ARM).
• ARM makes 32-bit and 64-bit RISC multi-core processors. RISC processors are
designed to perform a smaller number of types of computer instructions so that
they can operate at a higher speed, performing more millions of instructions per
second (MIPS). By stripping out unneeded instructions and optimizing
pathways, RISC processors provide outstanding performance at a fraction of the
power demand of CISC (complex instruction set computing) devices.
• ARM processors are extensively used in consumer electronic devices
• such as smartphones, tablets, multimedia players and other mobile devices,
such as wearables. Because of their reduced instruction set, they require
fewer transistors, which enables a smaller die size for the integrated circuitry
(IC). The ARM processor’s smaller size, reduced complexity and lower power
consumption makes them suitable for increasingly miniaturized devices.
ARM processor…
• ARM processor features include: • The simplified design of ARM processors
• Load/store architecture. enables more efficient multi-core processing
and easier coding for developers. While they
• An orthogonal instruction set. don't have the same raw
• Mostly single-cycle execution. compute throughput as the products
• Enhanced power-saving design. of x86 market leader Intel, ARM processors
sometimes exceed the performance of Intel
• 64 and 32-bit execution states for processors for applications that exist on both
scalable high performance. architectures.
• Hardware virtualization support.

• The ARM architecture is a widely used 32-bit RISC processor architecture. In fact, the ARM
family accounts for about 75% of all 32-bit CPUs, and about 90% of all embedded 32-bit
CPUs. ARM Limited licenses several popular microprocessor cores to many vendors (ARM
does not sell physical microprocessors). Originally ARM stood for Advanced RISC Machines.
ARM Microprocessors
• Some cores offered by ARM:
• ARM7TDMI
• ARM9
• ARM11
• Some examples of ARM based processors:
• Intel X-Scale (PXA-255 and PXA-270), used in Palm PDAs
• Philips LPC2000 family (ARM7TDMI-S core), LPC3000 family (ARM9 core)
• Atmel AT91SAM7 (ARM7TDMI core)
• ST Microelectronics STR710 (ARM7TDMI core)
• Freescale MCIMX27 series (ARM9 core)
• The lowest-cost ARM processors (in the LPC2000 series) have dropped
below US$ 5 in ones, which is less than the cost of many 16-bit and 8-bit
microprocessors.
PIC microcontroller
• PIC (usually pronounced as "pick") is a family of microcontrollers made
by Microchip Technology, derived from the PIC1650 originally developed
by General Instrument's Microelectronics Division. The name PIC initially
referred to Peripheral Interface Controller. The first parts of the family were
available in 1976; by 2013 the company had shipped more than twelve billion
individual parts, used in a wide variety of embedded systems.
• Early models of PIC had read-only memory (ROM) or field-programmable
EPROM for program storage, some with provision for erasing memory. All
current models use flash memory for program storage, and newer models allow
the PIC to reprogram itself. Program memory and data memory are separated.
Data memory is 8-bit, 16-bit, and, in latest models, 32-bit wide. Program
instructions vary in bit-count by family of PIC, and may be 12, 14, 16, or 24 bits
long. The instruction set also varies by model, with more powerful chips adding
instructions for digital signal processing functions.
PIC microcontroller
• The hardware capabilities of PIC devices range from 6-pin SMD, 8-pin DIP chips
up to 144-pin SMD chips, with discrete I/O pins, ADC and DAC modules, and
communications ports such as UART, I2C, CAN, and even USB. Low-power and
high-speed variations exist for many types.
• The manufacturer supplies computer software for development known
as MPLAB X, assemblers and C/C++ compilers, and programmer/debugger
hardware under the MPLAB and PICKit series. Third party and some open-
source tools are also available. Some parts have in-circuit programming
capability; low-cost development programmers are available as well as high-
production programmers.
• PIC devices are popular with both industrial developers and hobbyists due to
their low cost, wide availability, large user base, extensive collection of
application notes, availability of low cost or free development tools, serial
programming, and re-programmable Flash-memory capability.
PIC microcontroller
• The PIC architecture is characterized by its multiple attributes:
• Separate code and data spaces (Harvard architecture).
• A small number of fixed-length instructions
• Most instructions are single-cycle (2 clock cycles, or 4 clock cycles in 8-bit models), with one
delay cycle on branches and skips
• One accumulator (W0), the use of which (as source operand) is implied (i.e. is not encoded in
the opcode)
• All RAM locations function as registers as both source and/or destination of math and other
functions.[22]
• A hardware stack for storing return addresses
• A small amount of addressable data space (32, 128, or 256 bytes, depending on the family),
extended through banking
• Data-space mapped CPU, port, and peripheral registers
• ALU status flags are mapped into the data space
• The program counter is also mapped into the data space and writable (this is used to
implement indirect jumps).
• There is no distinction between memory space and register space because the
RAM serves the job of both memory and registers, and the RAM is usually just
referred to as the register file or simply as the registers.
Programming languages and tools for Embedded systems
• Embedded system software.
• Assembly languages, high level languages.
• Embedded C programming ( Eg: Kiel C, Microchip C, SDCC Compiler).
• PIC in keil C (uVision IDE).

What is meant by embedded programming?


• Embedded systems programming is the programming of
an embedded system in some device using the
permitted programming interfaces provided by that system.
• Embedded Java is an example of a development environment
for programming embedded systems that will execute Java programs.
Which programming language is used for embedded
systems?
• Code is typically written in C or C++, but various high-level programming
languages, such as Python and JavaScript, are now also in common use to target
microcontrollers and embedded systems. Ada is used in some military and
aviation projects.

Why C is used in embedded systems?


• C is the most widely used programming language for embedded
processors/controllers. ... As assembly language programs are specific
to a processor, assembly language didn't offer portability
across systems. To overcome this disadvantage, several high level
languages, including C, came up.
What is embedded C software?
• Embedded C is a set of language extensions for the C programming language by
the C Standards Committee to address commonality issues that exist between C
extensions for different embedded systems.
• The embedded software decides functioning of
the embedded system. Embedded C language is most frequently used to
program the microcontroller. Earlier, many embedded applications were
developed using assembly level programming.

What is embedded C++ programming?


• Embedded C++ (EC++) is a dialect of the C++ programming language for
embedded systems. It was defined by an industry group led by major Japanese
central processing unit (CPU) manufacturers, including NEC, Hitachi, Fujitsu, and
Toshiba, to address the shortcomings of C++ for embedded applications.
What is Keil C software?
• The Keil C51 C Compiler for the 8051 microcontroller is the most popular 8051 C
compiler in the world. It provides more features than any other 8051 C compiler
available today.
What is Keil Uvision 4?
• The µVision IDE combines project management, run-time environment, build
facilities, source code editing, and program debugging in a single powerful
environment. µVision is easy-to-use and accelerates your embedded software
development.
Embedded operating system
• An embedded operating system is a specialized OS for use in
embedded system (the computers built into larger systems).
An embedded system is a computer that is part of a different kind of
machine.

Is Android an embedded operating system?


• Android offers several advantages over proprietary embedded
operating systems, not the least of which is global familiarity in
developing for the platform. Other advantages include a stable kernel,
no royalties or licensing fees, and a vast library of open source code
and device drivers.
Module 2
• PIC Microcontroller: Architecture – memory organization – addressing
modes – instruction set – I/O port, RAM & ROM Allocation, Timer -
Interrupts, I2C bus-A/D converter-UART
PIC microcontroller
• PIC microcontroller was developed in the year 1993 by
microchip technology.
• The term PIC stands for Peripheral Interface Controller.
• These microcontrollers are very fast and easy to execute a
program compared with other microcontrollers.
• PIC Microcontroller architecture is based on Harvard
architecture.
• PIC microcontrollers are very popular due to their ease of
programming, wide availability, easy to interfacing with other
peripherals, low cost, large user base and serial programming
capability (reprogramming with flash memory), etc.
PIC Architecture
• PIC microcontroller architecture consists of RAM, ROM, CPU, timers, counters
and supports the protocols such as SPI, CAN, and UART for interfacing with other
peripherals.
• At present PIC microcontrollers are extensively used for industrial purpose due
to low power consumption, high performance ability and easy of availability of
its supporting hardware and software tools like compilers, debuggers and
simulators.
• Every PIC microcontroller architecture consists of some registers and stack where
registers function as Random Access Memory( RAM) and stack saves the return
addresses. The main features of PIC microcontrollers are RAM, flash memory,
Timers/Counters, EEPROM, I/O Ports, USART, CCP (Capture/Compare/PWM
module), SSP, Comparator, ADC (analog to digital converter), PSP(parallel slave
port), LCD and ICSP (in circuit serial programming)
• The 8-bit PIC microcontroller is classified into four types on the basis of internal
architecture such as Base Line PIC, Mid Range PIC, Enhanced Mid Range PIC and
PIC18
PIC Architecture
• The
PIC microcont
roller architec
ture
comprises of
CPU, I/O
ports,
memory
organization,
A/D
converter,
timers/counte
rs, interrupts,
serial
communicati
on, oscillator
and CCP
module which
are discussed
in detailed
below.
CPU (Central Processing Unit)
• It is not different from other microcontrollers CPU and the
PIC microcontroller CPU consists of the ALU, CU, MU and accumulator,
etc. Arithmetic logic unit is mainly used for arithmetic operations and to take
logical decisions. Memory is used for storing the instructions after processing. To
control the internal and external peripherals, control unit is used which are
connected to the CPU and the accumulator is used for storing the results and
further process.
Memory Organization
• The memory module in the PIC microcontroller architecture consists
of RAM (Random Access Memory), ROM (Read Only Memory) and
STACK.
Random Access Memory (RAM)
• RAM is an unstable memory which is used to store the data temporarily in its registers. The
RAM memory is classified into two banks, and each bank consists of so many registers. The
RAM registers are classified into two types: Special Function Registers (SFR) and General
Purpose Registers (GPR).
General Purpose Registers (GPR)
• These registers are used for general purpose only as the name implies. For example, if we want
to multiply two numbers by using the PIC microcontroller. Generally, we use registers for
multiplying and storing the numbers in other registers. So these registers don’t have any
special function,- CPU can easily access the data in the registers.
Special Function Registers (SFR)
• These registers are used for special purposes only as the name SFR implies. These registers will
perform according to the functions assigned to them , and they cannot be used as normal
registers. For example, if you cannot use the STATUS register for storing the data, these
registers are used for showing the operation or status of the program. So, user cannot change
the function of the SFR; the function is given by the retailer at the time of manufacturing.
Memory Organization
Read Only Memory (ROM)
• Read only memory is a stable memory which is used to store the data
permanently. In PIC microcontroller architecture, the architecture ROM stores
the instructions or program, according to the program the microcontroller acts.
The ROM is also called as program memory, wherein the user will write the
program for microcontroller and saves it permanently, and finally the program
is executed by the CPU. The microcontrollers performance depends on the
instruction, which is executed by the CPU.

Electrically Erasable Programmable Read Only


Memory (EEPROM)
• In the normal ROM, we can write the program for only once we cannot use
again the microcontroller for multiple times. But, in the EEPROM, we can
program the ROM multiple times.
Flash Memory
• Flash memory is also programmable read only memory (PROM) in
which we can read, write and erase the program thousands of times.
Generally, the PIC microcontroller uses this type of ROM.

Stack
• When an interrupt occurs, first the PIC microcontroller has to execute
the interrupt and the existing process address. Then that is being
executed is stored in the stack. After completing the execution of the
interrupt, the microcontroller calls the process with the help of
address, which is stored in the stack and get executes the process.
I/O Ports
• The series of PIC16 consists of five ports such as Port A, Port B, Port C,
Port D & Port E.
• Port A is an 6-bit port that can be used as input or output port based
on the status of the TRISA (Tradoc Intelligence Support Activity)
register.
• Port B is an 8- bit port that can be used as both input and output
port.
• Port C is an 8-bit and the input of output operation is decided by the
status of the TRISC register.
• Port D is an 8-bit port acts as a slave port for connection to the
microprocessor BUS.
• Port E is a 3-bit port which serves the additional function of the
control signals to the analog to digital converter.
BUS
• BUS is used to transfer and receive the data from one peripheral to
another. It is classified into two types such as data bus and address
bus.
• Data Bus: It is used for only transfer or receive the data.
• Address Bus: Address bus is used to transmit the memory address
from the peripherals to the CPU. I/O pins are used to interface the
external peripherals; UART and USART both are serial communication
protocols which are used for interfacing serial devices like GSM, GPS,
Bluetooth, IR , etc.
BUS
A/D converters
• The main intention of this analog to digital converter is to convert analog voltage values to
digital voltage values. A/D module of PIC microcontroller consists of 5 inputs for 28 pin devices
and 8 inputs for 40 pin devices. The operation of the analog to digital converter is controlled by
ADCON0 and ADCON1 special registers. The upper bits of the converter are stored in register
ADRESH and lower bits of the converter are stored in register ADRESL. For this operation, it
requires 5V of an analog reference voltage.
Timers/ Counters
• PIC microcontroller has four timer/counters wherein the one 8-bit
timer and the remaining timers have the choice to select 8 or 16-bit
mode. Timers are used for generating accuracy actions, for example,
creating specific time delays between two operations.

Interrupts
• PIC microcontroller consists of 20 internal interrupts and three
external interrupt sources which are associated with different
peripherals like ADC, USART, Timers, and so on.
Serial Communication
• Serial communication is the method of transferring data one bit at a time sequentially over a
communication channel.
• USART: The name USART stands for Universal synchronous and Asynchronous Receiver and
Transmitter which is a serial communication for two protocols. It is used for transmitting and
receiving the data bit by bit over a single wire with respect to clock pulses. The PIC
microcontroller has two pins TXD and RXD. These pins are used for transmitting and receiving
the data serially.
• SPI Protocol: The term SPI stands for Serial Peripheral Interface. This protocol is used to send
data between PIC microcontroller and other peripherals such as SD cards, sensors and shift
registers. PIC microcontroller support three wire SPI communications between two devices on
a common clock source. The data rate of SPI protocol is more than that of the USART.
• I2C Protocol: The term I2C stands for Inter Integrated Circuit , and it is a serial protocol which
is used to connect low speed devices such as EEPROMS, microcontrollers, A/D converters, etc.
PIC microcontroller support two wire Interface or I2C communication between two devices
which can work as both Master and Slave device.
Serial Communication
Oscillators
• Oscillators are used for timing generation. Pic microcontroller consist
of external oscillators like RC oscillators or crystal oscillators. Where
the crystal oscillator is connected between the two oscillator pins.
The value of the capacitor is connected to every pin that decides the
mode of the operation of the oscillator. The modes are crystal mode,
high-speed mode and the low-power mode. In case of RC oscillators,
the value of the resistor & capacitor determine the clock frequency
and the range of clock frequency is 30KHz to 4MHz.
CCP module
• The name CCP module stands for capture/compare/PWM where it works
in three modes such as capture mode, compare mode and PWM mode.
• Capture Mode: Capture mode captures the time of arrival of a signal, or
in other words, when the CCP pin goes high, it captures the value of the
Timer1.
• Compare Mode: Compare mode acts as an analog comparator. When the
timer1 value reaches a certain reference value, then it generates an
output.
• PWM Mode: PWM mode provides pulse width modulated output with a
10-bit resolution and programmable duty cycle.
PIC Microcontroller Applications
• The PIC microcontroller projects can be used in different applications, such as
peripherals, audio accessories, video games, etc. For better understanding of this
PIC microcontroller, the following project demonstrates PIC microcontroller’s
operations.
Street Light that Glows on Detecting Vehicle Movement:
• The main intention of this project is to detect the movement of vehicles on
highways to switch on a block of street lights ahead of it, and also switch off the
trailing lights to conserve energy. In this project, a PIC microcontroller is done by
using assembly language or embedded C.
• The power supply gives the power to the total circuit by stepping
down, rectifying, filtering and regulating AC mains supply. When there
are no vehicles on highway, then all lights will turn OFF so that the
power can be conserved. The IR sensors are placed on the road to
sense the vehicle movement. When there are vehicles on highway,
then the IR sensor senses the vehicle movement immediately, it
sends the commands to the PIC microcontroller to switch ON/OFF the
LEDs. A bunch of LEDS will be turned on when a vehicle come near to
the sensor and once the vehicle passes away from the sensor the
intensity will become lower than the LEDs will turn OFF
Advantages of PIC Microcontroller:
• PIC microcontrollers are consistent and faulty of PIC percentage is very
less. The performance of the PIC microcontroller is very fast because of
using RISC architecture.
• When comparing to other microcontrollers, power consumption is very
less and programming is also very easy.
• Interfacing of an analog device is easy without any extra circuitry

Disadvantages of PIC Microcontroller:


• The length of the program is high due to using RISC architecture (35
instructions)
• One single accumulator is present and program memory is not accessible
PIC Instruction set
• All the processors in the PIC family have essentially the same instruction set of
35 RISC instructions.
• All 12xxx and 16xxx processors function with this instruction set.
• For 17xxx and 18xxx family the number of instructions and features are
expanded. For 17xxx family 56 instructions in total including the standard 35
instructions. For 18xxx family the total number of instructions are 85.
• The ‘F’ version processors has a flash memory and can be programmed many
times. While the ‘C’ version processors can be programmed only once, but it is
cheaper than the ‘F’ version
• The special function registers are addressed in the RAM space of 256 bytes.
• All the SFR are located in four banks. The SFR banks are selected by two bits in
the status register (RS0 &RS1).
• The SFR map of a processor gives details of SFR addresses and free RAM
locations
Addressing modes
• Immediate addressing mode
• Direct addressing mode
• Indirect addressing mode
• Bit oriented addressing
• Direct Addressing Mode: In direct addressing mode 7 bits (0-6) of the
instruction identify the register file address and the 8 th bit of the register file
address register bank select bit(RP0).
• The below diagram explains the method of accessing register file address 13H
by direct addressing method.
• Indirect Addressing Mode: In the indirect addressing mode the 8-bit
register file address is first written into a Special Function Register(SFR)
which acts as a pointer to any address location in the register file. A
subsequent direct access of INDF will actually access the register file using
the content of FSR as a pointer to the desired location of the operand.

Reading from EEPROM Memory


• Setting the RD bit initializes transfer of data from address found in EEADR
register to EEDATA register. As in reading data we don't need so much time as
in writing, data taken over from EEDATA register can already be used further in
the next instruction.
• Sample of the part of a program which reads data in EEPROM, could
look something like the following:

• After the last program instruction, contents from an EEPROM address


zero can be found in working register w.
Writing to EEPROM Memory
• In order to write data to EEPROM location, programmer must first
write address to EEADR register and data to EEDATA register. Only
then is it useful to set WR bit which sets the whole action in motion.
WR bit will be reset, and EEIF bit set following a writing what may be
used in processing interrupts. Values 55h and AAh are the first and
the second key whose disallow for accidental writing to EEPROM to
occur. These two values are written to EECON2 which serves only that
purpose, to receive these two values and thus prevent any accidental
writing to EEPROM memory. Program lines marked as 1, 2, 3, and 4
must be executed in that order in even time intervals. Therefore, it is
very important to turn off interrupts which could change the timing
needed for executing instructions. After writing, interrupts can be
enabled again.
• Example of the part of a program which writes data 0xEE to first
location in EEPROM memory could look something like the following:
INSTRUCTION SET
• While writing the instructions the
following guidelines are followed.
a) Write the instructions mnemonics
in lower case (example: xorwf)
b) Write special Register names, RAM
variable names and bit names in
upper case (example: STATUS,
RPO….)
c) Write instruction and subroutine
labels in mixed case (example:
Mainline, LoopTime..)
The instruction set of PIC is divided into Three
basic categories.
(a) Byte oriented Instructions
(b) Bit oriented Instructions
(c) Literal and Control Instructions
Byte Oriented Instructions
• In a byte oriented Instructions f represents a file register and d
represents destination register. The destination specifies where the
result of operation is to be placed. If D= 0 the result is placed in W
register(Accumulator) and if d = 1 , the result is placed in the file
register specified in the instruction.
• ADDWF f, d : Add W and f
• CLRF f : Clear f
• MOVWF f ,d : Move f
• NOP : No operation
• SUBWF f ,d : Subtract W from f
Bit Oriented Instruction
• In bit oriented instructions, b represents a bit field designator which
selects the number of the bit affected by the operation and f
represents the number of the file in which the bit is located.
• BCF f , b : Bit clear f
• BSF f, b : Bit set f
• BTFSC f , b : Bit test f ,skip if set
Literal and Control Instructions
• In literal and control instructions K represents an 8 or 11 bit constant
or literal value.
• ADDLW k : Add literal and W
• ANDLW k : AND literal with W
• CALL k : Call subroutine
• MOVLW k : Move literal to W
• SUBLW k : Subtract W from literal
CLASSIFICATION OF INSTRUCTIONS BASED ON
TYPE OF OPERATION
(i). Arithmetic Operations
• ADDLW k : Add literal value k to W
• ADDWF f, d : The contents of the W register are added with the register f.
• SUBWF f ,d : the contents of W register are subtracted from register f

(ii). Logical Instructions


• ANDLW k : The contents of W register are ANDED with the 8-bit literal k. The result is
stored in the W register.
• IORLW k : Inclusive OR the literal value into W register
• XORWF f, d : The contents of W register are XORed with register f and the result is
stored in W or f.
• COMF f, d : Complement f .
(iii). Increment/Decrement Instructions
• INCF f,d : Increment contents of f register by 1
• DECF f , d : Decrement f by 1

(iv). Data Transfer instructions


• MOVF f, d : Move f to W i.e The contents of register f is moved to a destination
depending on d
• MOVLW k : Move literal k to W
• MOVWF f : Move W to f

(v). Clear Instructions


• CLRF : Clear file f
• CLR W : Clear the contents of W register and zero bit is set
• CLRWDT : Clear Watch dog timer
• BCF : Clear bit b of register f.

(vi). Rotate Instructions


• RLF : Rotate Left f through carry
• RRF : Rotate Right f through carry
(vii). Branch Instructions
There are two types of Branch instructions.
(i) Conditional Branch instructions
(ii) Un conditional Branch instructions.

(i) Conditional Branch Instructions


BTFSC f , b : Bit Test skip if clear
BTFSS f , b : Bit test f , skip if set
If bit B in register f is zero, then the next instruction is executed,
otherwise next instruction is discarded and a NOP is executed.

DECFSZ f,d : Decrement f, skip if zero.


INCFSZ f,d : Increment f, skip if zero
(ii) Unconditional Instructions
• CALL k : Call the subroutine k unconditionally
• GOTO k : Unconditional k branch
• RETURN : Return from subroutine
• REETLW k : Return with literal in W register.

(viii) Miscellaneous
• BSF f,b : Set bit b of register f
• SLEEP : Go into stand by mode
• NOP : No operation i.e Do nothing , wait one clock cycle.
Instruction Execution Period
• All instructions are executed in one cycle except for conditional
branch instructions if condition was true, or if the contents of
program counter was changed by some instruction. In that case,
execution requires two instruction cycles, and the second cycle is
executed as NOP (No Operation).
• Four oscillator clocks make up one instruction cycle.
• If we are using an oscillator with 4MHz frequency, the normal time for
executing an instruction is 1 µs, and in case of conditional branching,
execution period is 2 µs.
TIMER MODULES:
• There are three completely independent Timers available in PIC
16F8XX Microcontrollers. They are
• Timer 0
• Timer 1 and
• Timer 2
Timer 0:
• The Timer 0 module is a simple 8-bit overflow counter.
• The clock source can be either the internal system clock (Fosc/4) or an
external clock. When the clock source is an external clock, the Timer0
module can be selected to increment on either the rising or falling edge.
• The Timer 0 module also has a programmable prescaler option. This
prescaler can be assigned to either the Timer0 module or the Watchdog
Timer. Bit PSA assigns the prescaler and bits PS2:PSO determine the
prescaler value.
• TMR0 can increment at the following rates:1:1 when the prescaler is
assigned to Watchdog Timer, 1:2, 1:4, 1:8, 1:16, 1:32, 1:64, 1:128and 1:256.
• Synchronization of the external clock occurs after the prescaler. When the
prescaler is used, the external clock frequency may be higher than the
device’s frequency.
• The maximum frequency is 50 MHz, given the high and low time
requirements of the clock.
Timer 1
• Timer1 is a 16-bit timer/counter.
• The clock source can be either the internal systemclock (Fosc/4), an external
clock, or an external crystal.
• Timer1 can operate as either a timer or a counter.
• When operating as a counter (external clock source), the counter can
either operate synchronized to the device or asynchronously to the device.
• Asynchronous operation allows Timer1 to operate during sleep, which is
useful for applications that require a real-timeclock as well as the
power savings of SLEEP mode.
• Timer 1 also has a prescaler option, which allows TMR1 to increment at the
following rates: 1:1, 1:2, 1:4 and 1:8 TMR1 can be used in conjunction with
the Capture/Compare/PWM module.
• When used with a CCP module, Timer1 is the time-base for 16-bit capture
or 16-bit compare and must be synchronized to the device.
Timer 2
• Timer 2 is an 8bit timer with a programmable prescaler and a programmable
postscaler, as well as an 8- bit Period Register (PR2).
• Timer 2 can be used with the CCP module (in PWM mode) as well as the Baud
Rate Generator for the Synchronous Serial Port(SSP).
• The prescaler option allows Timer2 to increment at the following rates: 1:1,
1:4 and 1:16.
• The post scaler allows TMR2 register to match the period register (PR2) a pro
grammable number of times before generating an interrupt.
• The postscaler can be programmed from 1:1 to 1:16 (inclusive).
WATCH DOG TIMER (WDT):
• The Watchdog Timer is a free running on-chip RC oscillator which does
not require any external components.
• This RC oscillator is separate from the RC oscillator of theOSC1/CLKIN
pin. That means that the WDT will run, even if the clock on the
OSC1/CLKIN and OSC2/CLKOUT pins of the device has been stopped, for
example, by execution of a SLEEP instruction.
• During normal operation, a WDT time-out generates a device reset. If the
device is in SLEEP mode, a WDT time-out causes the device to wake-up
and continue with normal operation.
• The WDT can be permanently disabled by clearing configuration bit
WDTE.
WDT PERIOD:
• The WDT has a nominal time-out period of 18 ms, (with no prescaler).
• The time-out periods vary with temperature, VDD and process variations from
part to part (see DC specs).
• If longer time-out periods are desired, a prescaler with a division ratio of up to
can be assigned to the WDT under software control by writing to the OPTION
register. Thus, time-out periods up to seconds can be realized.
• The CLRWDT and SLEEP instructions clear the WDT and the postscaler, if
assigned to the WDT, and prevent it from timing out and generating a device
RESET condition.
• The TO bit in the STATUS register will be cleared upon a WDT time-out.
• WDT PROGRAMMING CONSIDERATIONS:
It should also be taken in account that under worst case conditions (VDD=
Min., Temperature = Max., max WDT prescaler) it may take several seconds
before a WDT time-out occurs.
Module 3
• Embedded system software.
• Assembly languages, high level languages.
• Embedded C programming ( Eg: Kiel C, Microchip C and SDCC Compiler).
• Data types, variables, port accessing, function.
• PIC in keil C (uVision IDE).
• Simple programs -LED blinking, LCD, Serial port.
• Embedded communication standards
• RS232, I2C, SPI ,USB (Over view).
• Case study of Traffic Light controller, Water level controller, DC Motor
speed control.
• Electronics manufacturing process, circuit designing, Programming, PCB
designing using software.
Differences b/n standard/ANSI C and Embedded C
• Included files
• Special function registers
• Super Loop
• Extensions to storage classes
• Special keywords must be used to specify a function as an interrupt service
routine
Difference b/n standard/ANSI C and Embedded C
• Storage classes
• Embedded C combilers supports the standard ANSI C data types
• char
• short
• int
• long
• float
• Extensions to storage classes
• Near/data
• Idata
• Far/xdata
• Pdata
• Bit
• Sfr
• Sbit
• code
Embedded C
• Programs written in C are much easier to develop and maintain than the
ones written in Assembly language
• Embedded C is a superset of standard ANSI C. Embedded C includes special
keywords to access the special features of the microcontroller for which the
program is being written.
• Due to the absence of an operating system, we use super loops while
writing C programs for microcontrollers.
• Certain keywords allow variables in C programs to be declared in the desired
memory spaces of the MCS-51 based microcontroller. These are called
storage classes. We can inform the compiler to use a default storage class for
all variables in a C program by specifying a memory model to use when
compiling the program.
Embedded C
• We can use absolute addressing for placing variables at a given address in
the external RAM
• We can manipulate individual bits of a byte-wide variable or register using
bitwise logical operators.
• Special keywords must be used to specify a function as an interrupt service
routine.
• Assembly language code can be mixed with C language code by using special
keywords.
Embedded C : sample questions
• Write three examples of embedded C compilers
• What are the main differences between the standard C and the
embedded C
• What is super loop? Why do we need super loops while writing C
programs for microcontrollers?
• What are the various storage classes that can be used with SDCC? In
which memory space are the variables placed as per each of these
storage classes.
Embedded C
• Example programs (printouts given earlier in the class)
• Blinking of LED
• Interfacing switch and LED
• Interfacing of LCD
• Serial communication
6B03ELE-P: Embedded System Practical (Practical-3)

1. One Serial Communication (RS232/UART)


2. LCD interface
3. Interfacing and Blinking of LED (3 experiments)
4. Interfacing of switch
5. Frequency Generator

Note: Assembly language programs for the above experiments (using


the STS 8051 LCD kit) are available in the user manual of the device.
LCD Display
• A liquid crystal display (LCD) is a flat panel display, electronic visual
display, or video display that uses the light modulating properties of
liquid crystals (LCs). LCs do not emit light directly. LCDs are more
energy efficient and offer safer disposal than CRTs. Its low electrical
power consumption enables it to be used in battery-powered
electronic equipment. It is an electronically modulated optical device
made up of any number of segments filled with liquid crystals and
arrayed in front of a light source (backlight) or reflector to produce
images in colour or monochrome. The most flexible ones use an array
of small pixels.
LCD Display
LCD Display
• 2 lines,
• 16 or 20 characters per line
• The display contains two byte-wide registers, one for commands
(RS=0) and the second for characters to be displayed (RS=1).
• It also contains the user programmed RAM area that can be
programmed to generate any desired character that can be formed
using a dot matrix.
LCD interfacing
• Port 1 supplies the
data byte. Port 3.2
selects the
command (0) or
data (1) registers.
Port 3.3 enables a
read (0) or write
(1) level, and port
3.4 generate an
active high-enable
strobe.
Assembly language program for LCD display
Assembly language program for LCD display…
Assembly language program for LCD display…
LCD display program for the Lab kit STS 8051
LCD display program for the Lab kit STS 8051...
LCD display program for the Lab kit STS 8051
LCD display program for the Lab kit STS 8051

Lab experiment question


• Display your name in the LCD display using 8051
LCD display program for the Lab kit STS 8051
LED Interfacing
C language code (SDCC compiler) for blinking LEDs connected to PORT2
Assembly language code for blinking LEDs
connected to PORT2
Lab experiments using STS 8051 kit
• Blink 1-8 LEDs
• Blink two LEDs alternatively
• LED pattern generation
Arrangement for LED interface experiments
26 pin IDC male connector 26 pin IDC female connector
cables and pinouts cables and pinouts
8255-I
Assembly language code for blinking 1-8 LEDs

Give additional delay here to reduce


the frequency of LED blinking
Assembly language code for blinking 2 LEDs alternatively

#01 #01 LED to PA0=ON


Give additional delay here to reduce
the frequency of LED blinking

#03 #03 Invert PA0 and PA1


Assembly code for blinking 8 LEDs like a ring counter pattern

#01 LED to PA0=ON


Give additional delay here to reduce
the frequency of LED blinking

23 RL A Move LED ON to left


Serial communication standard: USB
• Universal Serial Bus (USB) is a serial communication standard using
the Bus master-slave topology. It consists of a host acting as a master
and devices connected to the host as slaves. Very often a PC has a
USB host and peripheral devices, such as, printers, mouse, etc. have a
USB slave. A microcontroller can also have USB host functionality.
• A variant of USB device is USB On-The-Go (USB OTG). On-The-Go
allows a microcontroller to act as a USB host but with limited
capabilities.
Module 4
• Advanced embedded systems.
• ARM processors general architecture (refer to the Assignment
submitted).
• Over view of Embedded OS, Android OS.
• Real Time OS ,Embedded Linux (Examples).
Embedded operating system
• An embedded operating system is an operating system for embedded systems. This type of
operating system is typically designed to be resource-efficient and reliable. Resource efficiency
comes at the cost of losing some functionality or granularity that larger computer operating
systems provide, including functions which may not be used by the specialized applications
they run. Depending on the method used for multitasking, this type of OS is frequently
considered to be a real-time operating system, or RTOS.
• The hardware running an embedded operating system can be very limited in resources such
as RAM and ROM, therefore embedded design of these operating systems may have a narrow
scope tailored to a specific application in order to achieve desired operation under these
constraints. In order to take better advantage of the processing power of the CPU, software
developers may write critical code directly in assembly. This machine efficient language can
potentially result in gains in speed and determinism at the cost of portability and
maintainability. Often times, embedded operating systems are written entirely in more
portable languages, like C, however.
• An important difference between most embedded operating systems and desktop operating
systems is that the application, including the operating system, is usually statically linked
together into a single executable image. Unlike a desktop operating system, the embedded
operating system does not load and execute applications. This means that the system is only
able to run a single application.
Embedded operating system Examples
• Notable embedded OSs currently in use by consumers include:
Symbian - Used in cell phones, mainly ones made by Nokia.
• Embedded Linux - Of which Android is a subset, used in many other
devices like printers. ...
• iOS - Subset of Mac OS X, used in Apple's mobile devices.
Android OS
• Android is a mobile operating system developed by Google, based on a modified
version of the Linux kernel and other open source software and designed primarily
for touchscreen mobile devices such as smartphones and tablets. In addition, Google
has further developed Android TV for televisions, Android Auto for cars, and Android
Wear for wrist watches, each with a specialized user interface. Variants of Android are
also used on game consoles, digital cameras, PCs and other electronics.
• Initially developed by Android Inc., which Google bought in 2005, Android was
unveiled in 2007, with the first commercial Android device launched in September
2008. The operating system has since gone through multiple major releases, with the
current version being 8.1 "Oreo", released in December 2017.
• Android has been the best-selling OS worldwide on smartphones since 2011 and on
tablets since 2013. As of May 2017, it has over two billion monthly active users, the
largest installed base of any operating system, and as of 2017, the Google Play store
features over 3.5 million apps.
Distributi First devices to run
Version Code name Release date
on version
2.3 Gingerbread February 9, 2011 0.3% Nexus S
4.0 Ice Cream Sandwich October 19, 2011 0.4% Galaxy Nexus
4.1 Jelly Bean July 9, 2012 1.7% Nexus 7
4.2 Jelly Bean November 13, 2012 2.6% Nexus 4, Nexus 10
4.3 Jelly Bean July 24, 2013 0.7% Nexus 7 2013
4.4 KitKat October 31, 2013 12.0% Nexus 5
5.0 Lollipop November 3, 2014 5.4% Nexus 6, Nexus 9
5.1 Lollipop March 9, 2015 19.2% Android One
6.0 Marshmallow October 5, 2015 28.1% Nexus 5X, Nexus 6P
7.0 Nougat August 22, 2016 22.3% Nexus 5X, Nexus 6P
7.1 Nougat October 4, 2016 6.2% Pixel, Pixel XL
8.0 Oreo August 21, 2017 0.8% N/A
Pixel, Pixel XL, Nexus
8.1 Oreo December 5, 2017 0.3%
6P, Nexus 5X
Real time OS
• Real-time operating system is an operating system that supports the construction of real-time
systems.
• A real-time operating system (RTOS) is an operating system (OS) intended to serve real-time
applications that process data as it comes in, typically without buffer delays. Processing time
requirements (including any OS delay) are measured in tenths of seconds or shorter increments of
time. A real time system is a time bound system which has well defined fixed time constraints.
Processing must be done within the defined constraints or the system will fail. They either are event
driven or time sharing. Event driven systems switch between tasks based on their priorities while
time sharing systems switch the task based on clock interrupts.
• A key characteristic of an RTOS is the level of its consistency concerning the amount of time it takes to
accept and complete an application's task; the variability is jitter. A hard real-time operating system
has less jitter than a soft real-time operating system. The chief design goal is not high throughput, but
rather a guarantee of a soft or hard performance category. An RTOS that can usually or generally
meet a deadline is a soft real-time OS, but if it can meet a deadline deterministically it is a hard real-
time OS.
• An RTOS has an advanced algorithm for scheduling. Scheduler flexibility enables a wider, computer-
system orchestration of process priorities, but a real-time OS is more frequently dedicated to a
narrow set of applications. Key factors in a real-time OS are minimal interrupt latency and minimal
thread switching latency; a real-time OS is valued more for how quickly or how predictably it can
respond than for the amount of work it can perform in a given period of time.
What is an example of a real time operating
system?
• eCos, LynxOS, QNX, RTAI, RTLinux, Symbian OS, VxWorks, Windows
CE, MontaVista Linux.
• Of the above the real time order is: Symbian OS, Windows CE, QNX,
MontaVista, RTLinux.
• If you want to include Soft Real-Time systems, Windows 7 and stock
Linux might qualify.
Embedded Linux
• Linux is the operating system of choice for many embedded systems such as
smartphones, tablets, PDAs, set-top boxes, and personal media players. Any version
of Linux used to operate such machines is known as Embedded Linux. Linux is a
natural choice for many of these devices due to its low cost, ease of customization,
and the fact that it has already been ported to many custom-purpose
microprocessors.

• One major example of an embedded Linux is Android, developed by Google.


Android is based on a modified Linux kernel and released under an open source
license, which allows manufacturers to modify it to suit their particular hardware.
Other examples of embedded Linux include Maemo, BusyBox, and Mobilinux.
Debian, an open-source operating system which uses the Linux kernel, is used on
the embedded Raspberry Pi device in an operating system called Raspberry.

• Linux may require more system resources than some other embedded operating
systems but has a highly-tested stable kernel, is completely open source code, and
a zero distribution cost.

You might also like