You are on page 1of 52

Introduction to

Microcontrollers
Module UFMETU-20-1

Northshore College of Business & Technology, Colombo,
Sri Lanka
Semester I

Dilum Bandara
Dilum.Bandara@uom.lk

Slides extended from Makis Malliris & Sabir Ghauri
Outline
Building solutions to computational problems
General microcontroller architecture
Harvard vs. Von Neuman
CISC vs. RISC
Overview of PICmicro family
PIC 16F877 architecture
Register File Map
Memory registers, Special Function Registers

2
Building Binary Digital Solutions to
Computational Problems
3
Labs & Design project
Product specs
Algorithms, RTL, etc.
Flowcharts
State transition diagrams
Logic equations
Circuit schematics
TTL Gates (AND,OR,XOR ... )
Modules (counter, shifter,...)
Programmable Logic
Building Binary Digital Solutions to
Computational Problems Using HDLs
4
Labs & Design project
Product specs
Algorithms, RTL, etc.
Flowcharts
State transition diagrams
Verilog code
VHDL
Custom ASICs
Programmable Logic
FPGAs
Hardware Description
Languages (HDL)
Logic synthesis using a Hardware Description Language (HDL)
Automates the most tedious and error-prone aspects of design
Building Binary Digital Solutions to
Computational Problems Using Flexible Devices
5
Labs & Design project
Product specs
Algorithms, RTL, etc.
Flowcharts
State transition diagrams
Assembler
C
C++
MCUs
DSPs
FPGAs
Low and high-level
programming
Programming Hierarchies
6
Source - Introduction to PIC Microcontroller Part 1 by KHAN WAHID
Programming PIC
7
8
OUTPUT
P
R
O
C
E
S
S

INPUT
Single Chip Control Unit
Embedded Digital System
9
Digital Outputs
(peripherals, buses,
lights)
Analogue Outputs
( actuators, motors,
multimedia)
PAL, GAL, EPLD, CPLD, FPGA, ASICs, GPP, DSP, MCU
Digital processing systems consist of a data path, memory, & control
Early machines for arithmetic had insufficient memory, & often
depended on users for control
10
Digital Camera Controller (TI)
11
Memory Subsystem
Motors & Mechanical Sensors
Digital Still Camera (TI)
12
Architectural Differences
Length of microprocessors data word
4, 8, 16, 32, & 64 bit
Size of direct addressable memory
Speed of instruction execution
Clock rate & processor speed PIC 16F877 @ 4MHZ
CPU architecture
Instruction set
No & types of registers
Support circuits
Compatibility with existing software & hardware
development systems
13
Microcontroller Blocks
14
ROM
program
memory
Instruction
Register
STACK
Program counter
Instruction
Decoder
Timing, Control, & register selection
Working
register
RAM
data
registers
ALU
Port
regs
Port
regs
STATUS &
Special
Function
Registers
Microcontroller Blocks
15
Literal
Address
Operation



ROM
program
memory
Instruction
Register
STACK
Program counter
Instruction
Decoder
Timing, Control and Register selection
Working
Register
RAM
Data
Registers
ALU
Port
Regs
Port
Regs
STATUS &
Special
Function
Registers
Clock
Reset
Interrupts
Program execution section
Register processing section
Set up
Set up
Modify
Address
Internal data bus
Arithmetic & Logic Unit (ALU)
Data processing
unit
Arithmetic unit
Performs
arithmetic
operations
Logic unit
Performs logical
operations

16
Basic Instruction Processing Steps
Determine current instruction
based on program counter
Load instruction into
instruction register
Decode instruction
Read register
Perform ALU operation
Write back result
Additional data paths for
Change in program counter
Immediate values
I/O operation
Memory Architectures
18
Von Neumann vs. Harvard Architecture

19
20
Registers
Is a type of memory located inside
microcontroller/CPU
Can hold a single piece of data
This data is useful in both data processing &
control functionalities
Several types of CPU register
Program counter (PC)
Instruction register (IR)
Accumulator
Flag register
General purpose register
21
Program Counter (PC)
Used to keep track of memory address of next
instruction to be executed
When instructions are fetched (fetch cycle),
always instruction pointed by PC is fetched into
CPU/microcontroller
Once the instruction is fetched, PC is updated to
point to next instruction

22
Instruction Register (IR)
Once fetched instructions are stored in IR for
execution
Located closely to control unit which decodes
the instruction
23
Accumulator (A)
Results of arithmetic & logical operations always
go to accumulator
Connected directly to output of ALU
Referred to as register W in PICs
24
Source - Introduction to PIC Microcontroller Part 1 by KHAN WAHID
STATUS Register
Status bits
Bit 0: Carry
Bit 1: Digit carry
Bit 2: Zero result
Bits 3 & 4: Use at
power-up and sleep
Bit 5 & 6: bank
select
Bit 7: bank select for
indirect addressing
RAM address
extension bits
Register File Map (368 Bytes of RAM)
Registers are data
memory
General purpose
Special-purpose
Each register holds
an 8-bit value
Registers are
separated into banks
128 registers per
bank
PIC16F877 has 4
banks
Why use banks?
26
27
Internal Structure
A
E
D
C
B
ALU
A
d
d
r
e
s
s

