SlideShare una empresa de Scribd logo
1 de 67
INTRODUCTION TO MICROCONTROLLERS AND
EMBEDDED SYSTEMS
Prepared by:

Islam Samir
-

Islam Samir Mohamed

-

Electronics and Communications department, Faculty of
Engineering, Cairo University

-

Embedded Software Engineer.
INTRODUCTION
Prequisties:
- Digital logic design, basics of combinational and sequntial
circuits.
- Basics of microprocessors.
 (A brief review will be given in the course)
- C programming language.

INTRODUCTION


-

1.
-

-

Why do we study this course?
As engineers:
Learning how microprocessors work and how to use them is
very essential for every electrical engineer in many ways:
Implementing mathmatical algorithms:
To implement an algorithm for a communication system,
control system, or any real time system we usually write a
program and load it on the target microprocessor.
Then, this microprocessor is used as a part of this system.
INTRODUCTION
2.
-

-

Minimizing the cost and power:
If this system is a part of a battery-powered device, or it’s
required to keep the device’s cost low as much as possible,
we’ve to use a cheap microprocessor.
To do so, the program should be minimized as possible and
the designer should make use of every element of the used
microprocessor/microcontroller.
INTRODUCTION

-

-

-

As Egyptians:
The development of the field of electrical engineering in Egypt
is our responsibility, not anyone else.
To face the challenges facing our country these days, we have
to be at a technical level that allows us to create new products
and compete in the global market.
To do so, we’ve to be equipped with the required knowledge
and experience to innovate and bring new ideas that gives us
the advantage in the market.
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

EMBEDDED SYSTEMS


An embedded system is a special purpose
system that is used to perform one or few
dedicated functions.



Simply, we can call any computer system
embedded inside an electronic device an
embedded system.
EMBEDDED SYSTEMS (CONT.)


Embedded systems are made to
perform few tasks only, after
implementation you can’t use
them for another purposes.

Ex. You can’t watch movies using
the microprocessor of your
microwave oven!!
EMBEDDED SYSTEMS
Examples:
Digital and analog televisions
Set-top boxes (DVDs, VCRs, Cable boxes)
Personal digital assistants (PDAs)
MP3’s and iPod's
Kitchen appliances (refrigerators ,microwave ovens)
Telephones/cell phones
Cameras
Global positioning systems
And many others.
SO.. HOW DO WE IMPLEMENT THEM?


We do so by using microcontrollers (or microprocessor based
systems).



Or simply by using the digital circuits that perform the function we
want.
COMPARISON
Digital circuits

Microprocessor based
systems

Faster
- only propagation delay.

Slower
- Technology dependent.

Inflexible
-Functions they perform
can’t be changed easily.

Flexible
- We need only to update
the software.

Example
- Communication systems
ciphering algorithms.

Example
- Personal computers,
PDA’s, Mobile phones and
PLC’s.
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

WHAT IS A MICROCONTROLLER?


It’s a full computer system on
a chip, even if its resources
are far more limited than of a
desktop personal computer.



Designed for stand alone
operations.
WHAT IS A MICROCONTROLLER? (CONT.)


So.. What’s the difference between a microcontroller and a
microprocessor system?
WHAT IS A MICROCONTROLLER? (CONT.)


A microcontroller has a processor and many peripherals integrated
with it on the same chip, like a flash memory, RAM, I/O ports, serial
communication ports, ADC …Etc.
WHAT IS A MICROCONTROLLER? (CONT.)


A timer module to allow the MCU to perform tasks
for certain time periods.



A serial I/O port to allow data to flow between the
MCU and other devices such as a PC or another
MCU.



An ADC to allow the MCU to accept analog inputs
for processing.
WHAT IS A MICROCONTROLLER? (CONT.)


But a microprocessor can’t do all the functions of a
computer system on its own, and needs another circuits to
support it like:
I/O devices, RAM, ROM, DMA controllers, Timers, ADC,
LCD drivers.. Etc.
COMPARISON
Microcontroller

General purpose microprocessor

Depend mainly on its peripherals
like:
Program memory, I/O ports,
timers, interrupt circuitry,
ADC…Etc.

Depend mainly on other devices like:
I/O devices, memory, DMA controllers
..Etc.

Used for a few dedicated functions
determined by the system
designer.

Used in many applications, according
to the program running on it

Usually used as a part of a larger
system

It’s in the heart of our PC’s.
POPULAR MICROCONTROLLERS
8051 (Intel and others)
 80386 EX (Intel)
 PIC (Microchip)




68HC05 (Motorola)



Z8 (Zilog)
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

DEVELOPING EMBEDDED SYSTEMS
Embedded systems
development

Software
development

