8051 Full
8051 Full
8051 Full
CSE-317
Microcontroller
8051
Interfacing
8259 PIC (Programmable interrupt control)
8237 DMA
The 8051 Microcontroller and Embedded Systems
Mazidi Mazidi McKinlay Second Edition
8051
Introduction to 8051
The 8051 microcontroller was first introduced by Intel in the year 1981 for
embedded systems
It is an 8 – bit Microcontroller i.e. the data bus of the 8051 Microcontroller
(both internal and external) is 8 – bit wide
It is a CISC (Complex Instruction Set Computer) based Microcontroller with
Harvard Architecture (separate program and data memory). i.e It has
separate memory spaces for instructions and data
Originally, 8051 Microcontrollers were developed using N-MOS Technology
but the use of battery powered devices and their low power consumption
lead to usage of CMOS Technology (which is famous for its low power
consumption)
Introduction to 8051
• Even though Intel developed 8051 Microcontrollers (which is
discontinued in 2007), more than 20 semiconductor manufacturers are
still producing 8051 compatible microcontrollers i.e. processors based
on MSC-51 Architecture.
• Some of the 8051 Microcontrollers produced by different manufacturers
are: Atmel (AT89C51, AT89S51), Phillips (S87C654), STC Micro
(STC89C52), Infineon (SAB-C515, XC800), Siemens (SAB-C501),
Silicon Labs (C8051), NXP (NXP700, NXP900), etc.
• Because of their low power consumption, smaller size and simple
architecture, 8051 IP Cores are used in FPGAs (Field Programmable
Gate Array) and SoCs (System on Chip) instead of Advanced ARM
Architecture based MCUs.
Introduction to 8051
XTL2
Internal ROM
P2
4KB
(Prog Memory) P3
RESET
ALE
P3.0 RxD
EA 8051 P3.1 TxD
PSEN P3.2 INT0
• Microprocessors act as the heart of the • Microcontrollers act as the heart of the
computer system embedded system
CY AC F0 RS1 RS0 OV - P
D7/PSW7 D6/PSW6 D5/PSW5 D4/PSW4 D3/PSW3 D2/PSW2 D1/PSW1 D0/PSW0
The program status word (PSW) is an 8-bit register which is also referred as the
flag register
The main function of this register is to show the status of the program/flag after
any arithmetic operations
CY AC F0 RS1 RS0 OV - P
D7/PSW7 D6/PSW6 D5/PSW5 D4/PSW4 D3/PSW3 D2/PSW2 D1/PSW1 D0/PSW0
Out of 6, Four of the flags are called conditional flags, meaning that they
indicate some conditions that results after an instruction is executed, these
four are:
CY(carry)
AC(auxiliary carry)
P(parity) and
OV(overflow)
The bit 3 and bit 4 are designated as RS0 and RS1 which are
register selection bit and are used to select the bank register
PSW (Program Status Word)
CY AC F0 RS1 RS0 OV - P
D7/PSW7 D6/PSW6 D5/PSW5 D4/PSW4 D3/PSW3 D2/PSW2 D1/PSW1 D0/PSW0
CY AC F0 RS1 RS0 OV - P
D7 D6 D5 D4 D3 D2 D1 D0
P (parity flag)
The parity flag reflects the number of 1's in the A (accumulator) register
If the A register contains an odd number of 1's then Parity flag will be 1 and
it will be 0 if there is even numbers of 1’s
MOV A, #9CH
ADD A, #64H
MOV A, #BFH
ADD A, #2AH
MEMORY ORGANIZATION OF 8051
MEMORY ORGANIZATION OF 8051
The 8051 Microcontroller Memory is
divided into
Program Memory (ROM)
Data Memory (RAM)
The internal ROM of 8051 is 4K and the
internal RAM is 128B
The Program Memory of the 8051
Microcontroller is used for storing the
program to be executed i.e.,
instructions
The Data Memory on the other hand, is If the internal memory is inadequate,
used for storing temporary variable you can add external memory using
data and intermediate results suitable circuits
Program Memory (ROM)
0FFFH
Internal
• For this scenario, the EA Pin Program
Memory
must be connected to GND. In 4K (ROM)
this case, the memory 0000H
addresses of the external ROM
will be from 0000H to FFFFH.
Data Memory (RAM) of 8051 Microcontroller
The Data Memory or RAM of the 8051
Microcontroller stores temporary data and
intermediate results that are generated and used
during the operation of the microcontroller. Original
Intel’s 8051 Microcontroller had 128B of internal
RAM.
In some microcontrollers,
there is an additional 128B of
RAM, which share the
memory address with SFRs
i.e., 80H to FFH. But, this
additional RAM block is only
accessed by indirect
addressing
Data Memory (RAM) of 8051 Microcontroller
The CPU can access data in various way. The data could be
In a Register or
In a Memory location or
Be provided as an immediate value
This various way of addressing data is called addressing modes
Addressing Modes of 8051
The source data is a constant, immediate data and it can be 8-bit or16 bit
The operant comes immediately after the opcode
The operant (source data)must be preceeded by pound symbol “#”
This addressing mode is used to load information into any of the
registers including DPTR
Format: MOV, # Data
Immediate Addressing Mode
Some of the example of immediate addressing modes are
MOV A,#55H
MOV R1,#10H
MOV P1,#FFH
MOV DPTR,#4567H
Although DPTR is 16 bit register, but it can also be accessed by two 8 bit
register as DPH and DPL
• However, if the data is larger than register size then that will be
an invalid instruction, and will show as an error.
• For example
MOV A, #345H or
MOV DPTR, #32875H
Register Addressing Mode
For example,
MOV R1, R5; this is an invalid instruction
Direct Addressing Mode
This mode is used to access the internal memory of the microcontroller 8051.
In this mode address of the data is directly given in the instruction
Using this mode any register can be accessed such as general purpose,
SFRs, I/O ports etc
MOV A,30H
MOV 80H,B
MOV 45H,50H
Only this addressing mode is allowed for PUSHing and POPing the
data on stack
Indirect Addressing Mode
• MOVC A, @A+DPTR
• MOVC A, @A+PC
Implied Addressing Mode
• SWAP
• RLA
• RR
Instruction set of 8051
Instructions are command which are used to perform any specific task.
A group of instruction is called instruction set and
A set of instructions is called program
Instructions written in a program instruct microprocessor/microcontroller
which operation is to be performed.
The syntax of an instruction is
MOV A, R1
ADD A, #32H
Instruction set of 8051
• Data transfer,
• Arithmetic and logical operations,
• Program control, and I/O operations.
Instruction set of 8051
The instruction set of the 8051 Microcontroller includes a range of
instructions, including load and store instructions, arithmetic and
logical instructions, jump and call instructions, and I/O instructions.
Load and store instructions are used for transferring data between the
microcontroller’s internal registers and external memory
Instruction set of 8051
Jump and call instructions are used for controlling program flow by
jumping to specific locations in the program memory.
I/O instructions are used for controlling input and output operations to
and from the microcontroller.
Types of Instruction in 8051
This type of instruction is used only to transfer/mov data from one location
to other location
Using this instruction we do not perform add/ sub/ mod of any data
• JUMP
• CALL
• RETURN
Branching Instruction
• JUMP instruction permenently change the program counter or PC loaded with new
address of memory location and execute the subroutine and it don’t come back again
• The call instruction is used to transfer the control from the presently executing program
code to the subroutine,