B
U
S

Control Unit
IR
FLAG
ALU
PC
+1
D
a
t
a

B
U
S

C
T
R
L

B
U
S

28
Instruction Execution Sequence
1. Fetch next instruction from memory to IR
2. Change PC to point to next instruction
3. Determine type of instruction just fetched
4. If instruction needs data from memory, determine where
it is
5. Fetch data if needed into register
6. Execute instruction
7. Go to step 1 & continue with next instruction
29
A Sample Program
100: Load A,10
101: Load B,15
102: Add A,B
103: STORE A,[20]
Load A,10
Load B,15
ADD A,B
STORE A,[20]
100
101
102
103
104
105
Program memory
18
19
20
21
Data memory
00
00
00
00
30
Before execution of the 1
st
fetch cycle
A
E
D
C
B
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
IR
FLAG
ALU
100
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

31
After the 1
st
fetch cycle
A
E
D
C
B
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
Load A,10
FLAG
ALU
101
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

32
After the 1
st
instruction cycle
10
E
D
C
B
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
Load A,10
FLAG
ALU
101
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

33
A Sample Program
100: Load A,10
101: Load B,15
102: Add A,B

34
After the 2
nd
fetch cycle
A
E
D
C
B
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
Load B,15
FLAG
ALU
102
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

35
After the 2
nd
instruction cycle
10
E
D
C
15
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
Load B,15
FLAG
ALU
102
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

36
A Sample Program
100: Load A,10
101: Load B,15
102: Add A,B

37
After the 3
rd
fetch cycle
10
E
D
C
15
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
ADD A,B
FLAG
ALU
103
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

38
After the 3
rd
instruction cycle
25
E
D
C
15
ALU
A
d
d
r
e
s
s

B
I
U

Control Unit
ADD A,B
FLAG
ALU
103
+1
D
a
t
a

B
I
U

C
T
R
L

B
I
U

Instruction Set
Basic set of commands understood by
microprocessor/microcontroller
Complex Instruction Set Computer (CISC)
Instructions for all most all common tasks
Many of them are macro-like, allowing programmer to use
one instruction in place of many simpler instructions.
Almost all of todays microcontrollers are CISC
Powerful & specialised for specific control tasks
Reduced Instruction Set Computers (RISC)
Simple circuitry Smaller chip, smaller pin count,
very low-power, & better performance
Industry trend for microprocessor design
39

40
Decoding Instructions
41
Source - Introduction to PIC Microcontroller Part 1 by KHAN WAHID
Clocks & Pipelining
42
42
2- Stage Pipelining
Harvard architecture
Separate program &
data memory
Observation
Program memory is
idle while data
memory is in use
Accesses could be
interleaved

43
Causes for Pipeline Stalls
Control dependencies
Data dependencies
44
Microcontroller Families
45
46
Sophisticated Microcontrollers
Built-in monitor/debugger
Interrupt capabilities
Analog I/O (PWM, variable DC I/O)
Serial I/O
Parallel I/O
External memory interfaces (16-32 bit)

47
Digital Systems Components
Encoders, decoders
Multiplexer, demultiplexer, & buffer
Registers & memory
Memory address decoding
System address decoding
Counters & timers
Serial & shift registers
Arithmetic & Logic Unit (ALU)

48
Combinational vs. Sequential Logic
Combinational logic
Digital circuits where output is determined ONLY by
current inputs & not by inputs at some previous point
in time
E.g., Binary adders, basic function of the ALU in any
microprocessor
Sequential logic
Digital circuits where outputs is determined by current
inputs & inputs which were present at some earlier
point in time
Sequence of inputs determines output
E.g., flip-flops, data storage cells in registers, memory,
counters, & control logic in processor 49
Boolean Algebra
Mathematics of binary values
In 1854 George Boole shows that logic is
mathematics, not just philosophy

50




0
0
1
1
AND OR NOT
Data Devices
All data processing or digital control systems
have circuits to carry out following operations:
Data input
Data storage
Data processing
Data output
Control & timing
51
Simple Data System
52
0 V
+5V
Data
Input
Switch
TSG enable
[GE]
Tri-state gate IC
D Q
Data Latch
EN
Data Latch
Enable Pulse (0,1,0)
Current Driver 10mA
0V
Data
output
display

You might also like