You are on page 1of 99

Unit 1

Introduction to Microcontrollers

Prepared By,
ANILKUMAR PATIL M.Tech, (Ph.D).,
Asst Prof- E&TC
anilkumarpatil1988@gmail.com

Introduction

A decade back the process and control operations were totally


implemented by the Microprocessors only. But now a days the situation
is totally changed and it is occupied by the new devices called
Microcontroller. The development is so drastic that we cant find any
electronic gadget without the use of a microcontroller. This
microcontroller changed the embedded system design so simple and
advanced that the embedded market has become one of the most sought
after for not only entrepreneurs but for design engineers also.

What is a Microcontroller?
A single chip computer or A CPU with all the peripherals like RAM,
ROM, I/O Ports, Timers , ADCs etc... on the same chip. For ex:
Motorolas 6811, Intels 8051, Zilogs Z8 and PIC 16X etc

06/09/16

DYPIEMR AKURDI-44

MICROPROCESSORS & MICROCONTROLLERS

Microprocessor:

A CPU built into a single VLSI chip is called a microprocessor. It is a general-purpose device
and additional external circuitry are added to make it a microcomputer. The microprocessor
contains arithmetic and logic unit (ALU), Instruction decoder and control unit, Instruction
register, Program counter (PC), clock circuit (internal or external), reset circuit (internal or
external) and registers. But the microprocessor has no on chip I/O Ports, Timers , Memory etc.
For example, Intel 8085 is an 8-bit microprocessor and Intel 8086/8088 a 16-bit microprocessor.
The block diagram of the Microprocessor is shown in Fig.1

06/09/16

DYPIEMR AKURDI-44

MICROCONTROLLER:

A microcontroller is a highly integrated single chip, which consists of on chip CPU (Central
Processing Unit), RAM (Random Access Memory), EPROM/PROM/ROM (Erasable
Programmable Read Only Memory), I/O (input/output) serial and parallel, timers, interrupt
controller.
For example, Intel 8051 is 8-bit microcontroller and Intel 8096 is 16-bit microcontroller. The
block diagram of Microcontroller is shown in Fig.2.

06/09/16

What is the Microcontroller ?


A microcontroller is an integrated chip that is often part of an embedded system. The
microcontroller includes a CPU, RAM, ROM, I/O ports, and timers like a standard computer,
but because they are designed to execute only a single specific task to control a single system,
they are much smaller and simplified so that they can include all the functions required on a
single chip.

DYPIEMR AKURDI-44

Difference between MPU and MCU

06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

06/09/16

Von Neumann Architecture: It has single memory storage to hold both program instructions
and data i.e. common program and data space. The CPU can either read an instruction or data
from the memory one at a time (or write data to memory) because instructions and data are
accessed using same bus system. The Von Neumann Architecture is named after the mathematician
and computer scientist John Von Neumann. The basic organization of memory in this architecture is
shown in figure 1.7.
The advantage of Von Neumann architecture is simple design of microcontroller chip because only
one memory is to be implemented which in turn reduces required hardware.
The disadvantage is slower execution of a program. It is also referred as Princeton architecture as
it was developed at Princeton University. Motorola 68HC11 microcontroller is based on
VonNeumann architecture.

DYPIEMR AKURDI-44

Harvard Architecture: It has physically separate memory storage to hold program

instructions and data i.e. separate program and data space. Since it has separate
buses to access program and data memory, it is possible to access program memory
and data memory simultaneously. The organization of memory and buses in this
architecture is shown in figure 1.8.
The advantage of a Harvard architecture microcontroller is that it is faster for a given
circuit complexity because it offers greater amount of parallelism. The disadvantage is
that it requires more hardware, because two sets of buses and memory blocks are
required. MCS 51 (8051 family) and PIC microcontrollers are based on Harvard
architecture

06/09/16

DYPIEMR AKURDI-44

Harward and Von Neumann architecture

06/09/16

DYPIEMR AKURDI-44

RISC and CISC comparison

06/09/16

