The 8051 microcontroller family

Introduction

Early in the life-cycle of most embedded projects, an initial choice of microcontroller must be made. While it may become necessary to change the microcontroller as the project develops, the particular hardware platform that is used will have a substantial impact on many later software and hardware design decisions and development costs can be substantially reduced if subsequent changes can be avoided.

In this chapter, three patterns are presented to support this selection process:

Designing embedded systems-0073

Note that using any processor family requires a considerable investment in hard- ware, software and staff training: few firms can afford to select devices on a per-project basis: instead, they tend to specialize in a single family or a small number of families. As we will see, the huge – and growing – range of 8051 devices available can make it an excellent choice for a wide range of projects and, as a result, can frequently justify this investment.

STANDARD 8051

Context

You are developing a microcontroller-based embedded application and have some flexibility in the choice of hardware platform to be used.

Problem

Should you base your application on a standard 8051-family microcontroller?

Background

Taken as a whole, the 8051 family has what is, in the semiconductor world, a very long history. The underlying architecture is derived from that of the Intel 8048 micro- controller (introduced in 1976): the first 8051 was introduced in 1980 (Intel, 1985).

The original 8051 architecture had the following features:

● Up to 12 MHz operating frequency.

● Thirty-two digital input / output pins (arranged as four 8-bit ports).

● Internal data (RAM) memory – 128 bytes.

● Three versions with different program memory options:

– No program memory: all programs needed to be stored in external memory (8031)

– 4K × 8 bits internal mask-programmed ROM (8051)

– 4K × 8 bits UV-eraseable EPROM (8751)

● Two 16-bit timer / counters (Timer 0 and Timer 1).

● Five interrupt sources were provided (two external) with two priority levels.

● One programmable, full-duplex, serial port.

The external interface to the 8051 is illustrated in Figure 3.1.

Shortly after the launch of the 8051, the 8052 was launched (again by Intel). The 8052 differed in several important respects from the earlier device. The 8052 had the following features:

● Internal data (RAM) memory was increased to 256 bytes.

● Two 8052 versions were available with different program memory options:

– No program memory: all programs needed to be stored in external memory (8032)

– 8K × 8 bits internal mask-programmed ROM (8052)

● Three 16-bit timer / counters (Timer 0, Timer 1 and Timer 2).

● Six interrupt sources were provided (two external) with two priority levels.

The 8051 microcontroller family-0074

[Note: that many of the digital I/O pins have alternative functions: for example, in applications involving a UART-based serial interface, Pins 3.0 and 3.1 are used (see Chapter 18). Note also that the alternative functions on pins 1.0 and 1.1 are only provided on 8052- based derivatives.]

The 8052 added useful features to the basic architecture, particularly the additional RAM and ‘Timer 2’. It was also ‘upwardly compatible’ with the 8051: that is, it was pin, and code compatible with the 8051. Because of this, in almost all cases, modern ‘standard’ 8051 devices are based on the 8052 family. Within this text, we will con- sider ‘Standard 8051’ devices to be those which are pin and code compatible with either the 8051 or (more commonly) the 8052 device.

The popular Atmel 89S53 is a representative example of a modern Standard 8051. Listed here is a summary of the main features of the AT89S53:

● Fully static operation: 0–24 MHz operating frequency.

● Thirty-two input / output lines (arranged as four 8-bit ports).

● Internal data (RAM) memory – 256 bytes.

● 12 Kbytes of ‘in circuit programmable’ ROM.

● Three 16-bit timers / counters (Timer 2 with up/down counter feature).

● Nine interrupts (two external) with two priority levels.

● Programmable watchdog timer (see Chapter 12).

● SPI interface (see Chapter 24).

● Low-power idle and power-down modes.

● 4V to 6V operating range.

clip_image005Modern Standard 8051 devices like the AT89S53 are now generally packaged in 40- pin DIP, 44-pin PLCC or 44-pin MQFP cases. Examples of each type of package are shown in Figure 3.2.

The 8051 microcontroller family-0075

What’s in a name?

It should be noted that the naming of various members of the ‘8051’ family is a source of considerable confusion to new developers. For example, the 8031, 8751, 8052, 8032, C505c, C515, C509, 80C517, 83C452, ADµC812, and the 80C390 are all members of the 8051 family. The names of the devices provide little or no indica- tion of the family connections.

