Designing Embedded Systems
with PIC Microcontrollers:
Principles and Applications
2nd Edition. Tim Wilmshurst
1
Chapter 1
Tiny Computers, Hidden Control
The aims of this chapter are to introduce:
• The meaning of the term ‘embedded system’;
• The microcontroller which lies at the heart of the embedded system;
• The Microchip PIC® family;
• A first PIC microcontroller, the 12F508.
2
What is an embedded system?
What examples of embedded
systems do you know?
3
Example 2: Car Door Control, within a Larger Network
windowcontrolbuttons
windowstallsensor
windowm otor
lockcontrol
lockactuator opendoorsensor
4
Example 2: Car Door Control, within a Larger Network
Right
Door
Dash Climate
Board Control
Driver's
Steering Seat
Central
Control Air Radio
Bag & CD
CAN Bus
Left
Door
5
Example 3: The Derbot Autonomous Guided Vehicle
6
Ultrasound
Ranging
Module
Pulse Echo
Bump Sensor Bump Sensor
Left Right
Light Sensor Analog to Digital Light Sensor
Left Converter Right
Light Sensor Ultrasound
Rear Servo
Serial Data
PIC Compass
Power 5V
Microcontroller Serial
Clock
Regulation &
Management
Serial Extension Bus
9V
Alkaline Pulse Width Modulation
Stream x2
9V Motor Drive
Interface
Motor Motor
Left Right 7
(User Interface)
Generic Block Diagram (display, keypad etc.)
Conditioning
Embedded Computer
Conversion
Signal
Output
Input
Drive
Data
Output
Variables Software Variables
Hardware
(Link to other Systems)
An embedded system is a system whose principal function is not computational,
but which is controlled by a computer embedded within it.
8
The Embedded System - What Disciplines does it Involve?
Digital Integrated Circuit
Electronics Design
Analogue
Electronics Computer Architecture
Embedded Systems
Sensors and Software Engineering
Measurements
Data
Electric Motors & Communications
Actuators Control
Engineering
9
What can the Computer Actually Do?
• A computer “executes” instructions in its (ALU).
• Running through a series of instructions called a program.
• The ALU in turn forms part of the (CPU).
• (A) is the “Accumulator”, a digital register where the
computations actually occur.
• (M) is a location in memory.
• A typical 8-bit ALU can do the list shown below.
10
What can the Computer Actually Do?
Increment A A = A plus 1
Decrement A A=A-1
Add A to M A = A plus M
Subtract M from A A=A-M
AND A with M A = A.M
OR A with M A=A+M
Exclusive OR A with M A = A+ M
Shift A left A = 2A
Shift A right A = A/2
Rotate A left
Rotate A right
Complement A A = NOT A
Clear A A=0
11
How Instruction Sets are Made: “CISC”
• CPU has a set of instructions that it recognizes and responds to
all programs.
• We want computers to execute code as fast as possible.
• This leads to CISC (Complex Instruction Set Computer).
• A CISC has many instructions, but sophisticated.
• Simple ones can be expressed in a short instruction code, say
one byte of data, and execute quickly.
• Complex ones need several bytes, and take a long time. 12
How Instruction Sets are Made: “CISC”
A CISC machine is generally recognised by:
• Many instructions (say < 100), with considerable sophistication
• Instruction words are of different length;
• Instructions take different lengths of time to execute.
13
How Instruction Sets are Made: “RISC”
• RISC (Reduced Instruction Set Computer) keep the CPU very
simple and fast, and have a limited instruction set.
• One characteristic of the RISC approach is that each instruction
is contained within a single binary word.
• That word must hold all information necessary, including:
(instruction code - address - data ).
• Every instruction takes the same amount of time.
14
How Instruction Sets are Made: “RISC”
A RISC machine is generally recognised by:
• Few instructions (say > 100),
• Each performs a very simple action;
• All instructions are single word;
• Almost all instructions take the same length of time to execute.
15
The Microcontroller
A microcontroller is a microprocessor designed primarily to
perform simple control functions.
Microcontrollers usually have these features
• low cost,
• physically small,
• input/output intensive, and capable of easy interfacing,
• limited memory capability,
• ability to operate in a real-time environment. 16
The Microcontroller
In certain applications, following further features are essential:
• ability to operate in hostile environment, e.g. high or low
temperature, tolerant to electromagnetic interference,
• low power, with features adapted to battery power.
17
Program Further
Power Memory Peripheral
Data Further
Memory Peripheral
Digital
I/0
Microprocessor
Reset Core
Interrupt(s) Analog
I/0
Internal Data &
Address Buses
Clock Counters
& Timers
A microcontroller = microprocessor core + memory + peripherals
18
A Gathering of Microprocessors and Microcontrollers
Motorola PIC 16F877
PIC 16C72 68HC05B16
PIC 16F84A
Motorola 68000
PIC 12F508
19
Comparison of 8-bit PIC families:
Family Example Instruction Stack Number of Interrupt
Devices word size size instruction vectors
(words)
Baseline 10F200, 12-bit 2 33 None
12F508,
16F57
Mid-range 12F609, 14-bit 8 35 1
16F84A,
16F631,
16F873A
High 18F242, 16-bit 32 75, 2
Performance 18F2420 including (prioritized)
hardware
multiply
20
Microcontroller - PIC 12F508/509
21
The PIC 12F508/509
block diagram
22
Summary
• An embedded system is a product that has one or more computers
embedded within it (Microcontroller).
• Microcontrollers are designed according to accepted electronic and
computer principles.
• A microcontroller = microprocessor core + memory + peripherals
• Microchip offers a wide range of microcontrollers, with different families.
• Each family has identical (or very similar) central architecture and
instruction set.
23
End of Chapter 1
24