DYPIEMR AKURDI-44

CISC

RISC

Greater no. of Instructions

Lesser no. of instructions

Generally no instruction pipelining feature

Instruction Pipelining
execution speed

Non Orthogonal Instruction Set (All


instructions are not allowed to operate on
any register and use any addressing mode.
It is instruction specific)

Orthogonal Instruction Set (Allows each


instruction to operate on any register and
use any addressing mode)

Operations are performed on registers or


memory depending on the instruction

Operations are performed on registers


only, the only memory operations are load
and store
Large number of registers are available

Limited no. of general purpose registers


Instructions are like macros in C language.

and

increased

Variable length Instructions

Programmer needs to write more code to


execute a task since the instructions are
simpler ones
Single, Fixed length Instructions

More silicon usage

Less Silicon usage and pin count

Harvard or Von-Neumann Architecture

With Harvard Architecture

06/09/16

DYPIEMR AKURDI-44

Disadvantages of microprocessor
The overall system cost is high
A large sized PCB is required for
assembling all the components
Overall product design requires more time
Physical size of the product is big
A discrete components are used, the
system is not reliable
06/09/16

DYPIEMR AKURDI-44

Advantages of Microcontroller
based System

06/09/16

As the peripherals are integrated into a single chip, the overall


system cost is very less
The product is of small size compared to micro processor based
system
The system design now requires very little efforts
As the peripherals are integrated with a microprocessor the
system is more reliable
Though microcontroller may have on chip ROM,RAM and I/O
ports, addition ROM, RAM I/O ports may be interfaced
externally if required
On chip ROM provide a software security
DYPIEMR AKURDI-44

Applications of Microcontrollers
Biomedical instrumentations
ECG LCD Display cum recorder
Blood cell recorder cum Analyzer
Patient monitor system

Communication Systems

Numeric Pager
cellular phones
cable TV terminals
FAX
video games etc..

Peripheral controllers
keyboard controller
DRAM controller
printer controller
LASER controller
LAN controller etc..
06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

Survey of 8 bit Microcontrollers


PIC 16C5X/XX:
1.Microchip technology makes the PIC 16C5X/XX
family of 8-bit microcontroller chip
2.Maximum clock speed of 40 Hz, can run at lower
speed to save energy
3.They have from 512 to 2 KB of ROM
4.25 to 73 bytes of RAM
5.8 bit RTC, programmable sleep mode and watch
dog timer
6.Current consumption varies from 15 micro amp
to 2 milli amp
06/09/16

DYPIEMR AKURDI-44

Comparison of the 8051 Family


Members

ROM type

8031
80xx
87xx
89xx

no ROM
mask ROM
EPROM
Flash EEPROM

89xx

8951
8952
8953
8955
898252
891051
892051

Example (AT89C51,AT89LV51)

06/09/16

AT= ATMEL(Manufacture)
C = CMOS technology
LV= Low Power(3.0v)

DYPIEMR AKURDI-44

8051 Basic Component

06/09/16

4K bytes internal ROM


128 bytes internal RAM
Four 8-bit I/O ports (P0 - P3).
Two 16-bit timers/counters
One serial interface
64k external memory for code
64k external memory for dataMicrocontroller
210 bit addressable
DYPIEMR AKURDI-44

Motorolas 68HC11
It uses either UV erasable or
electronically erasable memory for
permanent storage
Upto 768 bytes of RAM
Upto 3 MHz clock frequency
27 milli amp of current drawn
It has 8 8-bit ADC for monitoring
analog signals in real time
06/09/16

DYPIEMR AKURDI-44

8051 Families and features

06/09/16

DYPIEMR AKURDI-44

Motorolas 68HC11 & Features

06/09/16

DYPIEMR AKURDI-44

What is Embedded System?

06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

Characteristics of Embedded system

Single Functioned: An Embedded System can execute a specific function


repeatedly i.e., dedicated function. As an example, Air conditioner will be cooling
the room. Cooling is its dedicated functionality and it cannot be used for any
other purposes.
Tightly Constraint : Whatever system is being designed, they have constraints.
Embedded Systems are also tightly constraint in many aspects. Few aspects are
being analyzed here.

