What is a microcontroller?

A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. A typical microcontroller includes a processor, memory and input/output (I/O) peripherals on a single chip.

Sometimes referred to as an embedded controller or microcontroller unit (MCU), microcontrollers are found in vehicles, robots, office machines, medical devices, mobile radio transceivers, vending machines and home appliances, among other devices. They are essentially simple miniature personal computers (PCs) designed to control small features of a larger component, without a complex front-end operating system (OS).

Microcontroller memory

Memory of a microcontroller (or mostly any electronic device) is a physically built semiconductor capable of storing information in the form of bits (0s and 1s). 0s and 1s are actually voltage levels where in general 0s refer to 0V and 1s refer to 5V.
NOTE: Bits defined on voltge levels are not the same for all devices and may change.
Each device has a specific memory size. Let us consider a sample memory size M.

Buses are specific pathways for data to be stored into the devices' memory.
There are three types of buses:

Examples of calculating memory sizes based on Address Bus and Data Bus:

NOTE: The memory locations are displayed by hexadecimal numbers

  1. Suppose P = 4 and N = 8
    • Memory Size = 24 x 8 = 16 x 8 = 16 bytes
    • First Address = 00H
    • Last Address = 0FH
  2. Suppose P = 7 and N = 8
    • Memory Size = 27 x 8 = 128 x 8 = 128 bytes
    • First Address = 00H
    • Last Address = 7FH
  3. Suppose P = 10 and N = 8
    • Memory Size = 210 x 8 = 1024 x 8 = 1Kb
    • First Address = 00H
    • Last Address = 0FH
  4. Suppose P = 11 and N = 8
    • Memory Size = 211 x 8 = 2048 x 8 = 2Kb
    • First Address = 00H
    • Last Address = 0FH

Memory Size Table:

Assume N = 8
Sr No. P (Address Lines) Memory Size Address in HEX
1 10 210 = 1024 x 8 = 1KB 000H to 3FFH
2 11 211 = 2048 x 8 = 1KB 000H to 7FFH
3 12 212 = 4096 x 8 = 1KB 000H to FFFH
4 13 213 = 8192 x 8 = 1KB 0000H to 1FFFH
5 14 214 = 16384 x 8 = 1KB 0000H to 3FFFH
6 15 215 = 32768 x 8 = 1KB 0000H to 7FFFFH
7 16 216 = 65536 x 8 = 1KB 0000H to FFFFH
Features of 8051 microcontroller

In 1981, Intel corporation introduced an [8-bit microcontroller] called the 8051 microcontroller.

8051 microcontroller IC package
8051 microcontroller IC package

It is an 8- bit processor, means processor (CPU) can work on only 8 bits of a data at a time. Data larger than 8 bit has to be broken into 8 pieces to be processed by the CPU.

Block diagram of 8051 microcontroller

8051 Block Diagram
Block Diagram Of 8051 Microcontroller

The above figure shows internal block diagram of 8051. It consists of Central Processing Unit (CPU), two kinds of memory (1) DATA RAM and (2) Programmable ROM / EPROM; Input/output ports, mode status and data registers. These elements communicate through an eight-bit data bus which runs through the chip referred as internal data bus.

Program Status Word (PSW)
Bits of the PSW register
(MSB) (LSB)
CY AC F0 RS1 RS0 OV - P
Flags represented by the bits and their functions
Symbol Position Function
CY PSW.7 Carry Flag
AC ACPSW.6 Auxiliary Carry Flag. For BCD Operations
ACF0 ACPSW.5 Flag 0. Available to the user for general purposes
ACRS1 ACPSW.4 Register bank select bits. Set by software to determine which registers are being used
ACRS0 ACPSW.3
ACOV ACPSW.2 Overflow Flag
- ACPSW.1 Not used
ACP ACPSW.0 Partiy Flag. Even Parity

Basic information bout the PSW register

CY (Carry Flag):

AC (Auxiliary Flag):

P (Parity Flag):

OV (Overflow Flag):

RS1, RS0 (Register Selection Bank):

RS1 RS0 Register Bank Address
0 0 0 00H-07H
0 1 1 08H-0FH
1 0 2 10H-17H
1 1 3 18H-1FH

The remaining two bits are general purpose status flag bits and can be used by the programmer for any purpose. In other words, they are user defined bits.

Data Memory Oragnisation

128 byte memory

Divided into three sections

  1. Register Banks (32)
    • R0 to R31 (00H to 1FH)
  2. Bit Addressable RAM (16)
    • R32 to R47 (20H to 2FH)
  3. Scratch Pad RAM (80)
    • R48 to R127 (30H to 7FH)
8051 RAM Architecture
8051 RAM Architecture

RAM Allocation

These 128 bytes are divided into three groups:

  1. A total of 32 bytes from locations 00H to 1FH are set aside for register banks and the stack.
  2. 2A total of 16 bytes from locations 20H to 2FH are set aside for bit addressable read/write memory.
  3. Remaining locations 30Hfrom to 7FH are called as general-purpose RAM or scratch pad RAM.

Register bank in 8051 microcontrollers:

A total of 32 bytes of RAM are set aside for the register banks and stacks. These 32 bytes are divided into 4 banks of register in which each bank has 8-registers, R0 to R7. The above figure shows how the 32 bytes are allocated into 4 banks. From the above figure, bank 1 uses the same RAM space as the stack. This is a major problem in programming 8051. We must either not use register bank 1, or we must allocate another area of RAM for stack.

BIT addressable RAM

Out of the 128 bytes internal RAM of the 8051, 16 bytes of it are bit addressable.Each bit of sixteen bytes from 20H to 2FH has individual bit address.Bit address varies from 00H to 7FH as shown in the figure below.

BIT addressable RAM
BIT addressable RAM

The rest must be accessed in byte format.The bit addressable RAM locations are 20H to 2FH.These 16 bytes provide 128 bits of RAM, addressed as 0 to 127 (in decimal) or 00H to 7FH in hexadecimal.The internal RAM locations 20 H to 2FH are both byte addressable and also bit addressable.

Scratch Pad RAM

30H-7FH is available to the user as data RAM. However, if the data pointer has been initialized to this area, enough bytes should be left aside to prevent SP data destruction.

internal and external memory
Data internal and external memory

Special Function Registers (SFR):

SFR Memory Map
SFR memory map
SFR bit address
SFR bit address

Unlike other microprocessor in the Intel Family, 8051 uses memory mapped I/O through a set of Special Function Registers (SFRS). SFR are of 128 bytes and that are implemented in the address space immediately above the 128 bytes of RAM. Fig. 1.14 shows SFR starts from 80 H and ends at FFH.SFR is a bit addressable area. All access to the four I/O ports, the CPU, interrupt control register, the timer / counter, UART and power control are performed through Special Function Registers (SFR) between 80H and FFH.

Input / Output Ports

Timer

Serial interface

Interrupts

Input / Output Ports

Accumulator (A) and B registers

Stack Pointer (SP)

Data Pointer Register (DPTR)

Hex address of each register
8051 instructions part 1
8051 instructions part 2