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.
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.
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.
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.
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.
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