06/09/16

1. Manufacturing Cost
2. Performance
3. Size
4. Power

Real Time and Reactive : What is real time? A nice question to start with! A
definition can be given through an example here. Take an instance of travel in
BMW car. (Great feel it would be). (The braking system is an embedded system).
And unfortunately a lorry is coming opposite to the car... The driver is applying
brake there!. What would be the action required? It should immediately stop the
car right. This is a real time and reactive behavior. The brake may be applied at
any point in time. And the vehicle should be stopped immediately at the instance
of applying brake. It is never known when brake has to be applied, so the system
should be ready to accept the input at any time and should be ready to process it.
DYPIEMR AKURDI-44

Complex Algorithms : The processor inside the embedded system should


perform operations that are complex in nature. An example is digital camera. It
is used to take color photographs, motion pictures, black and white pictures, etc.

User Interface : Here too with an example the concept can be explained.
NOKIA mobile phones are very big hit in market right, Why? What is the
reason? Is that because other mobile did not perform well? No, is the answer.
Nokia had excellent and simple user interface. Calls can be made and received
very easily. Typing SMS is also easier So it has been read by the people very
well.
So designing system with easier and comfortable interface is most important.
Also it should have options required for the operation of the device. Example is
ATM machine; it has got comfortable interfaces and options. Keep it in mind
and design the system.

Multi Rate: Embedded Systems need to control and drive certain operations at
one rate and certain other operations at different rate. Example can be Digital
Camera. It is used to take pictures which are still. Also it is capable of shooting
video. So it has to be capable of driving the first operation from a speed different
than the second one.

06/09/16

DYPIEMR AKURDI-44

Limitations of 8 bit Microcontrollers

Data bus width limits speed of execution


Addressable memory is limited for given application
Very small RAM & Flash memory
Does not have high performance interrupt system
Does not have DMA & cache memory for faster
execution
Does not have memory protection unit MPU
Does not have protected modes of operation
Can not implement RTOS which current need of
embedded system
06/09/16

DYPIEMR AKURDI-44

Three criteria in Choosing a


Microcontroller
meeting the computing needs of the task efficiently and
cost effectively
speed, the amount of ROM and RAM, the number of I/O ports
and timers, size, packaging, power consumption
easy to upgrade
cost per unit
Noise of environment

availability of software development tools


assemblers, debuggers, C compilers, emulator, simulator,
technical support

wide availability and reliable sources of the


microcontrollers
06/09/16

DYPIEMR AKURDI-44

Features Taken into consideration selecting


an Microcontrollers

06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

Roll Of Microcontroller In
Embedded System

06/09/16

DYPIEMR AKURDI-44

Facts and figures of Embedded


System
Over 4 billion embedded processors were
sold last year and the global market is
worth 60 billion with annual growth
rates of 14%.
Forecasts predict more than 16 billion
embedded devices by 2010 and over 40
billion by 2020.

Growth Rate
Automotive (36%),
Industrial Automation (22%),
Telecommunications (37%),
Consumer Electronics (41%) And
Health/Medical Equipment (33%).
Similarly, A Modern Cellular Phone Has
More Features Than Those Of a Laptop

Role of Embedded System


For example, in the case of a modern car,
by 2010 over 35% of its value will be due to
embedded electronics. This accounts for
90% of new innovations and features in:
engine management (improved efficiency
and reduced emissions)
safety features (like stability control,
antilock braking and airbags)
comfort (navigation and entertainment
features)

Hardware & Software Tools

Assembler eg MPASM free


Compilers C18,Hi Tech,IAR,SDCC CCS,microC
Do not use MikroCinitially
IDE MPLAB for PIC free
Simulators built in with IDE or Proteus, PIC Simulator
as separate but not free
Programmer, boot loader no special programmer in
PIC18F4550,USB programming is desirable
Development board is very useful for learning testing
the programs independently on new controller & should
be low cost