Hardware
development
HARDWARE DEVELOPMENT


This includes choosing the right MCU for your application,
so that it can satisfy the required specifications.

The criteria for choosing a microcontroller is:
1- Number of I/O ports.
2- Serial communication modules.
3- Peripherals like (Timer, ADC, PWM ..Etc.)
4- Memory requirements.
5- Processing speed required.
6- Power requirements.


SOFTWARE DEVELOPMENT
• Writing the required algorithm using assembly
or a high level language.
• Using a compiler or assembler and a linker.

• Debugging your code.
SOFTWARE DEVELOPMENT

Compiler

Assembler
SOFTWARE DEVELOPMENT


Using assembly involves learning the used microcontroller's
specific instruction set but results in the most compact and fastest
code.



Using C programming language makes your code portable,
which means that you can use it for another target microcontroller
without learning its instruction set, this eases the process of
software development (short time to market) with acceptable quality.
C VS ASSEMBLY

Assembly programs are optimized more than C programs, but
to develop more complicated programs, using C is more
practical and also efficient.
LINKER


The linker’s function is to link code modules saved in
different files together into a single final program .



At the same time it takes care of the chip's memory
allocation by assigning each instruction to a
microcontroller memory addresses in such a way that
different modules do not overlap.
DEBUGGER
Common debugging features include:
1.
The capability to examine and modify the
microcontroller's on-chip registers, data- and
program-memory.



2.

Pausing or stopping program executing at defined
program locations by setting breakpoints.

3.

Single-stepping (execute one instruction at a time)
through the code; and looking at a history of executed
code (trace).
SOFTWARE DEVELOPMENT


An Integrated Development Environment (IDE) puts
all of the previously discussed software components
under one common unified user interface.
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

ARCHITECTURE (MEMORY ACCESSING)
Von Neumann
One memory for data and program,
with one bus for both.
CPU provides address to get data
or instructions.
Data and instructions must have
the same width.

Harvard
-Separate program and data memories and
separate busses, can be accessed
simultaneously.

separated buses allow one instruction to
execute while the next instruction is fetched.
Data and instructions mustn’t have the same
width.
ARCHITECTURE (NUMBER OF INSTRUCTIONS)
CISC Processors:
-A large no. of instructions requiring
different no. of clock cycles.
Support many addressing modes.
More complex operations are
implemented in hardware and more
elaborate way of accessing data.

RISC Processors:
-Less no. of instructions.
-Instructions are of fixed length. This
facilitates ins. pipelining as when the CPU
fetches a new ins. It will depend only on the
address not on the pervious ins.
-Few addressing modes.
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

PIC MICROCONTROLLERS


One of the leading architectures for low
end applications (app.'s that require only
4-bit, 8-bit or 16-bit processors).



They are RISC, Harvard architecture
processors.



Easier implementation to pipelining
without having a complex hardware, less
silicon area and less power consumption.
PIC MICROCONTROLLERS


PICmicro devices architectural features:

1 – Harvard, RISC architecture.
2 - Single Word Instructions.
Each instruction takes one word of memory (14-bits).

3 - Single Cycle Instructions.
Each instruction is fetched in one instruction cycle, decoded and executed in the
next instruction cycle.
4 - Instruction Pipelining

An instruction is fetched and another instruction is executed at the same time every
single TCY.
PIC MICROCONTROLLERS


The one we’ll use is: PIC 16f877A
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

OSCILLATOR


1.
2.

You’ve to choose the suitable oscillator mode you’ll use in your
application, according to:
The required processing speed.
The required timing precision.
OSCILLATOR
1.
-

2.
-

-

External RC Oscillator:
Depend on the value of Rext, Cext, the supply voltage and
the temperature.
Less cost compared to using a crystal.
Internal 4 MHz RC Oscillator:
provides a fixed 4 MHz (nominal) system clock at VDD = 5V
and 25°C.
The value in the OSCCAL register is used to tune the
frequency of the internal RC oscillator.
OSCILLATOR
3-Crystal oscillator:
-A crystal or ceramic resonator is connected to the OSC1 and OSC2
pins to establish oscillation.
- Used for high precession timing requirements.
-The capacitors are chosen according to the frequency and the
preferred values in the datasheet of the used device.
INSTRUCTION CYCLE




We call the time of fetching, decoding and executing an
instruction, the instruction cycle.
For PICmicro devices:

Instruction cycle = 4 oscillator clock cycles
INSTRUCTION CYCLE


Actually, each instruction is fetched in one instruction cycle, and
then decoded and executed in another ins. cycle.



Due to using pipelining, while the current instruction is fetched, the
pervious instruction is executed. So, you can say that each
instruction is fetched, decoded and executed in one instruction
cycle (4 clock cycles).
INSTRUCTION CYCLE