Originally, there were some basic conventions used to identify the features of differ- ent variants of a particular 8051 device. For example, the standard 8051 had mask ROM, the 8031 had no ROM and the 8751 had UV-erasable ROM memory. This basic convention is now rarely observed. In the case of the Infineon C501, for example, dif- ferent suffixes are used to distinguish different C501 versions: C501-1R, C501-1E, and so on.

Solution

The aim of this pattern is to help you decide whether you should use a Standard 8051 in your application. When making such a decision, some or all of the following ques- tions need to be addressed:

1 Is the microcontroller powerful enough to perform the required tasks?

2 Does the microcontroller have sufficient memory ‘on chip’ to store the required code and data? If not, then does the microcontroller allow the use of appropriate external memory?

3 Does the microcontroller have appropriate on-chip hardware components (for example, CAN interface, PWM interface) to support the required tasks?

4 Does the microcontroller have sufficient port pins (or a suitable serial interface) to allow any required external components (such as switches, keypads, LCD displays) to be connected?

5 Is the power consumption of the chosen microcontroller appropriate (a particular concern with battery powered applications)?

We will consider each of these points in turn here.

Performance issues

One of the first question to be asked when considering a microcontroller for a project is whether it has the required level of performance. There are various ways in which such performance may be described: one measure is the number of machine instruc- tions that may be executed in one second, usually expressed in MIPS (million instructions per second).

For example, in an original Intel 8051 microcontroller (and most current members of the 8051 family), a minimum of 12 oscillator cycles are required to execute a machine instruction. As a result, at best, a 12 MHz 8051 has a performance of approximately 1 MIP.

A simple way of improving this performance is to increase the clock frequency. More modern (Standard) 8051 devices allow the use of clock speeds well beyond the 12 MHz limit of the original devices. For example, the Infineon C501 allows clock speeds up to 40 MHz: this raises the performance to around 3 MIPS.

Another way of improving the performance is to make internal changes to the microcontroller so that fewer oscillator cycles are required to execute each machine instruction. The Dallas ‘high speed microcontroller’ devices (87C520 and similar) use this approach, so that only four oscillator cycles are required to execute a machine instruction. These Dallas devices also allow faster clock rates: typically up to 33 MHz. Combined, these changes give a total performance of around 6 MIPS. Similar changes are made in members of the Winbond family of Standard 8051 devices (see the Winbond W77E58, for example) resulting in performance figures of up to 10 MIPS.

Clearly, for maximum performance, we would like to execute instructions at a rate of one machine instruction per oscillator cycle. The Dallas ‘ultra high speed’ 89C420 is the first 8051 device to achieve this: as a result, it runs at 12 times the speed of the original 8051. In addition, the 89C420 can operate at up to 50 MHz, increasing over- all performance to around 40–50 MIPS.

To put these figures in context, the popular Infineon C167 family of (16-bit) microcon- trollers has a modern architecture and performance level of around 10 MIPS. Clearly, therefore, in microcontroller terms, the performance of many 8051 devices is respectable.

Memory issues

The second question you need to ask is whether the microcontroller you are consider- ing supports the memory that your application requires.

The 8051 microcontroller family-0076

The first thing to note is that, for the Standard 8051, a maximum program size of 64 kbytes is directly supported. While it is possible to use larger programs by ‘bank switching’ the memory (a techniques considered in OFF - CHIP CODE MEMOR Y [page 100]) this technique is complex, less efficient than a linear address space, and can be error prone. Similarly, the memory available for data is restricted to 64 kbytes. In situ- ations where code or data memory in excess of 64 kbytes is required, use of an EXTENDED 8051 [page 46] is often a better alternative.

The second thing to note is that Figure 3.3 shows the total memory (both internal and external) available on all Standard 8051 devices. Where possible, it is better to use a device with all the required memory on the chip, since this can improve reliability, reduce costs, reduce the application size and reduce power consumption. As discussed in ‘Background’, the original 8051 family had up to 128 bytes of RAM and 4 kbytes of ROM available, from data and code (respectively). More modern Standard 8051s rarely provide more than around 1 kbyte of RAM (usually 256 bytes), but may provide up to 64 kbytes of flash, OTP or mask ROM (see Chapter 6 for further details).