06/09/16

DYPIEMR AKURDI-44

Software and hardware tools for development of


microcontroller
Levels of Programming Languages
1) Machine Language
Consists of individual instructions that will be
executed by the CPU one at a time

2) Assembly Language (Low Level Language)


Designed for a specific family of processors (different
processor groups/family has different Assembly
Language)
Consists of symbolic instructions directly related to
machine language instructions one-for-one and are
assembled into machine language.

3) High Level Languages


e.g. : C, C++ and Vbasic

Designed to eliminate the technicalities of a


particular computer.
Statements compiled in a high level language typically
generate many low-level instructions.

Advantages of Assembly Language


1. Shows how program interfaces with
the processor, operating system, and
BIOS.
2. Shows how data is represented and
stored in memory and on external
devices.
3. Clarifies how processor accesses and
executes instructions and how
instructions access and process data.
4. Clarifies how a program accesses
external devices.

A Hierarchy of Languages

Compiler and Assembler

Tools used for Assembly Language


development

Editor
Assembler
Linker
Loader
Debugger
Emulator

Editor
It helps the user to create a file that
contains assembly language statements
The editor stores the ASCII codes for the
letters and numbers in the successive RAM
locations
The file is called as the source file and an
ASM extension is given to it
Example of editor wordpad,
notepad,wordstar etc

Assembler
Assembler is a program which translates the
mnemonics into corresponding binary codes.
Operation of Assembler
1) It reads the source file of program
2) It determines the displacement of data items, offset
of label etc and put them into a symbol table
3) It produces the binary codes for each instruction
and inserts the offset etc..
4) It generates the object file with extension o
5) The assembler indicates any syntax error, this error
should be edited using the editor

Linkers
Linker is a program which is used for joining
many object files into one large object file
Searches program libraries to find library
routines used by the program
Library: collection of pre-written functions and
subroutines made available to perform commonly
required activities

Determines the memory locations that code from


each module will occupy and relocates
instructions by adjusting absolute references
Resolves references among files
Chapter 17 Programming Tools

17-43

Linking
Object file

Object
file or object
module

Linker

Executable
file

C library
Chapter 17 Programming Tools

17-44

Locator
The locator is a program which is used
for assigning the specific address of the
locations where the segments of the
object code are to be loaded into the
memory

Debugger
A software tool that is used to detect the
source of program by performing stepby-step execution of application code
and viewing the content of code
variables.
It is a program which permits the user to
load object code into system memory,
execute the program and debug it.

Emulator
Emulator is used to test and debug the
hardware and software of an external
system.

Digital storage oscilloscope

06/09/16

A digital storage oscilloscope is an oscilloscope which stores and analyses the


signal digitally rather than using analogue techniques. It is now the most common
type of oscilloscope in use because of the advanced trigger, storage, display and
measurement features which it typically provides.
The input analogue signal is sampled and then converted into a digital record of the
amplitude of the signal at each sample time. The sampling frequency should be not
less than the Nyquist rate to avoid aliasing. These digital values are then turned
back into an analogue signal for display on a cathode ray tube (CRT), or
transformed as needed for the various possible types of outputliquid crystal
display, chart recorder, plotter or network interface. Oscilloscopes are the devices
for testing signal voltages in fields such as electronic measurement, circuit
debugging, designing, testing in manufacturing, general testing and researches.
You can use the advantages of them to capture the complex signals and watch them
on the screen of the digital oscilloscopes. However, digital storage oscilloscopes
(DSO) can storage the waveform, so it easy for us to capture fleeting signals.

DYPIEMR AKURDI-44

Logic Analyzer

06/09/16