The instruction fetch begins with the program counter
incrementing in Q1.



In the execution cycle, the fetched instruction is latched
into the “Instruction Register (IR)” in cycle Q1. This
instruction is then decoded and executed during the Q2, Q3
and Q4 cycles. Data memory is read during Q2 (operand
read) and written during Q4 (destination write).
INSTRUCTION CYCLE
Ex. If you use a 4MHZ oscillator, the MCU will execute 1Million
instruction per second (1 MIPS)
Clock frequency (4MHZ) = Instruction execution (1MHZ)
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

MEMORY ORGANIZATION



There are two memory blocks:
Program memory.
Data memory.
Each one has its own bus. so that access to each block
can occur during the same oscillator cycle.
MEMORY ORGANIZATION
Program memory:
- 8 K×14 program memory space, capable of carrying 8K
instructions.
- Reset vector  0000h
 the place in memory the CPU branches to when a reset
occurs.
- Interrupt vector  0004h
-  the place in memory the CPU branches to when there is an
interrupt signal.
- 13-bit program counter.
- Program memory is partitioned to 4 banks, chosen by writing
the PCLATH<4:3> bits before executing any CALL or GOTO
instruction.
[11bit from op-code + 2 paging bits]

MEMORY ORGANIZATION
Stack:
- 8 level stack allow up to 8 program calls / interrupts to
occur.
- The return address (13-bit) will be PUSHed into the
stack so that the CPU knows from to continue.
- When a return instruction is executed, the whole 13bits
of PC are POPed from the stack.
- The stack pointer is not readable or writable.
- There are no PUSH or POP instructions.
MEMORY ORGANIZATION

-

-

-

-

Data memory:
Contains of general purpose registers (GPRs), and
special function registers (SFRs).
SFRs control the functions of the core and the
peripherals.
GPRs are not initialized by a power up on reset, and
unchanged on all other resets.
Data memory is partitioned to 4 banks, each bank is 128
byte.
MEMORY ORGANIZATION
Direct addressing:
- The bank selection bits are used
[STATUS <6:5>].

Indirect addressing:
- Data memory address is not fixed.
- The address is first defined in the SFR
register. then any access to the INDF register
will access the register pointed to by the SFR
register.
AGENDA
What are embedded systems? How do we
implement them?
 What is a microcontroller?
 Developing embedded applications using MCU’s.
 Basics of architecture.
 PIC microcontrollers.
 Basics of PICmicro devices architecture.
 Memory organization and addressing modes.
 C programming language.

C PROGRAMMING LANGUAGE
Features of C:











Extensive use of function calls
Low level (Bitwise) programming readily available
Pointer implementation - extensive use of pointers for memory
and arrays.
Structures and functions.
Can handle low-level activities.
Produces efficient programs.
Fast.
It can be compiled on a variety of computers.
C PROGRAMMING LANGUAGE
General form for any C program:
DATA TYPES
Type Bit Width Range:
Char

8

0 to 255

unsigned Char

8

0 to 255

Signed Char

8

-128 to 127

short

16

0 or 65536

long

32

0 to 65536

float

32

3.4E-38 to 3.4E+38

-

For each variable we should Know: Sign, Size and the variable’s name.
OPERATORS
+ addition
- subtraction

* multiplication
/ division
% modulus


a*=b is the same as a=a*b



a/=b





a+=b





a-=b





a%=b



a=a%b



a<<=b



a=a<<b



a>>=b



a=a>>b



a&=b





a|=b





a^=b



a=a/b
a=a+b
a=a-b

a=a&b
a=a|b
a=a^b
OPERATORS
Relational operators:
>,<,<=,>=,==,!=

Logical operators:
&&,||,!
Bitwise operators:
&, |, ^ (XOR), <<,>>,~

Precedence:
1.

Casting

2.

Parentheses

3.

Negative

4.

Multiplication and division

5.

Addition and subtraction
CONDITIONAL STATEMENTS
If statement:
if (expression)
{
statement(s);
}
If-else statement:
if (expression1)
{
statement(s)
}
else if(expression2)
{
statement(s)
}
else
{
statement(s)
}
SWITCH STATEMENT


switch (variable)

{

case constant1:
statement(s);
break;
case constant2:

statement(s);
break;
default:
statement(s);
}
FOR LOOP


for( initialization ; conditional_test ; increment )

Ex.


void main(void)

{
int i;
for(i=0; i<10; i++)

printf(“%d “,i);
printf(“done”);
}
WHILE & DO-WHILE LOOP
While:
while (expression)

{
statement;
}
do-while Loop


do