Availability of on-chip hardware components

One of the main reasons for choosing to use a microcontroller is that it integrates most or all of the hardware features you require in your application on a single chip. The 8051 family is particularly impressive in this area. There are numerous variants available which between them meet the needs of a huge number of projects, without having to resort to using large numbers of external components.

Some of the on-chip hardware components available on Standard 8051s are as follows:

● All Standard 8051s have at least one serial port available, supporting RS-232 serial protocols. This makes it easy, for example, to download data to a desktop PC. We discuss the linking of embedded and desktop systems in Chapter 18.

● All Standard 8051s have two or three timers.

● Many Standard 8051s have on-chip ‘watchdog timers’. Use of such components is discussed in Chapter 12.

● Some Standard 8051s have on-chip support for the SPI bus. We discuss this impor- tant serial bus protocol in Chapter 23.

● Some Standard 8051s have on-chip support for the I2C bus. We discuss this important serial bus protocol in Chapter 24.

Note that many more features are available in the EXTENDED 8051 [page 46] devices.

Despite this variation, the core architecture remains the same and software for one variant can generally be used without major alteration on another.

Pin count

All Standard 8051s have four 8-bit ports available, allowing a number of external devices to be added.

Please note:

● Port 0, Port 2 and part of Port 3 are required to support external memory (if used).

Use of external memory therefore has a dramatic impact on the number of spare port pins (see Chapter 6 for details).

● The availability of new ‘serial bus’ standards, like I2C and SPI (see Chapter 23 and Chapter 24), means that many peripherals may be connected to a device, by shar- ing a bus requiring a small number of port pins.

Power consumption

All modern implementations of Standard 8051s have at least three operating modes:

● Normal mode

● Idle mode

● Power-down mode

The ‘idle’ and ‘power-down’ modes are intended to be used to save power at times when no processing is required. Typical current requirements for the various modes are shown in Table 3.1.

The 8051 microcontroller family-0077

The Infineon C501 is an example of a Standard 8051 device, which offers power- down modes identical to those available in the 8052 and many other modern devices. The following description of the C501 idle modes, adapted from the user manual, describes these modes in detail. Please note that this description applies equally well to most Standard 8051s.

Idle mode

In the idle mode the oscillator of the C501 continues to run, but the CPU is gated off from the clock signal. However, the interrupt system, the serial port and all timers are connected to the clock. The CPU status is preserved in its entirety.

The reduction of power consumption which can be achieved by this feature depends on the number of peripherals running. If all timers are stopped and the serial interfaces are not running, the maximum power reduction can be achieved: the devel- oper has to determine which peripheral must continue to run and which may be stopped.

The idle mode is entered by setting the flag bit IDLE (PCON.0). Because PCON is not a bit-addressable register, the easiest way to set the IDLE bit is with the following ‘C’ statement:

PCON |= 0x01; // Enter idle mode

The instruction that sets bit IDLE is the last instruction executed before going into idle mode.

There are two ways to terminate idle mode:

● Activate any enabled interrupt. This interrupt will be serviced and the program will continue by executing the instruction following the instruction that sets the IDLE bit.

● Perform a hardware reset.

Power-down mode

In the power-down mode, the on-chip oscillator is stopped. Therefore all functions are stopped; only the contents of the on-chip RAM are maintained.

The power-down mode is entered by setting the flag bit PDE (PCON.1). This is most easily done in ‘C’ as follows:

PCON |= 0x02; // Enter power down mode

The instruction that sets bit PDE is the last instruction executed before going into power down mode. The only exit from power-down mode is a hardware reset.

Hardware resource implications

To summarize, the Standard 8051 provides the following hardware resources:

● A CPU performance of between 1 MIPS and 50 MIPS (approximately).

● Available on-chip memory of up to 64 kbytes for code and (typically) at least 256 bytes for data.

● One ‘RS-232’ serial port.

● Two or three hardware timers.

● Current consumption of around 20 mA in normal operating mode, 5 mA in idle mode, and 50 µA in power-down mode.