A logic analyzer is an electronic instrument that captures and displays multiple signals from a
digital system or digital circuit. A logic analyzer may convert the captured data into timing
diagrams, protocol decodes, state machine traces, assembly language, or may correlate assembly
with source-level software. Logic Analyzers have advanced triggering capabilities, and are
useful when a user needs to see the timing relationships between many signals in a digital
system.
Logic analyzers can uncover hardware defects that are not found in simulation. These problems
are typically too difficult to model in simulation, or too time consuming to simulate and often
cross multiple clock domains
Logic analyser types
Modular logic analyzers : This type of logic analyser is probably what may be thought of as
the most typical form of test instrument, although it is the highest cost option providing the
highest level of functionality. It comprises a chassis and the various modules - including channel
modules. The number of modules being larger for the higher channel counts.
Portable logic analyzers : In a number of instances there may be a need for a smaller analyser,
possibly for restricted budgets or for field service. These test instruments incorporate all
elements of the analyser into a single box for ease of transportation.
PC based logic analyzers: There is a growing number of PC based logic analysers. These
consist of an analyser unit that is connected to a PC. USB is an obvious option for this, but
Ethernet is also widely used because of its high speed. This form of PC based instrument uses
the processing power of the PC combined with its display to reduce the cost of the overall
system.
DYPIEMR AKURDI-44

Logic analyser key characteristics

06/09/16

There are several key characteristics of a logic analyser that separate it from multichannel oscilloscopes and other test instruments:
Provide a time display of logic states: Logic analysers possess a horizontal time axis
and a vertical axis to indicate a logic high or low states. In this way a picture of the
digital lines can be easily displayed.
Multiple channels: Logic analyzers are designed to monitor a large number of digital
lines. As logic analyzers are optimized for monitoring a large number of digital circuits,
typically they may have anywhere between about 32 and 200+ channels they can
monitor, each channel monitoring one digital line. However some specialized logic
analyzers are suitably scaled to be able to handle many more lines, and in this way
enable tracking and fault finding on much more complex systems.
Displays logic states: The vertical display on the analyser displays the logic state as a
high of low state. The signals enter the various channels and are converted into a high
or low state for further processing within the analyser. It provides a logic timing
diagram of the various lines being monitored.
Does NOT display analogue information : These test instruments do not present any
analogue information, and in this way they differ from an oscilloscope. They are purely
aimed at monitoring the logic operation of the system. If any analogue information is
required, then an oscilloscope must be used in addition.

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

DSO & Logic Analyzer

06/09/16

To see clock freq


To see control signals like SDA,SCK, LE etc
To see data & address line on LA
Triggering for time or state domain Analysis
PC based LA is cheaper than Stand alone
To see port output high low for LED, Relay etc
To see PWM output on DSO
To see square wave or other waveforms

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

UNIT 2

06/09/16

DYPIEMR AKURDI-44

Comparison of the 8051 Family


Members

ROM type

8031
80xx
87xx
89xx

no ROM
mask ROM
EPROM
Flash EEPROM

89xx

8951
8952
8953
8955
898252
891051
892051

Example (AT89C51,AT89LV51)

06/09/16

AT= ATMEL(Manufacture)
C = CMOS technology
LV= Low Power(3.0v)

DYPIEMR AKURDI-44

Comparison some of the 8051 Family


Members

06/09/16

ROM

RAM

Timer

8051

4k

128

8031

128

8751

4k eprom

128

8052

8krom

256

8032

256

8752

8k eprom

256

DYPIEMR AKURDI-44

8051 Basic Component

06/09/16

4K bytes internal ROM


128 bytes internal RAM
Four 8-bit I/O ports (P0 - P3).
Two 16-bit timers/counters
One serial interface
64k external memory for code
64k external memory for dataMicrocontroller
210 bit addressable
DYPIEMR AKURDI-44

The basic 8051 Core


8-bit CPU optimized for control applications
Capability for single bit Boolean operations.
Supports up to 64K of program memory.
Supports up to 64K of data memory.
4 K bytes of on-chip program memory.
Newer devices provide more.
128 or 256 bytes of on-chip data RAM
Four 8 bit ports.
Two 16-bit timer/counters
UART
Interrupts
On-chip clock oscillator
06/09/16

DYPIEMR AKURDI-44

Block Diagram
External interrupts
Interrupt
Control