{
statements
}
while(expression)
ARRAYS
type array_name[size] = {value list};

Ex.


int i[5] = {1,2,3,4,5};

Multidimensional arrays:


int num[3][3]={ 1,2,3,
4,5,6,
7,8,9};
FUNCTIONS


main() is the first function called when the program is executed. The other
functions, function1() and function2(), can be called by any function in the
program.

Example.
main()
{
int x=0;
X=Function1(5,6);
}
int function1(int a,int b )
{
Return (a+b);
}
MIX C AND ASSEMBLY



We can mix c and assembly by using the command
#asm
statements



#End asm

Más contenido relacionado

La actualidad más candente

8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
Tech_MX
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
mkazree
 

La actualidad más candente (20)

EMBEDDED SYSTEM DESIGN ARM architecture support for operating system by sanj...
 EMBEDDED SYSTEM DESIGN ARM architecture support for operating system by sanj... EMBEDDED SYSTEM DESIGN ARM architecture support for operating system by sanj...
EMBEDDED SYSTEM DESIGN ARM architecture support for operating system by sanj...
 
Microcontroller based automatic engine locking system for drunken drivers
Microcontroller based automatic engine locking system for drunken driversMicrocontroller based automatic engine locking system for drunken drivers
Microcontroller based automatic engine locking system for drunken drivers
 
ARM Microcontrollers and Embedded Systems-Module 1_VTU
ARM Microcontrollers and Embedded Systems-Module 1_VTUARM Microcontrollers and Embedded Systems-Module 1_VTU
ARM Microcontrollers and Embedded Systems-Module 1_VTU
 
Different addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessorDifferent addressing mode and risc, cisc microprocessor
Different addressing mode and risc, cisc microprocessor
 
8237 dma controller
8237 dma controller8237 dma controller
8237 dma controller
 
RISC (reduced instruction set computer)
RISC (reduced instruction set computer)RISC (reduced instruction set computer)
RISC (reduced instruction set computer)
 
ARM CORTEX M3 PPT
ARM CORTEX M3 PPTARM CORTEX M3 PPT
ARM CORTEX M3 PPT
 
Introduction to stm32-part1
Introduction to stm32-part1Introduction to stm32-part1
Introduction to stm32-part1
 
Arm processor
Arm processorArm processor
Arm processor
 
Thesis report 16 bit RISC processor
Thesis report 16 bit RISC processorThesis report 16 bit RISC processor
Thesis report 16 bit RISC processor
 
Chp4 introduction to the pic microcontroller copy
Chp4 introduction to the pic microcontroller   copyChp4 introduction to the pic microcontroller   copy
Chp4 introduction to the pic microcontroller copy
 
Risc processors
Risc processorsRisc processors
Risc processors
 
How to Measure RTOS Performance
How to Measure RTOS Performance How to Measure RTOS Performance
How to Measure RTOS Performance
 
ARM architcture
ARM architcture ARM architcture
ARM architcture
 
PIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTESPIC MICROCONTROLLERS -CLASS NOTES
PIC MICROCONTROLLERS -CLASS NOTES
 
RISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set ComputingRISC - Reduced Instruction Set Computing
RISC - Reduced Instruction Set Computing
 
PIC Microcontrollers
PIC MicrocontrollersPIC Microcontrollers
PIC Microcontrollers
 
Project Report on Embedded Systems
Project Report on Embedded Systems Project Report on Embedded Systems
Project Report on Embedded Systems
 
Von-Neumann machine and IAS architecture
Von-Neumann machine and  IAS architectureVon-Neumann machine and  IAS architecture
Von-Neumann machine and IAS architecture
 
Architectural support for High Level Language
Architectural support for High Level LanguageArchitectural support for High Level Language
Architectural support for High Level Language
 

Destacado (7)

Embedded systems, 8051 microcontroller
Embedded systems, 8051 microcontrollerEmbedded systems, 8051 microcontroller
Embedded systems, 8051 microcontroller
 
Interfacing to the analog world
Interfacing to the analog worldInterfacing to the analog world
Interfacing to the analog world
 
Solution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidiSolution manual 8051 microcontroller by mazidi
Solution manual 8051 microcontroller by mazidi
 
Timers
TimersTimers
Timers
 
Interrupts
InterruptsInterrupts
Interrupts
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
USART
USARTUSART
USART
 

Similar a Introduction to Embedded Systems and Microcontrollers

Introduction to embedded systems using the msp430 6. 1 Enumerate the.pdf
Introduction to embedded systems using the msp430 6. 1 Enumerate the.pdfIntroduction to embedded systems using the msp430 6. 1 Enumerate the.pdf
Introduction to embedded systems using the msp430 6. 1 Enumerate the.pdf
aienterpresses
 
