Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Class 03: 8051 Microcontroller Memory Organisation

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 7

Class 03: 8051

Microcontroller Memory
organisation
Memory Organisation
Data Memory
 Data Memory in a Microcontroller is responsible for storing values
of variables, temporary data, intermediate results and other data for
proper operation of the program.

 Data Memory is often called as RAM (Random Access Memory),


which is a type of volatile memory.

Program Memory

 The instructions of the CPU are stored in the Program Memory.

 It is usually implemented as Read Only Memory or ROM, where the


Program written in to it will be retained even when the power is
down or the system is reset.
Internal Data Memory (RAM) Organisation
 The Data Memory or RAM of the 8051
Microcontroller stores temporary data and
intermediate results that are generated and used during
the normal operation of the MC.
 Original Intel’s 8051 Microcontroller had 128B of
internal RAM.
 In the first 128B (32B) i.e. memory addresses from
00H to 7FH is divided in to Working Registers
(Scratch Pad Area) (organized as Register Banks), Bit – Addressable Area
and General Purpose RAM (also known as Scratchpad
area).

 But almost all modern variants of 8051 Microcontroller have 256B of RAM.
Register Bank Area
• In the first 128B of RAM (from 00H to 7FH), the
first 32B i.e. memory from addresses 00H to 1FH
consists of 32 Working Registers that are
organized as four banks with 8 Registers in each
Bank.
• But only one register bank can be used at any
(Stack)
point in time. To select the register bank, two bits
of PSW (Program Status Word) are used.
• Each Bank consists of 8 registers named as R0 –
R7. Each Register can be addressed in two ways:
either by name or by address.
How to Switch Register Banks

Register bank 0 is the default when the 8051 is powered up.


We can switch to the other banks using PSW register.
D4 and D3 bits of the PSW are used to select the desired register bank, since
they can be accessed by the bit addressable instructions SETB and CLR.
For example, "SETB PSW.3" will set PSW.3 = 1 and select the bank register 1.

PSW Register (all 8051 and 251 variants) RS10 RS21 Bank Selected
0 0 Bank0
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0
CY AC FO RS1 RS0 OV UD P 0 1 Bank1
1 0 Bank2
1 1 Bank3
Stack
• The stack is a section of RAM used by the
CPU to store information temporarily. This
information could be data or an address. The
CPU needs this storage area since there are
only a limited number of registers.
• Here the stack pointer (SP) is an only 8-bit
register, because the internal RAM area is only
in range 00H to 7FH, and when all register
banks are being used, the stack location will be
in range 30H to 7FH. So in such a case, the SP
will be initialized with 2FH.
How Stacks are Accessed

 The storing operation of a CPU register in the stack is known as a PUSH, and
getting the contents from the stack back into a CPU register is called a POP.
Pushing into the Stack
 In the 8051, the stack pointer (SP) points to the last used location of the stack.
When data is pushed onto the stack, the stack pointer (SP) is incremented by 1.
 When PUSH is executed, the contents of the register are saved on the stack and
SP is incremented by 1.
 To push the registers onto the stack, we must use their RAM addresses. For
example, the instruction "PUSH 1" pushes register R1 onto the stack.
Popping from the Stack
 Popping the contents of the stack back into a given register is the opposite to
the process of pushing. With every pop operation, the top byte of the stack is
copied to the register specified by the instruction and the stack pointer is

You might also like