On-chip
ROM for
program
code

Timer/Counter

On-chip
RAM

Timer 1
Timer 0

CPU

OSC

Bus
Control

4 I/O Ports

P0 P1 P2 P3

Address/Data
06/09/16

DYPIEMR AKURDI-44

Serial
Port

TxD RxD

Counter
Inputs

8051 Internal Block Diagram

06/09/16

DYPIEMR AKURDI-44

8051
Schematic
Pin out

06/09/16

DYPIEMR AKURDI-44

8051
Foot Print

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND

06/09/16

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

8051
(8031)
(8751)
(8951)

DYPIEMR AKURDI-44

40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21

Vcc
P0.0(AD0
)P0.1(AD1)
P0.2(AD2
) 0.3(AD3)
P
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14
)P2.5(A13
)P2.4(A12
)P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)

Power-On RESET Circuit


Vcc

+
10 uF
31
30 pF
8.2 K

11.0592 MHz

19
18

30 pF

EA/VPP
X1
X2

9 RST

06/09/16

DYPIEMR AKURDI-44

Port 0 with Pull-Up Resistors


Vcc

10 K

06/09/16

Port 0

P0.0
DS5000 P0.1
P0.2
8751
P0.3
P0.4
8951
P0.5
P0.6
P0.7

DYPIEMR AKURDI-44

IMPORTANT PINS (IO Ports)


One of the most useful features of the 8051 is that it contains
four I/O ports (P0 - P3)
Each port can be used as input or output (bi-direction)

Port 0
pins 32-39 P0.0 P0.7

8-bit R/W - General


Purpose I/O
Or acts as a multiplexed
low byte address and data
bus for external memory
design

06/09/16

DYPIEMR AKURDI-44

IMPORTANT PINS (IO Ports)

Port 1
pins 1-8 P1.0
P1.7

Only 8-bit R/W General Purpose I/O

06/09/16

DYPIEMR AKURDI-44

IMPORTANT PINS (IO Ports)

Port 2
pins 21-28 P2.0
P2.7

8-bit R/W General Purpose


I/O
Or high byte of
the address bus
for external
memory design
06/09/16

DYPIEMR AKURDI-44

IMPORTANT PINS (IO Ports)


Port 3
pins 10-17 P3.0
P3.7

General Purpose I/O


if not using any of the
internal peripherals
(timers) or external
interrupts.

06/09/16

DYPIEMR AKURDI-44

Port 3 Alternate Functions

06/09/16

DYPIEMR AKURDI-44

ALE

- Address latch enable


to select valid address
EA/Vpp - External access enable
EA-0 execute program in external
memory
EA-1 execute program in internal
memory
Vpp it receives 21 V for on chip EPROM
PSEN Program store enable
store to read the external program memory

06/09/16

DYPIEMR AKURDI-44

Registers
A
B
R0

DPTR

DPH

DPL

R1
R2

PC

PC

R3
R4

Some 8051 16-bit Register

R5
R6
R7
Some 8-bitt Registers of
the 8051

06/09/16

DYPIEMR AKURDI-44

Parallel I/O Ports

Each port can be input or output


Direction is set in Special Function Registers

06/09/16

Port0
latch

Port1
latch

Port2
latch

Port3
latch

Port0

Port1

Port2

Port3

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

DPTR
The data pointer consists of a high
byte(DPH) and a low byte (DPL). Its
function is to hold a 16 bit address. It
may be manipulated as a 16 bit data
register or two independent 8 bit
register. It serves as a base register in
indirect jumps, lookup table instructions
and external data transfer.
06/09/16

DYPIEMR AKURDI-44

PROGRAM STATUS WORD (PSW)


CY

06/09/16

AC

F0

RS1

RS0

OV

RS0

RS1

BANK SELECTION

00H 07H BANK0

08H 0FH BANK 1

10H 17H BANK2

18H 1FH BANK 3

DYPIEMR AKURDI-44

Stack in the 8051


7FH

The register used to access