Reliability and safety implications

There are no available figures to suggest that the Standard 8051 is any more (or less) reliable than any other microcontroller family. Nonetheless, there are differences

between the facilities provided by the various 8051 family members and the choice of an inappropriate microcontroller can have a detrimental impact on the safety and / or reliability of your application.

These differences arise simply due to the availability of on-chip resources: as we have mentioned, these include – for example – different amounts of memory (RAM and ROM), serial interfaces (SPI and I2C) and analog-to-digital converters. Where pos- sible, the use of on-chip components generally increases application reliability, for the following reasons:

● With external components, each of the soldered joints has a risk of failure, particu- larly in the presence of vibration and / or high humidity: reducing the number of joints reduces this risk.

● External wires act as miniature aerials and increase vulnerability to electromagnetic interference (EMI): as a consequence reduction in external wiring tends to make the application more robust in the presence EMI.

● Without external components, the complexity of the hardware design is reduced, which means there are fewer opportunities for wiring and / or hardware design errors,

As (in almost all cases) the ‘on-chip’ solution will also be both cheaper to produce and physically smaller, the message is clear: you should generally use a microcon- troller with all the on-chip resources you require if at all possible. Note, however, that use of less common on-chip resources will make your design less portable (see next section).

Portability

Because of the huge range of different 8051 devices available, design based on the Standard 8051 are inherently portable. However, if you assume the availability of non-standard components (extra RAM, extra serial interfaces etc.), your design will not be as portable.

Overall strengths and weaknesses

To summarize, the Standard 8051 has the following strengths and weaknesses:

It is a flexible, general-purpose microcontroller suitable for use in many projects. It is a low-cost device.

It has an architecture with which many developers are familiar. It is supported by many development tools.

The family as a whole is available in more than 300 different forms.

It is available from a very wide range of different manufacturers: if one com- pany fails, there will be an alternative source.

Its CPU performance (in some versions) is equal to or greater than many 16-bit devices.

It has limited memory available (compared with 16-bit or 32-bit microcon- trollers).

Its memory architecture is comparatively complex.

Related patterns and alternative solutions

In this section, we consider some alternatives to the Standard 8051 microcontroller.

Smaller alternatives

If your application does not require external memory and you do not require more than (approximately) 15 port pins for input and output, you may find that the Small 8051s are a good option: see SMALL 8051 [page 41].

Extended 8051 alternatives

The Extended 8051s can generally do everything that the Standard 8051 can do. In addition, they usually have a larger number of available port pins and a wider range of on-chip hardware components such as digital-to-analog converters, CAN interfaces, SPI interfaces, I2C interfaces and so on. The Extended 8051s also, in some cases, provide support for large amounts of external memory: up to 16 Mbytes in some cases.

We discuss such devices in EXTENDED 8051 [page 46].

The Intel 80251 family

The Intel MCS-251 is both software and hardware compatible with the Standard 8051 family. This means that, in most cases, you can load your existing code into a 251 and place this (40-pin or 44-pin) device into your existing 8051-based circuit board.

It is claimed that performance can be improved by a factor of 5–15 times by this approach (compared with the original 1-MIP 8051) and that further improve- ments are possible by recompiling and / or rewriting code to take advantage of the new architecture.

To summarize, the key features of the 251 are:

● Software and hardware compatibility with the Standard 8051.

● 5–15 × the performance of the original 8051.

● Large (up to 16 Mbyte) linear address space.

● Additional on-chip RAM compared with the Standard 8051 (up to 1 kbyte).

● Other additional components, such as a watchdog timer and a PWM unit.

● Two serial ports in some versions.

Overall, the main advantage of the 251 family is that can provide a more powerful, drop-in replacement for the original 8051 and that it may be used without purchasing additional tools (such as compilers). However, the 251 family has not proved nearly as popular as the 8051 and it offers little that Standard and Extended 8051 devices cannot now provide.

If you wish to find out more about the 251 family, then Ayala (2000) may be of interest.

Example: Using the Standard 8051

We give many examples of the use of Standard 8051 devices throughout this book.

Further reading

A collection of data books for a range of Standard 8051 devices is included on the CD-ROM.