View Course Path

8051 Architecture – In-depth explanation using old and modern variants

“It is not the strongest of the species that survives, nor the most intelligent, it is the one that is most adaptable that survives”- Charles Darwin.

You might be wondering why this guy is quoting Darwin before introducing the 8051 architecture? Well, simply because Darwin’s theory is also applicable here. If a particular device does not evolve with the constantly changing technological landscape, it dies. (Nokia, ahem)

Most of us think that the 8051 is an obsolete microcontroller, well that probably would have been the case if it had not evolved since its introduction in the 1980s. The 8051 microcontroller has seen a lot of upgrades in the past 40 years, which makes it a formidable (if not great) embedded development device even today. Just to give you an idea, microcontrollers with 8051 IP cores are used in tire pressure monitoring systems, managing TCP/IP stacks in routers and industrial control systems. Heck, some satellites currently in orbit are still using 8051 cores. Here’s an article we wrote to answer the common question of why is the 8051 still popular?

In this article, we will be talking about the architecture of the 8051 microcontroller (AT89C51-Atmel), which closely resembles the MCS-51 (The OG 8051) manufactured by Intel. We will also be talking about the architecture of another microcontroller, which uses the 8051 IP core (STC-15W4K32S4) and offers a ton of new features.

Block diagram for AT89C51-Atmel

8051 block diagram HD HQ-page-001

 

Most people think that learning and memorizing architecture is not good. But from my personal experience, knowing the architecture of a controller makes coding fun. I mean, learning the architecture of the controller helps you visualize your code better. As a beginner, understanding the architecture for 8051 can get a little overwhelming. So to make the entire process a little easy, we will break the architecture into small digestible bits.

Crystal Oscillator

The crystal oscillator is the heart of any microcontroller. It generates a master clock of a particular frequency which synchronizes and runs each element on the microcontroller. Using the inverse piezoelectric effect and a quartz crystal, the crystal oscillator generates a precise clock signal under various temperature conditions, making them ideal for microcontrollers. The crystal on the microcontroller can be changed, and the Atmel AT89C51 supports a maximum clock frequency of 24 MHz.

Note: Most of the 8051 microcontrollers use a clock frequency of 11.0592 MHz. But it takes a total of 12 such clock cycles to complete an instruction. The reason for this is that the CPU has to decode the opcode and then execute it. Both these operations take six clock cycles each, reducing the machine cycle to 1MHz (clock frequency/12). Modern 8051 variants can execute each instruction in 1 clock cycle.

Timing and control

The crystal oscillator connects to the timing and control block. This block is responsible for routing the clock signal to the components which need to be operated for the execution of a particular instruction. The instruction register is connected to the timing block because it stores the instruction which is executing currently and sends signals to the control block accordingly.

CPU

The CPU is the brains of any microcontroller. Apart from handling all the complex mathematical computations of any system, it is also responsible for fetching, decoding, and executing all instructions. This makes the CPU a complicated block, and we will be going over the various components which comprise the CPU.

  • ALU– The ALU or the arithmetic-logic unit is responsible for performing all the logical and mathematical operations. Now, this ALU needs data for processing, which it gets from the two temporary registers connected to it.
  • Accumulator– The accumulator is a special register that connects to the ALU, and all the results of any computation performed in the CPU are stored there. There is another register know as the B register, which stores the results when the data is too large and cannot be stored in an 8-bit register. This happens during operations like multiplication and division.

Buses

The CPU needs to get data from particular addresses in the RAM. The 8051 has two sets of busses which help in getting data from the RAM. These busses are namely the address bus and data bus. Note: The 8051 has a 16-bit address bus and an 8-bit data bus. As it has a 16-bit address bus, it can address up to 2^16 locations, which are 64 KB of addresses.

Flash Memory

The 8051 uses Harvard architecture. Due to which it has two different memory elements: Flash (ROM) and RAM. Flash memory is where all your program code gets stored and tells the microcontroller what to do. The Atmel AT89C51  comes with a 4KB EEPROM, whereas the MCS-51 used an on-chip PROM. The upgrade of using flash on AT89C51 made it extremely popular as it allowed the developer to reprogram the microcontroller. Some of you might be wondering that if the 8051 has a 16-bit address bus, so it can access 64KB locations. But the flash memory is only 4kb. Where is the rest of the addressable memory? Well, to answer that question, the 8051 can interface with additional external memory using Port 0 on the microcontroller.

RAM

The flash memory, as explained earlier, has the program code. The RAM, on the other hand, has registers that are responsible for storing results that might be needed later during the execution of the program. It includes the various register banks, special function registers (SFRs), and free memory space to keep data. The 8051 has a 128 byte RAM space and can be upgraded by using an external RAM. To make you familiar with the various special-function registers, we will be defining them in brief over here. We take a look at the SFRs of the 8051 in detail over here.

  • Program Status Word (PSW)– Manages the various mathematical overheads defined later in the article.
  • Power Control (PCON)– Selects various power saving modes of 8051.
  • Serial Control (SCON)– Offers controlling mechanisms for serial communication between various devices and the 8051.
  • Timer Control (TCON)– Controls the two timers on 8051.
  • Timer Mode (TMOD)– This SFR is used to select the mode of the timer.
  • Interrupt Priority (IP)– It is used to change the priority of various interrupts.
  • Interrupt enable (IE)– Used to enable the interrupts on 8051.

Note: the 8051 has independent address spaces for RAM and flash due to Harvard architecture.