the stack is called SP
(stack pointer) register.

Scratch pad RAM


30H
2FH

The stack pointer in the


8051 is only 8 bits wide,
which means that it can
take value 00 to FFH.
When 8051 powered up,
the SP register contains
value 07.

06/09/16

Bit-Addressable RAM
20H
1FH
18H
17H
10H
0FH
08H
07H
00H

DYPIEMR AKURDI-44

Register Bank 3
Register Bank 2
Register Bank 1( Stack)
Register Bank 0

Memory Organization
The 8051 memory organization is rather complex.
The 8051 has separate address spaces for Program Memory, Data Memory, and
external RAM.
This is refereed to as a Harvard architecture.
The early Mark I (1944) computer developed at Harvard was of this type of
architecture.
Von Neumann at Princeton pointed out that it was not necessary to put
instructions and data in separate memories.
Most machines have been Princeton architecture.
Recently Harvard architecture has been employed to help alleviate the
memory bottleneck.
Both program memory and external data memory are 8 bits wide and use 16 bits
of address. The internal data memory is accessed using an 8-bit address.
Since the same address can refer to different locations the specific location is
determined by the type of instruction.

06/09/16

DYPIEMR AKURDI-44

Program or Code Memory


May consist of internal or external program memory. The amount of
internal program memory varies depending on the device.
4K bytes typical in older devices.
The Silicon Labs C8051F310 contains 16K of flash memory for
programs.
The Silicon Labs C8051F020 which is on the University Daughter Card
(UDC) contains 4K bytes of program memory.
The MOVC instruction can be use to read code memory.
To reference code memory I will use the notation:
CM = CM(0,,FFFFH) = CM(0,,FFFFH; 7,,0)
This notation can be used to specify particular bits and bytes of code
memory.
For example CM(1234H) refers to the byte of code memory at address 1234H.
CM(1234H;7) refers to the most significant bit in that address.

06/09/16

DYPIEMR AKURDI-44

MOVC A,@A + DPTR ;A CM(A+DPTR)


MOVC A,@A + PC
;A CM(A+PC)

CM

PC = PC(15..0)
DPTR = DPTR(15..0)

06/09/16

DYPIEMR AKURDI-44

External Memory
Supports up to 64K bytes external memory.
XM(0000,,FFFF)
= XM(0000,,FFFF; 7,,0)
Accessed by using the MOVX instruction.

On the original using external memory reduces


number of available I/O ports.
On some new devices this is not the case.
For example in C8051F020 64K bytes of external memory
has been included in the chip.
The 4 standard 8051 ports are available and three additional
ports have been added.

06/09/16

MOVX A,@DPTR
;A XM(DPTR)
MOVX A,@Rn
;A XM(P2|Rn)
MOVX @DPTR,A
;XM(DPTR) A
MOVX @Rn,ADYPIEMR AKURDI-44
;XM(P2|Rn) A

Data Memory
The original 8051 had 128 bytes of on-chip data RAM.
This memory includes 4 banks of general purpose registers at
DM(00..1F)
Only one bank can be active at a time.
If all four banks are used, DM(20..7F) is available for program data.
DM(20..2F) is bit addressable as BADM(00..7F).

DM(80,,FF) contains the special function registers such as


I/O ports, timers, UART, etc.
Some of these are bit addressable using BADM(80..FF)

On newer versions of the 8051, DM(80,,FF) is also use as


data memory. Thus, the special functions registers and data
memory occupy the same address space. Which is accessed is
determined by the instruction being used.

06/09/16

DYPIEMR AKURDI-44

MOV A,0A2H

XM

MOV R1,#0A2H
MOV A@R1

MOV A,62H

DM

MOV R1,#62H
MOV A@R1
06/09/16

DYPIEMR
AKURDI-44
Data
memory

06/09/16

DYPIEMR AKURDI-44
Data Memory
(DM)

06/09/16

DYPIEMR AKURDI-44

Intel 8051: Timers/Counters

06/09/16

DYPIEMR AKURDI-44

Timer

