Module-1 1
Module-1 1
8051
Microcontroller
● Introduction
II
18EC4
6
Micocontroll
MICROCONTROLLER 18EC46
Halesha H R
MICROCONTROLLER 18EC46
Definition:
• Microcontroller (MCU for microcontroller unit) is a small computer on a
single metal-oxide-semiconductor (MOS) integrated circuit (IC) chip.
• Microcontroller contains one or more CPUs (processor cores) along with
memory and programmable input/output peripherals.
Halesha H R
MICROCONTROLLER 18EC46
Halesha H R
MICROCONTROLLER 18EC46
Halesha H R
MICROCONTROLLER 18EC46
Halesha H R
MICROCONTROLLER Syllabus 18EC46
Module -2
Module-1
8051 Instruction Set: Addressing Modes, Data
8051 Microcontroller: Microprocessor Vs
Transfer instructions, Arithmetic instructions,
Microcontroller, Embedded Systems, Embedded
Logical instructions, Branch instructions, Bit
Microcontrollers, 8051 Architecture- Registers,
manipulation instructions. Simple Assembly
Pin diagram, I/O ports functions, Internal
language program examples (without loops) to
Memory organization. External Memory (ROM &
use these instructions.
RAM) interfacing.
Module-3
8051 Stack, I/O Interfacing
Programming: and
Port8051 Stack, Stack and Subroutine
instructions. Assembly language program
examples on subroutine and involving loops.
Interfacing simple switch and LED to I/O ports to
switch on/off LED with respect to switch status.
Halesha H R
MICROCONTROLLER Syllabus 18EC46
Module -4 Module -5
8051 Timers and Serial Port: 8051 Timers and 8051 Interrupts and Interfacing Applications:
Counters – Operation and Assembly language 8051 Interrupts. 8051 Assembly language
programming to generate a pulse using Mode-1 programming to generate an external interrupt
and a square wave using Mode-2 on a port pin. using a switch, 8051 C programming to generate a
8051 Serial Communication- Basics of Serial square waveform on a port pin using a Timer
Data Communication, RS-232 standard, 9 pin interrupt. Interfacing 8051 to ADC-0804, DAC, LCD
RS232 signals, Simple Serial Port programming and Stepper motor and their 8051 Assembly
in Assembly and C to transmit a message and to language interfacing programming.
receive data serially.
Halesha H R
MICROCONTROLLER 18EC46
Halesha H R
MICROCONTROLLER 18EC46
Computer:
• Computer hardware consists of four main
• Multipurpose programmable machine;
components.
• Reads binary instructions from its memory, 1. Central processing unit (CPU) which acts
• Accepts binary data as input, as computer‘s brain.
• Processes data according to those instructions 2. Input unit through which program and
data can be entered.
and
Eg: Keyboard, Mouse
• Provides results as output. 3. Output unit on which results of the
• Made up of both hardware and software. computations can be displayed.
• Hardware: Various components of the computer. Eg: Monitor
• Software: Set of instructions written for computer to 4. Memory in which data and programs are
stored.
solve a specific task is called program and collection of
programs is called software.
Halesha H R
MICROCONTROLLER 18EC46
Computer:
Halesha H R
MICROCONTROLLER 18EC46
Microprocessors:
• Used as digital computer central processing unit (CPU).
• Known as ‘Computer on Chip’ but not complete digital
computer.
• Block diagram of a Microprocessor CPU consists of:
• ALU, Program counter (PC), Stack pointer (SP),
working registers, clock timing circuit and interrupt
circuit’s.
• For microcomputer we must add;
• Memory usually RAM and ROM, memory decoders,
oscillator & number of Input/Output devices such as Fig: Block Diagram of a
serial and parallel ports. Microprocessor.
• In addition special purpose devices such as interrupt
handler and counters may be added to relieve the
CPU from time consuming.
Halesha H R
MICROCONTROLLER 18EC46
Microcontroller:
• Microcontroller is a programmable digital processor with necessary peripherals.
• Both microcontrollers and microprocessors are complex sequential digital circuits
meant to carry out job according to the program/instructions.
• Analog input/output interface makes a part of microcontroller circuit as mixed mode
(both analog and digital) in nature.
• Microcontroller is a true “Computer on chip”.
• Incorporates all features found in microprocessor CPU: ALU, PC, SP and registers.
• Also has other features needed to make a complete computer: ROM, RAM, Parallel I/O,
serial I/O, Counters and clock circuits.
Halesha H R
MICROCONTROLLER 18EC46
Microcontroller:
Halesha H R
MICROCONTROLLER 18EC46
Differences Between Microprocessor & Microcontroller
Microprocessor: Microcontroller:
1. CPU is stand-alone. RAM, ROM, I/O, timer are 1. CPU, RAM, ROM, I/O, and timer are located on a
separate and interfaced with CPU. single chip.
2. Designer can decide on the amount of RAM, 2. Fixed amount of RAM, ROM, I/O ports on chip.
ROM etc can be connected. 3. Applications in which cost, space and power
3. Expensive applications. are critical.
4. Versatile and general purpose. 4. Not very versatile.
5. Large number of instructions with flexible 5. Limited number of instructions with few
addressing modes. addressing modes.
6. Very few instructions 6. Many instructions which have bit-
which have bit-handling handling
capability.
capability.
Halesha H R
Module No: 1
8051 Microcontroller
● 8051 Architecture,
Registers
II
18EC4
6
Micocontroll
MICROCONTROLLER 18EC46
8051 Microcontroller:
Definition: It is an 8-bit microcontroller created in 1981
by Intel Corporation. It has an 8-bit processor that
means it operates on 8-bit data at a time. It is the most
popular and commonly used microcontroller.
• It is 40-pin IC
• Data bus is 8-bit
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic & Arithmetic and Logic Unit:
Logic Unit • Its an 8-bit
• Performs arithmetic and logical operations on 8-bit data.
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
A and B registers:
Logic Unit
• 8-bit registers, holds result of arithmetic and logical operations.
A B • Bit-addressable registers i.e., each bit can be accessed for reading or
for altering.
• A register is also called as Accumulator, since it is used as destination
in many operations such as addition, subtraction, integer
multiplication, division, Boolean bit manipulation and Accumulates
the result.
• Also used for data transfers between 8051 and external memory.
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
A and B registers:
Logic Unit
• B register may be used as general purpose register to store the data.
A B • Along with A register, B register is used for multiplication and division
operations.
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit
• 8-bit register, also referred to as flag register.
A B • Indicates certain conditions like carry, parity, sign etc. after execution
of certain instructions.
• Flags are 1-bit registers, jump instructions can test condition of flags
(0 or 1) and make decisions based on status of flags.
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit
• Status of flags are grouped in PSW register, Only 6 bits are used.
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
CY: Carry Flag
• Alternate name is PSW.7
• Used in arithmetic, jump, rotate, and Boolean instructions
= 1; when there is a carry after an addition or a barrow after
subtraction.
= 0; otherwise
• Also it can be set or reset using an instructions “SETB C” &
“CLR C”.
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
1 0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 1 0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
C6 = 0 1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 1 0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
C6 = 0 1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 1 0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
C7 = 1 C6 = 0 1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 1 0 0 0 0 0
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit No: 7 6 5 4 3 2 1 0
C7 = 1 C6 = 0 1 AC = 1
1 0 0 1 1 0 0 0 = 98h
1 0 0 0 1 0 0 0 = 88h
0 0 1 0 0 0 0 0 = 20h
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Example:
Bit 6 5 4 3 2 1 0
7
No:
C7 = 1 C6 = 0 1 AC = 1
1 0 0 1 1 0 0 0 = 98h = 152
1 0 0 0 1 0 0 0 = 88h = 136
0 0 1 0 0 0 0 0 = 120h = 288
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
-- : User defined flag
• Alternate name is PSW.1
• Reserved for future use
P: Parity Flag
• Alternate name is PSW.0
• Shows the parity of register A
• Reflects number of 1’s in accumulator register
= 1; Odd parity: odd number of 1’s
= 0; Even parity: even number of 1’s
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW
Program Status Word (PSW) Register:
Logic Unit • PSW and bit assignments are shown below:
7 6 5 4 3 2 1 0
A B CY AC F0 RS1 RS0 OV -- P
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW Special Special Function Registers (SFR):
Logic Unit Function • Do not use RAM addresses 00h to 7Fh, specific
Register internal registers, uses addresses from 80h to FFh.
A B RAM • Some SFRs are bit-addressable.
• All addresses from 80h to FFh are not used.
• In instructions, SFRs are named by functional
names, such as A or TH0, also referenced by their
DPTR
addresses, such as 0E0h or 8Ch.
PC DPL
• SFR’s have special roles in 8051.
DPH
• Various registers and their addresses are:
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic & Special Name: Function: Address
PSW
Logic Unit Function A Accumulator E0
B Arithmetic F0
Register
DPH Addressing External Memory 83
A B RAM DPL Addressing External Memory 82
IE Interrupt Enable Control A8
IP Interrupt Priority B8
P0 Input / Output Port Latch 80
P1 Input / Output Port Latch 90
DPTR P2 Input / Output Port Latch A0
PC DPL P3 Input / Output Port Latch B0
DPH PCON Power Control 87
PSW Program Status Word D0
SCON Serial Port Control 98
SBUF Serial Port Data Buffer 99
SP Stack Pointer 81
TMOD Timer/Counter Mode Control 89
TCON Timer/Counter Control 88
TL0 Timer 0 low byte 8A
TH0 Timer 0 high byte 8C
TL1 Timer 1 low byte 8B
Halesha HTH1
R Timer 1 high byte 8D
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic &
PSW Special ROM:
Logic Unit Function • 4K bytes of Read only Memory
Register • Address Range: 0000h to 0FFFh
A B RAM
DPTR
PC DPL ROM
DPH
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic & Special
PSW
Logic Unit
Port 0
Latch
Function
Register
A B RAM
Port 1
Latch
I/O
DPTR
PC DPL ROM
DPH
Port 2
Latch
I/O Port:
• 32 I/O Pins arranged as 4, 8-Bit
ports
Port 3
Latch
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic & Special
PSW
Logic Unit
Port 0
Latch
Function
Register
A B RAM
8-Bit Data &
Address
Port 1
Latch
Bus
I/O
DPTR
PC DPL ROM
DPH 16-Bit
Port 2
Latch
Address Bus
Port 3
Latch
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic & Special
PSW
Logic Unit
Port 0
Latch
Function
Register
A B RAM
8-Bit Data &
Address
Port 1
Latch
Bus
I/O
DPTR
PC DPL ROM
DPH 16-Bit
Port 2
Latch
Address Bus
Port 3
Latch
Halesha H R
MICROCONTROLLER Architecture of 8051 18EC46
Arithmetic & Special
PSW
Logic Unit
Port 0
Latch
Function
Register
A B RAM
8-Bit Data &
Address
Port 1
Latch
Bus
I/O
DPTR
PC DPL ROM
DPH 16-Bit
Port 2
Latch
Address Bus
Port 3
Latch
Halesha H R
MICROCONTROLLER Feature of 8051 18EC46
Halesha H R
MICROCONTROLLER Feature of 8051 18EC46
1. 8-bit CPU with registers A (Accumulator) and B. Accumulator is used in most arithmetic and
logic operations. Register B is used for integer multiplication and division.
2. 16-bit Program counter (PC): To hold the address of the next instruction to be executed, and
16-bit Data Pointer (DPTR): Used to access external memory.
3. 8-bit Program Status Word (PSW): Indicates certain conditions like status of carry, parity, sign
etc, after execution of some instructions.
4. 8-bit Stack Pointer (SP): To hold the address of Top of Stack (TOS).
5. Internal Memory (RAM) of 128 bytes, divided as:
i. Four register banks of 8 registers each.
ii. 16 bytes, which are bit addressable. The individual bits of these bytes cab be altered.
iii. 80 bytes of general purpose RAM memory.
iv. 4K Code Memory
Halesha H R
MICROCONTROLLER Feature of 8051 18EC46
6. 4K Code Memory
7. 32 I/O Pins arranged as 4, 8 Bit ports
8. Two 16 Bit Timer/Counter: Timer 0 (T0), and Timer 1 (T1). The timers can be used in timer
mode when counting the internal clock pulses and in counter mode when counting the external
pulses.
9. Full Duplex serial data receiver/transmitter register (SBUF). This holds the byte to be
transmitted or the received byte, when serial communication is used.
10. Control Registers: TCON, TMOD, SCON, PCON, IP and IE which controls the operations of the
timers, serial port and interrupts.
11. Two External and Three Internal Interrupt sources. Interrupts are events which interrupt the
normal sequence of execution of instructions.
12. Oscillator and clock circuits
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
□ Heart of 8051 which generates clock pulses and all internal
operations are synchronized.
□ In most microcontrollers, built-in circuitry allows simple
connection of a crystal or ceramic resonators or an external
clock source. Pins XTAL1 and XTAL2 are provided.
□ Typically, quartz crystal & capacitors are employed.
□ Ceramic resonators
resonators. is low-
□ costpoor frequency stability and accuracy, foralternative
But high-speed
Fig: Crystal or Ceramic Resonator to
data serial communication with other systems.
crystal
Oscillator Circuit. □ Oscillator formed by crystal, capacitors and on-chip inverter
generates a pulse of train at frequency of the crystal.
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1
P2
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1
P2
State 1
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1
P2
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1
P2
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Address Latch Enable (ALE): Used as a timing pulse for external memory access.
Lower order address bus is multiplexed with data bus: AD0 to AD7
ALE = 1; A0 to A7
ALE = 0; D0 to
D7
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Address Memory Write ALP to add two numbers stored in 20h & 21h and store the result in 22h.
in Hex ORG 00h
Content MOV A, 20h ;Copy content of 20h into A register, A = 39h
22 5C MOV R0, 21h ;Copy content of 21h into R0 register, R0 = 23h
ADD A, R0 ;Add content of A with the content of R0
21 23 MOV 22h, A ;Store result 20h, 20h = 5Ch
20 39 END ;End of
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1
Address P2Memory
in Hex
0006 Content
22
State 1 State 2 State 3 State 4 State 5 State 6
0005 F5
One Machine Cycle (6 States, 12 pulses) 0004 28
0003 21
ALE
0002 A8
Address Memory ORG 00h 0001 20
in Hex MOV A, 20h ;E5h, 20h 0000 E5
Content MOV R0, ;A8h, 21h
22 5C 21h
ADD A, R0 ;28h
MOV 22h, ;F5h, 22h
21 23 A END
20 39 Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Halesha H R
MICROCONTROLLER 18EC46
Oscillator Circuit and Timing of 8051:
P1 P2 P1 P2 P1 P2 P1 P2 P1 P2 P1 P2
ALE
Halesha H R
MICROCONTROLLER 18EC46
8051 Internal Memory:
□ Memory is must to store program codes and also data.
□ 8051 has internal ROM (4K byte) and RAM (128 bytes) memory.
□ Harvard architecture: Uses same address in different memory locations for code and data.
□ Additional external memory can be interfaced if required.
□ Internal circuitry accesses correct memory segment, based on the instruction being
executed.
Halesha H R
MICROCONTROLLER 18EC46
8051 Internal RAM Memory: Register Banks:
• Starting 32 bytes from 00h to 1Fh are assigned to 32
□ 128bytes internal
working registers.
RAM is organized into 3
• Organized as 4 register banks, each having 8 registers.
distinct areas. Banks are: Bank 0 to Bank 3
1. Register Banks Registers are: R0 to R7
2. Bit/Byte addressable RAM • Register can be addressed by name or by its address.
3. General purpose RAM • RS0 & RS1 of PSW determines which bank is currently
selected.
• Register banks which are not selected can be used as
general purpose RAM.
• By default Bank 0 is selected on reset.
Halesha H R
MICROCONTROLLER 18EC46
8051 Internal RAM Memory:
Bank 0 Bank 1 Bank 2 Bank 3
Address Address Address Address
in Hex in Hex in Hex in Hex
07 R7 0F R7 17 R7 1F R7
06 R6 0E R6 16 R6 1E R6
05 R5 0D R5 15 R5 1D R5
04 R4 0C R4 14 R4 1C R4
03 R3 0B R3 13 R3 1B R3
02 R2 0A R2 12 R2 1A R2
01 R1 09 R1 11 R1 19 R1
00 R0 08 R0 10 R0 18 R0
Halesha H R
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
Halesha H R 20
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2E 77 76 75 74 73 72 71 70
• Next 16 bytes from 20h to 2Fh are bit
2D 6F 6E 6D 6C 6B 6A 69 68
addressable. 2C 67 66 65 64 63 62 61 60
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2E 77 76 75 74 73 72 71 70
• Next 16 bytes from 20h to 2Fh are bit
2D 6F 6E 6D 6C 6B 6A 69 68
addressable. 2C 67 66 65 64 63 62 61 60
2A 57 56 55 54 53 52 51 50
• Address Range is: 00h to 7Fh
29 4F 4E 4D 4C 4B 4A 49 48
• Bit may be specified by its address. 28 47 46 45 44 43 42 41 40
26 37 36 35 34 33 32 31 30
address or byte address.
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2E 77 76 75 74 73 72 71 70
For example: Address 27h is a bit address of bit
2D 6F 6E 6D 6C 6B 6A 69 68
7 of 24h or it can be a byte address, it depends 2C 67 66 65 64 63 62 61 60
on the instruction. 2B 5F 5E 5D 5C 5B 5A 59 58
2A 57 56 55 54 53 52 51 50
29 4F 4E 4D 4C 4B 4A 49 48
28 47 46 45 44 43 42 41 40
27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2E 77 76 75 74 73 72 71 70
For example: Address 27h is a bit address of bit
2D 6F 6E 6D 6C 6B 6A 69 68
7 of 24h or it can be a byte address, it depends 2C 67 66 65 64 63 62 61 60
on the instruction. 2B 5F 5E 5D 5C 5B 5A 59 58
2A 57 56 55 54 53 52 51 50
MOV A, 27h; Byte address
29 4F 4E 4D 4C 4B 4A 49 48
MOV C, Bit address 28 47 46 45 44 43 42 41 40
27h; 27 3F 3E 3D 3C 3B 3A 39 38
26 37 36 35 34 33 32 31 30
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
Address
8051 Internal RAM Memory: in Hex
7 6 5 4 3 2 1 0
2E 77 76 75 74 73 72 71 70
For example: Address 27h is a bit address of bit
2D 6F 6E 6D 6C 6B 6A 69 68
7 of 24h or it can be a byte address, it depends 2C 67 66 65 64 63 62 61 60
on the instruction. 2B 5F 5E 5D 5C 5B 5A 59 58
2A 57 56 55 54 53 52 51 50
MOV A, 27h; Byte address
29 4F 4E 4D 4C 4B 4A 49 48
MOV C, 27h; Bit address 28 47 46 45 44 43 42 41 40
26 37 36 35 34 33 32 31 30
program needs to remember a binary event.
25 2F 2E 2D 2C 2B 2A 29 28
24 27 26 25 24 23 22 21 20
23 1F 1E 1D 1C 1B 1A 19 18
22 17 16 15 14 13 12 11 10
21 0F 0E 0D 0C 0B 0A 09 08
Halesha H R 20 07 06 05 04 03 02 01 00
MICROCONTROLLER 18EC46
8051 Internal RAM Memory: Address
in Hex
General purpose RAM 7F
• Above the bit area from 30h to 7Fh, is
general purpose RAM, and they are
byte addressable.
Directly and Indirectly
addressable general
purpose RAM
30
Halesha H R
MICROCONTROLLER 18EC46
8051 Internal Extended Memory:
• Internal RAM is 128 byte.
• Minimum address bits required is 7-bits.
• To represent in hexadecimal, consider 8-bits
• Maximum address range is: 00h to FFh.
• 00h to 7Fh are used.
• 80h to FFh are not used.
• Can’t be used as general purpose memory.
• Used for SFR’s, and all addresses are not used.
Halesha H R
MICROCONTROLLER 8051 Internal Extended Memory: 18EC46
8F Un-us 9F AF CF FF
DF EF
ed
8E to BF
8D TH1 Un-us
to ed Un-us Un-us
8C TH0 to ed to ed
8B TL1
8A TL0 9A
86 Un-us
ed
84 to Un-us Un-us Un-us
to ed to ed to ed
83 DPH
82 DPL
81 SP 91 A1 B1 D1 E1 F1
80 Port 0 90 Port 1 A0 Port 2 B0 Port 3 C0 D0 PSW E0 A F0 B
Halesha H R
MICROCONTROLLER 18EC46
Internal ROM:
• Different family members have different ROM sizes.
• 8751, AT8951 have 4K bytes of ROM on chip;
• AT89C52 has 8K bytes;
• DS5000-32 has 32K bytes and so on.
• But can’t access more than 64K bytes of opcode, since the program
counter is 16-bits (0000h to FFFFh).
• First location of is 0000h, last location can differ, depending on the size
of the ROM on chip.
• If ROM size is 4k, the address range is 0000h to 0FFFh.
Halesha H R
MICROCONTROLLER 18EC46
Thank you
Halesha H R