Introduction to embedded systems using the msp430 6.1 Enumerate the .pdf
Introduction to embedded systems using the msp430 6.1 Enumerate the .pdfIntroduction to embedded systems using the msp430 6.1 Enumerate the .pdf
Introduction to embedded systems using the msp430 6.1 Enumerate the .pdf
aienterpresses
 
Project report on embedded system using 8051 microcontroller
Project  report on embedded system using 8051 microcontrollerProject  report on embedded system using 8051 microcontroller
Project report on embedded system using 8051 microcontroller
Vandna Sambyal
 
8051 microcontroller and embedded system
8051 microcontroller and embedded system8051 microcontroller and embedded system
8051 microcontroller and embedded system
sb108ec
 
BEE 049- design of embedded system.pdf
BEE 049- design of embedded system.pdfBEE 049- design of embedded system.pdf
BEE 049- design of embedded system.pdf
abdisahirko
 
Density based traffic light controlling (2)
Density based traffic light controlling (2)Density based traffic light controlling (2)
Density based traffic light controlling (2)
hardik1240
 

Similar a Introduction to Embedded Systems and Microcontrollers (20)

Unit-1.pptx
Unit-1.pptxUnit-1.pptx
Unit-1.pptx
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Embeddedsystem
EmbeddedsystemEmbeddedsystem
Embeddedsystem
 
Introduction to embedded systems using the msp430 6. 1 Enumerate the.pdf
Introduction to embedded systems using the msp430 6. 1 Enumerate the.pdfIntroduction to embedded systems using the msp430 6. 1 Enumerate the.pdf
Introduction to embedded systems using the msp430 6. 1 Enumerate the.pdf
 
Introduction to embedded systems using the msp430 6.1 Enumerate the .pdf
Introduction to embedded systems using the msp430 6.1 Enumerate the .pdfIntroduction to embedded systems using the msp430 6.1 Enumerate the .pdf
Introduction to embedded systems using the msp430 6.1 Enumerate the .pdf
 
Project report on embedded system using 8051 microcontroller
Project  report on embedded system using 8051 microcontrollerProject  report on embedded system using 8051 microcontroller
Project report on embedded system using 8051 microcontroller
 
8051 microcontroller and embedded system
8051 microcontroller and embedded system8051 microcontroller and embedded system
8051 microcontroller and embedded system
 
lec 1Embedded System Design ppt.pptx
lec 1Embedded System Design ppt.pptxlec 1Embedded System Design ppt.pptx
lec 1Embedded System Design ppt.pptx
 
Microcontroller
MicrocontrollerMicrocontroller
Microcontroller
 
microprocessor-and-microcontroller
microprocessor-and-microcontrollermicroprocessor-and-microcontroller
microprocessor-and-microcontroller
 
An introduction to digital signal processors 1
An introduction to digital signal processors 1An introduction to digital signal processors 1
An introduction to digital signal processors 1
 
Microprocessor and Microcontroller Based Systems.ppt
Microprocessor and Microcontroller Based Systems.pptMicroprocessor and Microcontroller Based Systems.ppt
Microprocessor and Microcontroller Based Systems.ppt
 
Introduction to DSP Processors-UNIT-6
Introduction to DSP Processors-UNIT-6Introduction to DSP Processors-UNIT-6
Introduction to DSP Processors-UNIT-6
 
K.Bhagavan gupta.pdf according to the labu
K.Bhagavan gupta.pdf according to the labuK.Bhagavan gupta.pdf according to the labu
K.Bhagavan gupta.pdf according to the labu
 
BEE 049- design of embedded system.pdf
BEE 049- design of embedded system.pdfBEE 049- design of embedded system.pdf
BEE 049- design of embedded system.pdf
 
An Entire Concept of Embedded systems
An Entire Concept of Embedded systems An Entire Concept of Embedded systems
An Entire Concept of Embedded systems
 
An entire concept of embedded systems entire ppt
An entire concept of embedded systems entire pptAn entire concept of embedded systems entire ppt
An entire concept of embedded systems entire ppt
 
Embedded system
Embedded systemEmbedded system
Embedded system
 
Embedded
EmbeddedEmbedded
Embedded
 
