Elements of Elecronics
Elements of Elecronics
Microcontrollers
Ambresh
1
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Introduction
Computer: A computer is a programmable machine that receives
input, stores and manipulates data/information, and provides output in
a useful format.
Basic computer system consist of a CPU, memory and I/O unit.
Address bus
I/O I/O
ROM RAM interfa devic
CP ce es
U
Data Contr
bus ol
bus
Block diagram of a basic computer
system
2 2
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Microprocessor
3
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Introduction
• T h e microprocessor also known as the central
processing unit, is the brain of all computers and
many household and electronic devices. Multiple
microprocessors, working together, are the "hearts"
of datacenters, super-computers, communications
products, and other digital devices.
4
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
History
64-bit
microprocessors
• Intel core 2
• Intel core i7
• Intel core i5
• Intel core i3
8
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Microprocessor (MPU)
MPU (CPU)
Read
instructions
Process binary
data
9
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Memory
Storage Device
Addresses
Registers
Major Categories
Read/Write
Memory (R/W)
Read-only-
Memory (ROM)
D7 D0
10
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Input/Output (I/O)
Input Devices
Switches and Keypads
Provide binary information to
the MPU
Output devices
LEDs and LCDs
Receive binary information
from the MPU
11
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Microprocessor Architecture
The MPU communicates with Memory
and I/O using the System Bus
Address bus
Unidirectional
12
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Microprocessor – Basic concept
ADDRESS BUS
32-bit / 64-bit wide
CPU
contains
CCU CONTROL BUS
ALU Timing signals, ready signals,
data registers interrupts etc
and
pointer registers
13
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
How does a Microprocessor
works
To execute a program, the microprocessor “reads”
each instruction from memory, “interprets” it, then
“executes or perform” it.
The right name for the cycle is
Fetch
Decode
Execute
This sequenceis continued until all instructions
are performed.
14
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Machine Language
To communicate with computer, instruction is given in binary
language.
MP has 8 bit data, so 28 = 256 combinations. So difficult to
write programs in set of 0’s and 1’s .
for eg:
0011 1100 – is an instruction that increments the number in
accumulator by 1
1000 0000– is an instruction that add the number in register B to the
accumulator content , and keep the result in A.
1. Register Array
19
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
8085 Architecture ……
cont….
1. Registers Array : 14 register out of which 12 are 8 bit capacity and 2 of 16
bit. Classify into 4 types
(b.1) Accumulator
(A): (user accessible)
8 bit register
All the ALU operations are performed with reference to the contents of
Accumulator. Result of an operation is stored in A.
Store 8 bit data during I/O transfer
(b.2) Instruction Register: (user not
accessible)
When an instruction is fetched from memory, it is loaded in IR. Then
transferred to the
decoder for decoding.
It is not programmable and can not be accessed through any instruction.
20
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
8085 Architecture ……
cont….
(b.3) Flag Register(F): (user accessible)
8 bit Register
Indicates the status of the ALU operation.
ALU includes 5 flip flop, which are set or reset after an
operation
according to data conditions of the result in the
accumulator.
(Flag
Register) 21
1
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Flag Register…… cont….
Flag Significance
C or CY (Carry) CY is set when an arithmetic operation generates a
carry
out, otherwise it is 0 (reset)
P (Parity) P= 1; if the result of an ALU operation has an
even number of 1’s in A;
P= 0; if number of 1 is odd.
23
1
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
8085 Architecture ……
(d.1)
cont….
(d)Pointer Register or special purpose [SP, PC]
Stack Pointer(SP)
16 bit address which holds the address of the data present at the top
of the stack
memory
It is a reserved area of the memory in the RAM to store and retrieve the
temporary information.
Also hold the content of PC when subroutines are used.
When there is a subroutine call or on an interrupt. ie. pushing the return
address on a jump, and retrieving it after the operation is complete to
come back to its original location.
(d. Program Counter(PC)
3)
16 bit address used for the execution of program
Contain the address of the next instruction to be executed after fetching
the instruction it is automatically incremented by 1.
Not much use in programming, but as an indicator to user only.
24
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
8085 Architecture …… cont….
In addition to register MP contains some latches
and buffer
Increment
and decrement address latch
16 bit register
Used to increment or decrement the content of
PC and SP
Address
buffer
8 bit unidirectional buffer
Used to drive high order address bus(A8 to A15)
When it is not used under such as reset, hold and halt etc this
buffer is used tristate high order address bus.
Data/Address
buffer
8 bit bi-Directional buffer
Used to drive the low order address (A0 to A7) and data (D0 to
D7) bus.
Under certain conditions such as reset, hold and halt etc this
buffer is used tristate low order address bus. 25
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
8085 Architecture …… cont….
(2)ALU & Logical Group: it consists ALU, Accumulator,
Temporary
register and Flag Register.
(a) ALU
Performs arithmetic and logical operations
Stores result of arithmetic and logical operations in
accumulator
(b) Accumulator
General purpose register
Stores one of the operand before any arithmetic and
logical operations and result of operation is again
stored back in Accumulator 26
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
8085 Architecture …… cont….
(2)ALU & Logical Group…………………..cont…………………
Fetching Cycles
The fetch cycle takes the instruction
required from memory,
stores it in the instruction register, and
Moves the program counter on one so that it
points to the next instruction.
Execute cycle
The actual actions which occur during the execute
cycle of
an instruction.
Depend on both the instruction itself and the
addressing mode specified to be used to access the
data that may be required. 31
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Instruction Formats
Each instruction has two parts.
Opcod Operan
e d
32
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Opcode Format
Opcode contains the information regarding about
operation, register used, memory to be used etc.
Register Code
B 000 Regist Code
er
C 001 pair
D 010 BC 00
E 011 DE 01
H 100
HL 10
L 101
A, F, SP 11
M 110
A 111
33
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Write the Assemble Program..cont..
Sta
rt
En Block 4: En
d 4 HALT d
34
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Write the Assemble Program..cont..
Mnemoni Hex
cs Code
MVI A, 32H 3E 2 Byte Instruction
32
MVI B, 48H 06 2 Byte Instruction
48
ADD B 80 1 Byte Instruction
OUT 01H D3 2 Byte Instruction
01
HALT 76 1 Byte
Instruction
35
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Program Stored in memory as
Mnemonics Hex Memory Memory
Code Content Address
MVI A, 32H 3E 0011 1110 2000
32 0011 0010 2001
MVI B, 48H 06 0000 0110 2002
48 0100 1000 2003
ADD B 80 1000 0000 2004
OUT 01H D3 1101 0011 2005
01 0000 0001 2006
HALT 76 0111 1110 2007
Eight Machine code, require eight memory location. MPU can only
understand binary code; everything else(Mnemonics, Hex code,
comments) for the convenience of human being.
36
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Executing the Program
To execute the program, we need to tell the
MPU where the program begins by entering
the memory address 2000H.
Push the execute Key, so MPU loads 2000H in PC.
PC is transferred from the monitor program to our
program.
MPU begin to read the one machine cycle at a time,
when it fetches the complete instruction, it execute
that instruction.
For Eg. When it fetches the machine code stored in
2000 and 2001H and execute the instruction MVI A,
32H , thus load 32H in register A.
Continue to execute the instruction until it fetches the
HLT
instruction.
37
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Microcontroller
38
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Micro controller
A self-contained system in which a processor,
support, memory, and input/output (I/O) are all
contained in a single package.
A small computer system on a single IC
39
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
History of Microcontroller
40
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Microcontroller
41
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Basic Features of Microcontroller
Processor reset
Device clocking
Central processor
Programand Variable
Memory (RAM)
I/O pins
Instruction cycle timers
42
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
More Sophisticated Features
43
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Basic microcontroller architecture (1/3)
44
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Basic microcontroller architecture (2/3)
Memory
• RAM
• ROM
• Store data and code
CPU
• Mathematical and logical
operation
• Memory units are called
Register
45
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Basic microcontroller architecture (3/3)
• BUS
– Group of 8,16 or more wires
– Three type, address bus, data bus
and control bus
• Input-output unit
– port A, port B, port C … …
– Input, output and bidirectional
ports
• Serial communication
• Timer unit
• Watchdog
– Automatic reset to prevent stall
• Analog to Digital Converter (ADC) 46
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture
CISC ( Complex Instruction Set Computer)
• Large amount of instructions each carrying out a
different permutation of the same operation
• Functionality of the instructions is more
dependent upon the processor’s designer.
47
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture continued..
48
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture continued..
49
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture continued..
50
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture continued..
51
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Von Neumann Architecture
52
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture
53
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Processor Architecture
Harvard architecture
Separatememory space
program and data
Instructions are executed in
one cycle
Easier timing of loops and
delays
54
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Harvard Architecture
55
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Advantages of Microcontroller over
Microprocessor
Pin count down
Design time down, Board layout size down
Upgrade path easier – matching between
peripherals for speed
Cost down – bulk purchases
Reliability up
Common software / hardware design
environment available from manufacturer
56
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Difference between
microprocessor & microcontroller
Microprocessor Microcontroller
58
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Host and Target Machine
59
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Embedded Tools
Compiler
Assembler
Linker and locator
Debugger
Emulator
Simulator
Profiler
60
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Compiler
61
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Assembler
An Assembler is software program that
converts source code written in assembly
language into machine language.
63
Faculty
©M. S. Ramaiah
of Engineering
University
& Technology
of Applied Sciences © Ramaiah University of Applied Sciences
Linker and Locator
64
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Linker and Locator
66
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Emulator
• An emulator is a piece of Hardware/Software that
enables one computer system to run programs that
are written for another computer system.
• For example there is a Comodore 64 emulator for
the iPhone which allow you to run games that written
for the iPhone.
• An emulator is used on the target processor (the
processor for which the program is being written).
67
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Emulator Hardware Emulator software
68
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Simulator
69
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Simulator Hardware Simulator Software
70
Faculty of Engineering & Technology © Ramaiah University of Applied Sciences
Profiler