Timer/Counter Mode Control Register TMOD

A timer is a counter that is


increased with every time an
instruction is executed e.g. 8051
with 12MHz increases a counter
every 1.000 s
General 8051 has 3 timer:

2 16-bit timer
1 16-bit timer with
extra-functionality
(introduced with the
8052)
06/09/16

Timer/Counter Control Register TCON

DYPIEMR AKURDI-44

Uses of Timers & Counters


- Interval Timing
- Periodic event timing
- Time base for measurements
- Event Counting
-Baud Rate Generation
8051 Timers
- 2 timers (Timer 0 and Timer 1)
- 16-bit timers (65,535) max
- Flag is set when the timer overflows
-Timers can be based on internal clock (OSC/6) or from
external source (counter mode).
TMOD - Timer/Counter mode register
TCON - Timer/Counter control register
06/09/16

DYPIEMR AKURDI-44

TMOD Register:

Gate : When set, timer only runs while INT(0,1) is


C/T : Counter/Timer select bit.
M1 : Mode bit 1.
M0 : Mode bit 0.

06/09/16

DYPIEMR AKURDI-44

high.

TCON Register:

TF: Overflow flag


Set by hardware on Timer/Counter overflow
Cleared by hardware when processor vectors to interrupt routine
TR: Run control bit
Set/Cleared by software to turn Timer/Counter on/off
IE: Interrupt Edge flag
Set by hardware when external interrupt edge detected
Cleared when interrupt processed
IT: Interrupt Type control bit
Set/Cleared by software to specify
falling edge/low level triggered external interrupts

06/09/16

TF1: Timer 1 overflow flag.


TR1: Timer 1 run control bit.
TF0: Timer 0 overflag.
TR0: Timer 0 run control bit.
IE1: External interrupt 1 edge flag. IT1: External interrupt 1 type flag.
IE0: External interrupt 0 edge flag. IT0: External interrupt 0 type flag.
DYPIEMR AKURDI-44

Internal clock
To Counter/Timer

Falling edge-trigger
External clock
06/09/16

DYPIEMR AKURDI-44

Timer Modes
- 0: 13 bit timer
- 1: 16-bit timer
- 2: 8-Bit auto reload
-3: Split timer mode
Mode 0: 13-Bit Timer
- Lower byte (TL0/TL1) + 5 bits of upper bytes (TH0/TH1).
- Backward compatible to the 8048
- Not generally used
06/09/16

DYPIEMR AKURDI-44

Mode 1: 16-bit
- All 16 bits of the timer (TH0/TL0, TH1,TL1) are used.
- Maximum count is 65,536
-At 12Mhz, maximum interval is 65536 microseconds
or 65.536 milliseconds
- TF0 must be reset after each overflow
- THx / TLx must be manually reloaded after each overflow.

06/09/16

DYPIEMR AKURDI-44

Mode 2: 8-bit Auto Reload


- Only the lower byte (TLx) is used for counting.
- Upper byte (THx) holds the value to reload into TLx after
an overflow.
- TFx must be manually cleared.
- Maximum count is 256
- Maximum interval is 256 Microseconds or .256
milliseconds

06/09/16

DYPIEMR AKURDI-44

Mode 3- Split Timer


- Splits Timer 0 into two 8-bit timers
- TL0 sets TF0
- TH0 sets TF1
- Timer 1 is available for other 3 modes, but the TF1
is not available.

06/09/16

DYPIEMR AKURDI-44

06/09/16

DYPIEMR AKURDI-44

Timer Delay and Timer Reload Value


Timer Delay = Delay Value Timer Clock Cycle Duration
Delay Value = how many counts before register(s) roll over
Timer Clock Cycle Duration = 6/oscillator frequency
Delay Value = Maximum Register Count Timer Reload Value
Maximum Register Count = 65535

06/09/16

DYPIEMR AKURDI-44

http://www.slideshare.net/ajooani/introd
uction-to-microcontrollers-29681308

06/09/16

DYPIEMR AKURDI-44