Stack pointer 

A set of registers in the RAM form the stack. This stack of registers is used to store either data or addresses which are required during the execution of a program. To access the data in the stack, a special 8-bit register known as the stack pointer is used. When the microcontroller is powered up, the stack pointer points to the location 07H and grows upwards till the memory location 1FH. This provides a total of 24 bytes for the stack area. It uses special push and pop instructions to place and retrieve data stored in the stack respectively. If more memory space for the stack is required, it can be moved to the scratch-pad in the location 30H to 7FH. All of this might be a bit overwhelming for you at the moment, but don’t worry, we will be covering the entire RAM space in the next article, which will make things crystal clear.

Program status word (PSW)

It is a special function register (SFR) that is responsible for managing the various mathematical overheads like carries, auxiliary carries, and much more. Although the PSW register is 8-bit wide, only 6 bits are used by the 8051 microcontroller. The other two bits are user-definable and can be used according to the needs of the programmer.

The PSW register comprises four conditional flags, namely Carry (CY), auxiliary carry (AC), Parity (P), and Overflow (OV). Two bits in the PSW register are used to select the register bank in the RAM for storing data. By default, register bank 0 stores all the data. Note: the 8051 has four register banks containing eight registers each. The PSW register is bit addressable, which allows the programmer to access each bit individually.

psw_register

  • The 8051 microcontroller has an 8-bit architecture. Sometimes during mathematical operations, the ALU produces results greater than 8 bits. To show the programmer that the result is greater than 8 bits, the microcontroller changes the CY bit from 0 to 1.
  • The Auxilary Carry is another carry flag which helps in performing BCD addition. This flag is raised when there is a carry from D3 to D4.
  • Both PSW.5 and PSW.1 can be configured according to the needs of the programmer.
  • RS1 and RS0 are used to select a particular register bank in the RAM space.
  • The overflow flag is raised from 0 to 1 if there is an error in any mathematical calculation. Sometimes during subtraction operation, the result of the calculation is wrong, and to tell the programmer that the result is not correct, this flag is updated.
  • The parity flag is used as an even party for the accumulator. This bit is 1 if the number of 1’s in the accumulator is odd and 0 otherwise

DPTR

DPTR or the data pointer register, as the name suggests, is a register that points to some data. In any computer system, data is kept at a particular address, and the DPTR is responsible for storing the address. Due to the 16-bit address bus of the 8051 microcontroller, it has a 16-bit DPTR so that it can access all the data locations. It is divided into two parts, namely DPH(4 upper bits ) and DPL(4 lower bits).

I/O ports 

Every embedded system has the job of either monitoring a particular device or driving an actuator. To do this, it needs input-output ports. The 8051 has four ports, namely port 0, port 1, port two, and port 3. All these ports are 8-bit ports; this means is that each port has eight individual pins.

Program counter  

The program counter is a 16-bit register that is responsible for holding the address of the next instruction, which needs to be executed.

PC Incrementer

In any microcontroller, the program code is sequentially burned into the flash. So the PC Incrementer is responsible for increasing the address in the program counter register by one. This makes it a point to the next instruction, which needs to be executed.

Timers

Any electronic device needs to keep time to perform operations in an optimized manner. For this reason, the 8051 has two 16 bit timers, namely T0 and T1.

As mentioned earlier, the 8051 is still manufactured using the same IP cores. So now, we will be talking about the STMC15W4K32S4 to make you accustomed to the architecture of the microcontrollers currently in the market and to show you how much they have evolved over the years.

Difference between AT89C51 and STC15W4K32S4

stc-microcontroller_blockdiagram

  • For one, the STC15W4K32S4 is way faster compared to the older 8051 variants. As mentioned earlier, the 8051 has a machine cycle of 12 clocks making the processing slower. The newer counterpart is 12 times faster and can fetch, decode and execute operations in 1 clock period. The main reason for this high-speed processing is the pipelining of the microcontroller.
  • In terms of memory, it offers higher onboard RAM (4096 bytes) and up to 64KB ROM. This provides the programmer with extra pins as they do not need to interface memory hardware to run their programs. It also offers ISP and IAP, which makes programming the flash much easier.
  • Most of the data that needs to be extracted from the environment is in the form of analog data. As you might know, a microprocessor can only understand digital data. The STC15W4K32S4 has a 10-bit on-chip ADC, which converts analog signals into digital data.
  • It also has dual DPTR, which makes data transfer much faster and efficient.
  • It also offers six-channel PWM ports, which make controlling motors and other actuators very easy. These PWM ports can also be used and digital to analog converters.
  • An on-chip comparator makes comparing operations lightning fast.
  • It is also possible to alter the clock frequency of the internal clock between 5MHz and 35MHz.
  • The older 8051 microcontrollers have only one UART port, whereas the STC15W4K32S4 has 4 UART Ports.
  • STC15W4K32S4 offers seven timers and 26-64 input-output ports, allowing them to manage a ton of devices.
  • It also has a 15-bit watchdog timer, which will reset your microcontroller if it stops working correctly.
  • The SPI interface makes interfacing with other peripherals like shift registers and SD cards much easier.
  • It also offers a dedicated power-down timer, which helps save power when the microcontroller is idle.

We hope that reading this article has helped you understand the architecture of the 8051 microcontroller. If anything was not clear in the article feel free to ask in the comments and we will get back to you in a jiffy.

Leave a Reply

Your email address will not be published. Required fields are marked *