Density based traffic light controlling (2)
Density based traffic light controlling (2)Density based traffic light controlling (2)
Density based traffic light controlling (2)
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Introduction to Embedded Systems and Microcontrollers

  • 1. INTRODUCTION TO MICROCONTROLLERS AND EMBEDDED SYSTEMS Prepared by: Islam Samir
  • 2. - Islam Samir Mohamed - Electronics and Communications department, Faculty of Engineering, Cairo University - Embedded Software Engineer.
  • 3. INTRODUCTION Prequisties: - Digital logic design, basics of combinational and sequntial circuits. - Basics of microprocessors.  (A brief review will be given in the course) - C programming language. 
  • 4. INTRODUCTION   - 1. - - Why do we study this course? As engineers: Learning how microprocessors work and how to use them is very essential for every electrical engineer in many ways: Implementing mathmatical algorithms: To implement an algorithm for a communication system, control system, or any real time system we usually write a program and load it on the target microprocessor. Then, this microprocessor is used as a part of this system.
  • 5.
  • 6. INTRODUCTION 2. - - Minimizing the cost and power: If this system is a part of a battery-powered device, or it’s required to keep the device’s cost low as much as possible, we’ve to use a cheap microprocessor. To do so, the program should be minimized as possible and the designer should make use of every element of the used microprocessor/microcontroller.
  • 7. INTRODUCTION  - - - As Egyptians: The development of the field of electrical engineering in Egypt is our responsibility, not anyone else. To face the challenges facing our country these days, we have to be at a technical level that allows us to create new products and compete in the global market. To do so, we’ve to be equipped with the required knowledge and experience to innovate and bring new ideas that gives us the advantage in the market.
  • 8. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 9. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 10. EMBEDDED SYSTEMS  An embedded system is a special purpose system that is used to perform one or few dedicated functions.  Simply, we can call any computer system embedded inside an electronic device an embedded system.
  • 11. EMBEDDED SYSTEMS (CONT.)  Embedded systems are made to perform few tasks only, after implementation you can’t use them for another purposes. Ex. You can’t watch movies using the microprocessor of your microwave oven!!
  • 12. EMBEDDED SYSTEMS Examples: Digital and analog televisions Set-top boxes (DVDs, VCRs, Cable boxes) Personal digital assistants (PDAs) MP3’s and iPod's Kitchen appliances (refrigerators ,microwave ovens) Telephones/cell phones Cameras Global positioning systems And many others.
  • 13. SO.. HOW DO WE IMPLEMENT THEM?  We do so by using microcontrollers (or microprocessor based systems).  Or simply by using the digital circuits that perform the function we want.
  • 14. COMPARISON Digital circuits Microprocessor based systems Faster - only propagation delay. Slower - Technology dependent. Inflexible -Functions they perform can’t be changed easily. Flexible - We need only to update the software. Example - Communication systems ciphering algorithms. Example - Personal computers, PDA’s, Mobile phones and PLC’s.
  • 15. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 16. WHAT IS A MICROCONTROLLER?  It’s a full computer system on a chip, even if its resources are far more limited than of a desktop personal computer.  Designed for stand alone operations.
  • 17. WHAT IS A MICROCONTROLLER? (CONT.)  So.. What’s the difference between a microcontroller and a microprocessor system?
  • 18. WHAT IS A MICROCONTROLLER? (CONT.)  A microcontroller has a processor and many peripherals integrated with it on the same chip, like a flash memory, RAM, I/O ports, serial communication ports, ADC …Etc.
  • 19. WHAT IS A MICROCONTROLLER? (CONT.)  A timer module to allow the MCU to perform tasks for certain time periods.  A serial I/O port to allow data to flow between the MCU and other devices such as a PC or another MCU.  An ADC to allow the MCU to accept analog inputs for processing.
  • 20. WHAT IS A MICROCONTROLLER? (CONT.)  But a microprocessor can’t do all the functions of a computer system on its own, and needs another circuits to support it like: I/O devices, RAM, ROM, DMA controllers, Timers, ADC, LCD drivers.. Etc.
  • 21. COMPARISON Microcontroller General purpose microprocessor Depend mainly on its peripherals like: Program memory, I/O ports, timers, interrupt circuitry, ADC…Etc. Depend mainly on other devices like: I/O devices, memory, DMA controllers ..Etc. Used for a few dedicated functions determined by the system designer. Used in many applications, according to the program running on it Usually used as a part of a larger system It’s in the heart of our PC’s.
  • 22. POPULAR MICROCONTROLLERS 8051 (Intel and others)  80386 EX (Intel)  PIC (Microchip)   68HC05 (Motorola)  Z8 (Zilog)
  • 23. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 24. DEVELOPING EMBEDDED SYSTEMS Embedded systems development Software development Hardware development
  • 25. HARDWARE DEVELOPMENT  This includes choosing the right MCU for your application, so that it can satisfy the required specifications. The criteria for choosing a microcontroller is: 1- Number of I/O ports. 2- Serial communication modules. 3- Peripherals like (Timer, ADC, PWM ..Etc.) 4- Memory requirements. 5- Processing speed required. 6- Power requirements. 
  • 26. SOFTWARE DEVELOPMENT • Writing the required algorithm using assembly or a high level language. • Using a compiler or assembler and a linker. • Debugging your code.
  • 28. SOFTWARE DEVELOPMENT  Using assembly involves learning the used microcontroller's specific instruction set but results in the most compact and fastest code.  Using C programming language makes your code portable, which means that you can use it for another target microcontroller without learning its instruction set, this eases the process of software development (short time to market) with acceptable quality.
  • 29. C VS ASSEMBLY Assembly programs are optimized more than C programs, but to develop more complicated programs, using C is more practical and also efficient.
  • 30. LINKER  The linker’s function is to link code modules saved in different files together into a single final program .  At the same time it takes care of the chip's memory allocation by assigning each instruction to a microcontroller memory addresses in such a way that different modules do not overlap.
  • 31. DEBUGGER Common debugging features include: 1. The capability to examine and modify the microcontroller's on-chip registers, data- and program-memory.  2. Pausing or stopping program executing at defined program locations by setting breakpoints. 3. Single-stepping (execute one instruction at a time) through the code; and looking at a history of executed code (trace).
  • 32. SOFTWARE DEVELOPMENT  An Integrated Development Environment (IDE) puts all of the previously discussed software components under one common unified user interface.
  • 33. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 34. ARCHITECTURE (MEMORY ACCESSING) Von Neumann One memory for data and program, with one bus for both. CPU provides address to get data or instructions. Data and instructions must have the same width. Harvard -Separate program and data memories and separate busses, can be accessed simultaneously. separated buses allow one instruction to execute while the next instruction is fetched. Data and instructions mustn’t have the same width.
  • 35. ARCHITECTURE (NUMBER OF INSTRUCTIONS) CISC Processors: -A large no. of instructions requiring different no. of clock cycles. Support many addressing modes. More complex operations are implemented in hardware and more elaborate way of accessing data. RISC Processors: -Less no. of instructions. -Instructions are of fixed length. This facilitates ins. pipelining as when the CPU fetches a new ins. It will depend only on the address not on the pervious ins. -Few addressing modes.
  • 36. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 37. PIC MICROCONTROLLERS  One of the leading architectures for low end applications (app.'s that require only 4-bit, 8-bit or 16-bit processors).  They are RISC, Harvard architecture processors.  Easier implementation to pipelining without having a complex hardware, less silicon area and less power consumption.
  • 38. PIC MICROCONTROLLERS  PICmicro devices architectural features: 1 – Harvard, RISC architecture. 2 - Single Word Instructions. Each instruction takes one word of memory (14-bits). 3 - Single Cycle Instructions. Each instruction is fetched in one instruction cycle, decoded and executed in the next instruction cycle. 4 - Instruction Pipelining An instruction is fetched and another instruction is executed at the same time every single TCY.
  • 39. PIC MICROCONTROLLERS  The one we’ll use is: PIC 16f877A
  • 40. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 41. OSCILLATOR  1. 2. You’ve to choose the suitable oscillator mode you’ll use in your application, according to: The required processing speed. The required timing precision.
  • 42. OSCILLATOR 1. - 2. - - External RC Oscillator: Depend on the value of Rext, Cext, the supply voltage and the temperature. Less cost compared to using a crystal. Internal 4 MHz RC Oscillator: provides a fixed 4 MHz (nominal) system clock at VDD = 5V and 25°C. The value in the OSCCAL register is used to tune the frequency of the internal RC oscillator.
  • 43. OSCILLATOR 3-Crystal oscillator: -A crystal or ceramic resonator is connected to the OSC1 and OSC2 pins to establish oscillation. - Used for high precession timing requirements. -The capacitors are chosen according to the frequency and the preferred values in the datasheet of the used device.
  • 44. INSTRUCTION CYCLE   We call the time of fetching, decoding and executing an instruction, the instruction cycle. For PICmicro devices: Instruction cycle = 4 oscillator clock cycles
  • 45. INSTRUCTION CYCLE  Actually, each instruction is fetched in one instruction cycle, and then decoded and executed in another ins. cycle.  Due to using pipelining, while the current instruction is fetched, the pervious instruction is executed. So, you can say that each instruction is fetched, decoded and executed in one instruction cycle (4 clock cycles).
  • 46. INSTRUCTION CYCLE  The instruction fetch begins with the program counter incrementing in Q1.  In the execution cycle, the fetched instruction is latched into the “Instruction Register (IR)” in cycle Q1. This instruction is then decoded and executed during the Q2, Q3 and Q4 cycles. Data memory is read during Q2 (operand read) and written during Q4 (destination write).
  • 47. INSTRUCTION CYCLE Ex. If you use a 4MHZ oscillator, the MCU will execute 1Million instruction per second (1 MIPS) Clock frequency (4MHZ) = Instruction execution (1MHZ)
  • 48. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 49. MEMORY ORGANIZATION   There are two memory blocks: Program memory. Data memory. Each one has its own bus. so that access to each block can occur during the same oscillator cycle.
  • 50. MEMORY ORGANIZATION Program memory: - 8 K×14 program memory space, capable of carrying 8K instructions. - Reset vector  0000h  the place in memory the CPU branches to when a reset occurs. - Interrupt vector  0004h -  the place in memory the CPU branches to when there is an interrupt signal. - 13-bit program counter. - Program memory is partitioned to 4 banks, chosen by writing the PCLATH<4:3> bits before executing any CALL or GOTO instruction. [11bit from op-code + 2 paging bits] 
  • 51.
  • 52. MEMORY ORGANIZATION Stack: - 8 level stack allow up to 8 program calls / interrupts to occur. - The return address (13-bit) will be PUSHed into the stack so that the CPU knows from to continue. - When a return instruction is executed, the whole 13bits of PC are POPed from the stack. - The stack pointer is not readable or writable. - There are no PUSH or POP instructions.
  • 53. MEMORY ORGANIZATION  - - - - Data memory: Contains of general purpose registers (GPRs), and special function registers (SFRs). SFRs control the functions of the core and the peripherals. GPRs are not initialized by a power up on reset, and unchanged on all other resets. Data memory is partitioned to 4 banks, each bank is 128 byte.
  • 54. MEMORY ORGANIZATION Direct addressing: - The bank selection bits are used [STATUS <6:5>]. Indirect addressing: - Data memory address is not fixed. - The address is first defined in the SFR register. then any access to the INDF register will access the register pointed to by the SFR register.
  • 55. AGENDA What are embedded systems? How do we implement them?  What is a microcontroller?  Developing embedded applications using MCU’s.  Basics of architecture.  PIC microcontrollers.  Basics of PICmicro devices architecture.  Memory organization and addressing modes.  C programming language. 
  • 56. C PROGRAMMING LANGUAGE Features of C:         Extensive use of function calls Low level (Bitwise) programming readily available Pointer implementation - extensive use of pointers for memory and arrays. Structures and functions. Can handle low-level activities. Produces efficient programs. Fast. It can be compiled on a variety of computers.
  • 57. C PROGRAMMING LANGUAGE General form for any C program:
  • 58. DATA TYPES Type Bit Width Range: Char 8 0 to 255 unsigned Char 8 0 to 255 Signed Char 8 -128 to 127 short 16 0 or 65536 long 32 0 to 65536 float 32 3.4E-38 to 3.4E+38 - For each variable we should Know: Sign, Size and the variable’s name.
  • 59. OPERATORS + addition - subtraction * multiplication / division % modulus  a*=b is the same as a=a*b  a/=b   a+=b   a-=b   a%=b  a=a%b  a<<=b  a=a<<b  a>>=b  a=a>>b  a&=b   a|=b   a^=b  a=a/b a=a+b a=a-b a=a&b a=a|b a=a^b
  • 60. OPERATORS Relational operators: >,<,<=,>=,==,!= Logical operators: &&,||,! Bitwise operators: &, |, ^ (XOR), <<,>>,~ Precedence: 1. Casting 2. Parentheses 3. Negative 4. Multiplication and division 5. Addition and subtraction
  • 61. CONDITIONAL STATEMENTS If statement: if (expression) { statement(s); } If-else statement: if (expression1) { statement(s) } else if(expression2) { statement(s) } else { statement(s) }
  • 62. SWITCH STATEMENT  switch (variable) { case constant1: statement(s); break; case constant2: statement(s); break; default: statement(s); }
  • 63. FOR LOOP  for( initialization ; conditional_test ; increment ) Ex.  void main(void) { int i; for(i=0; i<10; i++) printf(“%d “,i); printf(“done”); }
  • 64. WHILE & DO-WHILE LOOP While: while (expression) { statement; } do-while Loop  do { statements } while(expression)
  • 65. ARRAYS type array_name[size] = {value list}; Ex.  int i[5] = {1,2,3,4,5}; Multidimensional arrays:  int num[3][3]={ 1,2,3, 4,5,6, 7,8,9};
  • 66. FUNCTIONS  main() is the first function called when the program is executed. The other functions, function1() and function2(), can be called by any function in the program. Example. main() { int x=0; X=Function1(5,6); } int function1(int a,int b ) { Return (a+b); }
  • 67. MIX C AND ASSEMBLY   We can mix c and assembly by using the command #asm statements  #End asm