Intel P8051microcontroller | |
| History | |
|---|---|
| Predecessor | Intel MCS-48 |
| Successor | Intel MCS-151 |
TheIntel MCS-51 (commonly termed8051) is a single-chipmicrocontroller (MCU) series developed byIntel in 1980 for use inembedded systems. The architect of the Intel MCS-51 instruction set wasJohn H. Wharton.[1][2] Intel's original versions were popular in the 1980s and early 1990s, and enhancedbinary compatible derivatives remain popular today. It is acomplex instruction set computer with separate memory spaces for program instructions and data.
Intel's original MCS-51 family was developed using N-type metal–oxide–semiconductor (NMOS) technology, like its predecessorIntel MCS-48, but later versions, identified by a letter C in their name (e.g., 80C51) use complementary metal–oxide–semiconductor (CMOS) technology and consume less power than their NMOS predecessors. This made them more suitable for battery-powered devices.
The family was continued in 1996 with the enhanced8-bit MCS-151 and the 8/16/32-bit MCS-251 family of binary compatible microcontrollers.[3] While Intel no longer manufactures the MCS-51, MCS-151 and MCS-251 family, enhanced binary compatible derivatives made by numerous vendors remain popular today. Some derivatives integrate adigital signal processor (DSP) or afloating-point unit (coprocessor, FPU). Beyond these physical devices, several companies also offer MCS-51 derivatives asIP cores for use infield-programmable gate array (FPGA) orapplication-specific integrated circuit (ASIC) designs.

The 8051 architecture provides many functions (central processing unit (CPU),random-access memory (RAM),read-only memory (ROM),input/output (I/O) ports, serial port,interrupt control,timers) in onepackage:
One feature of the 8051 core is the inclusion of a Boolean processing engine, which allowsbit-levelBoolean logic operations to be carried out directly and efficiently on select internalregisters, ports and selectRAM locations. Another feature is the inclusion of fourbank-selectable working register sets, which greatly reduce the time required to perform thecontext switches to enter and leaveinterrupt service routines. With one instruction, the 8051 can switch register banks, avoiding the time-consuming task of transferring the critical registers to RAM.
As of 2013[update], new derivatives are still being developed by many major chipmakers, and major compiler suppliers such asIAR Systems,Keil andTASKING[6] continuously release updates.
MCS-51-based microcontrollers typically include one or twoUARTs, two or three timers, 128 or 256 bytes of internal dataRAM (16 bytes of which are bit-addressable), up to 128 bytes ofI/O, 512 bytes to 64 KB of internal program memory, and sometimes a quantity of extended data RAM (ERAM) located in the external data space. External RAM and ROM share the data and address buses. The original 8051 core ran at 12 clock cycles per machine cycle, with most instructions executing in one or two machine cycles. With a 12 MHzclock frequency, the 8051 could thus execute 1 million one-cycle instructions per second or 500,000 two-cycle instructions per second. Enhanced 8051 cores are now commonly used which run at six, four, two, or even one clock per machine cycle (denoted "1T") and have clock frequencies of up to 100 MHz, thus being capable of an even greater number of instructions per second. AllSilicon Labs, someDallas (now part ofMaxim Integrated) and a fewAtmel (now part ofMicrochip) devices havesingle-cycle cores.[7][8][9]
8051 variants may include built-in reset timers withbrown-out detection, on-chip oscillators, self-programmableflash ROM program memory, built-in external RAM, extra internal program storage,bootloader code in ROM,EEPROM non-volatile data storage,I2C,SPI, andUSB host interfaces,CAN orLIN bus,Zigbee orBluetooth radio modules,PWM generators, analogcomparators,analog-to-digital anddigital-to-analog converters,RTCs, extra counters and timers, in-circuitdebugging facilities, more interrupt sources, extra power-saving modes, more or fewer parallel ports etc. Intel manufactured a mask-programmed version, 8052AH-BASIC, with aBASIC interpreter in ROM, capable of running user programs loaded into RAM.
MCS-51-based microcontrollers have been adapted to extreme environments. Examples for high-temperature variants are the Tekmos TK8H51 family for −40 °C to +250 °C[10] or theHoneywell HT83C51 for −55 °C to +225 °C (with operation for up to 1 year at +300 °C).[11]Radiation-hardenend MCS-51 microcontrollers for use in spacecraft are available; e.g., fromCobham (formerlyAeroflex) as the UT69RH051[12] or from NIIET as the 1830VE32 (Russian:1830ВЕ32).[13]
In some engineering schools, the 8051 microcontroller is used in introductory microcontroller courses.[14][15][16][17]
Intel's first MCS-51 microcontroller was the 8051, with 4 KB ROM and 128 byte RAM. Variants starting with 87 have a user-programmable EPROM, sometimes UV-erasable. Variants with a C as the third character are some kind ofCMOS. 8031 and 8032 are ROM-less versions, with 128 and 256 bytes of RAM. The last digit can indicate memory size, e.g. 8052 with 8 KB ROM, 87C54 16 KB EPROM, and 87C58 with 32 KB EPROM, all with 256-byte RAM.
The MCS-51 has four distinct types of memory: internal RAM, special function registers, program memory, and external data memory. To access these efficiently, some compilers[18] utilize as many as 7 types of memory definitions: internal RAM, single-bit access to internal RAM, special function registers, single-bit access to selected (divisible by 8) special function registers, program RAM, external RAM accessed using a register indirect access, using one of the standard 8-bit registers, and register indirect external RAM access utilizing the 16-bit indirect access register.
The 8051's instruction set is designed as aHarvard architecture with segregated memory (data and instructions); it can only execute code fetched from program memory and has no instructions to write to program memory. However, the bus leaving the IC has a single address and data path, and strongly resembles avon Neumann architecture bus.
Most 8051 systems respect the instruction set and require customized features to download new executable programs, e.g. in flash memory.
Internal RAM (IRAM) has an 8-bit address space, using addresses 0 through 0xFF. IRAM from 0x00 to 0x7F contains 128 directly addressable 1-byte registers, which can be accessed using an 8-bit absolute address that is part of the instruction. Alternatively, IRAM can be accessed indirectly: the address is loaded into R0 or R1, and the memory is accessed using the@R0 or@R1 syntax, or as stack memory through the stack pointer SP, with thePUSH/POP and*CALL/RET operations.
The original 8051 has only 128 bytes of IRAM. The 8052 added IRAM from 0x80 to 0xFF, which canonly be accessed indirectly (e.g. for use as stack space). Most 8051 clones also have a full 256 bytes of IRAM.
Direct accesses to the IRAM addresses 0x80–0xFF are, instead, mapped onto the special function registers (SFR), where the accumulators A, B, carry bit C, and other special registers for control, status, etc., are located.
Special function registers (SFR) are located in the same address space as IRAM, at addresses 0x80 to 0xFF, and are accessed directly using the same instructions as for the lower half of IRAM. They cannot be accessed indirectly via@R0 or@R1 or by the stack pointer SP; indirect access to those addresses will access the second half of IRAM instead.
The special function registers (SFR) include the accumulators A (or ACC, at E0) and B (at F0) and program status word (or PSW, at D0), themselves, as well as the 16-bit data pointer DPTR (at 82, as DPL and 83 as DPH). In addition to these, a small core of other special function registers – including the interrupt enable IE at A8 and interrupt priority IP at B8; the I/O ports P0 (80), P1 (90), P2 (A0), P3 (B0); the serial I/O control SCON (98) and buffer SBUF (99); the CPU/power control register PCON (87); and the registers for timers 0 and 1 control (TCON at 88) and operation mode (TMOD at 89), the 16-bit timer 0 (TL0 at 8A, TH0 at 8C) and timer 1 (TL1 at 8B, TH1 at 8D) – are present on all versions of the 8051. Other addresses are version-dependent; in particular, the registers of timer 2 for the 8052, the control register T2CON (at C8), the 16-bit capture/latch (RCAP2L at CA, RCAP2H at CB) and timer 2 (TL2 at CC and TH2 at CD) are not included with the 8051.
The 32 bytes in IRAM from 0x00 to 0x1F contain space for four 8-byteregister windows, which the eight registers R0–R7 map to. The currently active window is determined by a two-bit address contained in the program status word.
The 16 bytes (128 bits) at IRAM locations 0x20–0x2F contain space for 128 1-bit registers, which are separately addressable as bit registers 00–7F.
The remaining bit registers, addressed as 80–FF, are mapped onto the 16 special function registers 80, 88, 90, 98, ..., F0 and F8 (those whose addresses are multiples of 8), and therefore include the bits comprising the accumulators A, B and program status word PSW. The register window address, being bits 3 and 4 of the PSW, is itself addressable as bit registers D3 and D4 respectively; while the carry bit C (or CY), at bit 7 of the PSW, is addressable as bit register D7.
Program memory (PMEM, though less common in usage than IRAM and XRAM) is up to 64 KB of read-only memory, starting at address 0 in a separate address space. It may be on- or off-chip, depending on the particular model of chip being used. Program memory is read-only, though some variants of the 8051 use on-chip flash memory and provide a method of re-programming the memory in-system or in-application.
In addition to code, it is possible to store read-only data such aslookup tables in program memory, retrieved by theMOVCA,@A+DPTR orMOVCA,@A+PC instructions. The address is computed as the sum of the 8-bit accumulator and a 16-bit register (PC or DPTR).
Special jump and call instructions (AJMP andACALL) slightly reduce the size of code that accesses local (within the same 2 KB) program memory.[19]
When code larger than 64 KB is required, a common system makes the code bank-switched, with general-purpose I/O selecting the upper address bits. Some 8051 compilers[18] make provisions to automatically access paged code. In these systems, the interrupt vectors and paging table are placed in the first 32 KB of code and are always resident.
External data memory (XRAM) is a third address space, also starting at address 0, and allowing 16 bits of address space. It can also be on- or off-chip; what makes it "external" is that it must be accessed using theMOVX (move external) instruction. Many variants of the 8051 include the standard 256 bytes of IRAM plus a few kilobytes of XRAM on the chip.
The first 256 bytes of XRAM may be accessed using theMOVXA,@R0,MOVXA,@R1,MOVX@R0,A, andMOVX@R1,A instructions. The full 64 KB may be accessed usingMOVXA,@DPTR andMOVX@DPTR,A. The 16-bit address requires the programmer to load the 16-bit index register. For this reason, RAM accesses with 16-bit addresses are substantially slower.
Some CPUs[20] permit the 8-bit indirect address to use any 8-bit general-purpose register.
To permit the use of this feature, some 8051-compatible microcontrollers with internal RAM larger than 256 bytes, or an inability to access external RAM,[20] access internal RAM as if it were external and have a special function register (e.g. PDATA) that permits them to set the upper address of the 256-byte page. This emulates the MCS8051 mode that can page the upper byte of a RAM address by setting the general-purpose I/O pins.
When RAM larger than 64 KB is required, a common system makes the RAM bank-switched, with general-purpose I/O selecting the upper address bits. Some 8051 compilers[18] make provisions to automatically access paged data.
The only register on an 8051 that is not memory-mapped is the 16-bit program counter (PC). This specifies the address of the next instruction to execute. Relative branch instructions supply an 8-bit signed offset which is added to the PC.
Eight general-purpose registers R0–R7 may be accessed with instructions one byte shorter than others. They are mapped to IRAM between 0x00 and 0x1F. Only eight bytes of that range are used at any given time, determined by the two bank-select bits in the PSW.
The following is a partial list of the 8051's registers, which are memory-mapped into the special function register space:
256 single bits are directly addressable. These are the 16 IRAM locations from 0x20–0x2F, and the 16 special function registers 0x80, 0x88, 0x90, ..., 0xF8. Any bit of these bytes may be directly accessed by a variety of logical operations and conditional branches.
Note that the PSW does not contain the commonnegative (N), orzero (Z) flags. For the former, the most significant bit of the accumulator can be addressed directly, as it is a bit-addressable SFR. For the latter, there are explicit instructions to jump on whether or not the accumulator is zero. There is also a two-operand compare and jump operation.
The parity (P) bit is often used to implement serial modes that include parity. To support this, the standard MCS51UARTs could send 9 bits.
The microarchitecture of the Intel MCS8051 is proprietary, but published[21] features suggest how it works. It is amulti-cycle processor. The MCS8051 used 12 clock cycles[21] for most instructions. Many instructions utilize an accumulator.[21] In contrast, most compatible computers execute instructions in one to three cycles, except for the multiply and divide instructions. The much higher speed is a major reason why these have replaced the MCS8051 in most applications.
Each interrupt has four priorities.[21] Within each priority, the interrupts of devices are in a fixed priority.[21]
Instructions are all 1 to 3 bytes long, consisting of an initial opcode byte, followed by up to 2 bytes of operands.
1⁄4 of the opcode bytes,x0–x3, are used for irregular opcodes.
3⁄4 of the opcode bytes,x4–xF, are assigned to 16 basic ALU instructions with 12 possible operands. The least significantnibble of the opcode selects the primary operand as follows:
INCoperand,DECoperand)or the operation already includes an immediate source (MOVoperand,#data,CJNEoperand,#data,offset), this instead specifies that the accumulator is used.The most significant nibble specifies the operation as follows. Not all support all addressing modes; the immediate mode in particular is unavailable when the primary operand is written to. Instruction mnemonics usedestination,source operand order.
INCoperandINCA.DECoperandDECA.ADDA,operandRLA, "rotate left" but actually ashift left) may be thought of asADDA,A.ADDCA,operandRLCA, rotate left through carry) may be thought of asADDCA,A.ORLA,operandORLaddress,#data andORLaddress,A, are specified by opcodes 0x43 and 0x42.ANLA,operandANLaddress,#data andANLaddress,A, are specified by opcodes 0x53 and 0x52.XRLA,operandXRLaddress,#data andXRLaddress,A, are specified by opcodes 0x63 and 0x62.MOVoperand,#dataMOVA,#data.MOVaddress,operandSUBBA,operandMOVoperand,addressCJNEoperand,#data,offset#data, and jump toPC +offset if not equal. Immediate and memory direct modes (opcodes 0xB4 and 0xB5) compare the operand against the accumulator,CJNEA,operand,offset. Note that there is no compare and jump if equal instruction,CJE.XCHA,operandDJNZoperand,offsetMOVA,operandMOVoperand,AOnly theADD,ADDC, andSUBB instructions set PSW flags. TheINC,DEC, and logical instructions do not. TheCJNE instruction modifies the C bit only, to the borrow that results fromoperand1 −operand2.
The irregular instructions comprise 64 opcodes, having more limited addressing modes, plus several opcodes scavenged from inapplicable modes in the regular instructions.
| Opcode | x0 | x1 | x2 | x3 | x4 |
|---|---|---|---|---|---|
| 0y | NOP |
| LJMPaddr16 | RRA (rotate right) | INCA |
| 1y | JBCbit,offset (jump if bit set with clear) | LCALLaddr16 | RRCA (rotate right through carry) | DECA | |
| 2y | JBbit,offset (jump if bit set) | RET | RLA (rotate left) | ADDA,#data | |
| 3y | JNBbit,offset (jump if bit clear) | RETI | RLCA (rotate left through carry) | ADDCA,#data | |
| 4y | JCoffset (jump if carry set) | ORLaddress,A | ORLaddress,#data | ORLA,#data | |
| 5y | JNCoffset (jump if carry clear) | ANLaddress,A | ANLaddress,#data | ANLA,#data | |
| 6y | JZoffset (jump if zero) | XRLaddress,A | XRLaddress,#data | XRLA,#data | |
| 7y | JNZoffset (jump if non-zero) | ORLC,bit | JMP@A+DPTR | MOVA,#data | |
| 8y | SJMPoffset (short jump) | ANLC,bit | MOVCA,@A+PC | DIVAB | |
| 9y | MOVDPTR,#data16 | MOVbit,C | MOVCA,@A+DPTR | SUBBA,#data | |
| Ay | ORLC,/bit | MOVC,bit | INCDPTR | MULAB | |
| By | ANLC,/bit | CPLbit | CPLC | CJNEA,#data,offset | |
| Cy | PUSHaddress | CLRbit | CLRC | SWAPA | |
| Dy | POPaddress | SETBbit | SETBC | DAA (decimal adjust) | |
| Ey | MOVXA,@DPTR | MOVXA,@R0 | MOVXA,@R1 | CLRA | |
| Fy | MOVX@DPTR,A | MOVX@R0,A | MOVX@R1,A | CPLA |
MOVaddress,address move directly between two IRAM or SFR registers.CJNEA,address,offset compare accumulator to an IRAM or SFR register, and jump toPC +offset if not equal.XCHDA,@R0–1 exchange low-order nibble of operands.TheSJMP (short jump) opcode takes a signed relative offset byte operand and transfers control there relative to the address of the following instruction. TheAJMP/ACALL opcodes combine the three most significant bits of the opcode byte with the following byte to specify an 11-bit destination that is used to replace 11 bottom bits of the PC register (top 5 bits of PC register remain intact). For larger addresses, theLJMP andLCALL instructions allow a 16-bit destination.
One of the reasons for the 8051's popularity is its range of operations on single bits. Bits are always specified by absolute addresses; there is no register-indirect or indexed addressing. Instructions that operate on single bits are:
SETBbit,CLRbit,CPLbit: Set, clear, or complement the specified bitJBbit,offset: Jump if bit setJNBbit,offset: Jump if bit clearJBCbit,offset: Jump if bit set, and clear bitMOVC,bit,MOVbit,C: Move the specified bit to the carry bit, or vice versaORLC,bit,ORLC,/bit: Or the bit (or its complement) to the carry bitANLC,bit,ANLC,/bit: And the bit (or its complement) to the carry bitA bit operand is written in the formaddress.number. Because the carry flag is bit 7 of the bit-addressable program status word, theSETBC,CLRC andCPLC instructions are shorter equivalents toSETBPSW.7,CLRPSW.7 andCPLPSW.7.
There are varioushigh-level programming language compilers for the 8051. SeveralC compilers are available for the 8051, most of which allow the programmer to specify where each variable should be stored in its six types of memory, and provide access to 8051-specific hardware features such as the multiple register banks and bit manipulation instructions. There are many commercial C compilers.[22]Small Device C Compiler (SDCC) is a popular open-source C compiler.[23]Other high level languages such asC++,Forth,[24][25][26][27]BASIC,Object Pascal,Pascal,PL/M andModula-2 are available for the 8051, but they are less widely used[28] than C andassembly.
Because IRAM, XRAM, and PMEM (read only) all have an address 0, C compilers for the 8051 architecture provide compiler-specificpragmas or other extensions to indicate where a particular piece of data should be stored (i.e. constants in PMEM or variables needing fast access in IRAM). Since data could be in one of three memory spaces, a mechanism is usually provided to allow determining to which memory a pointer refers, either by constraining the pointer type to include the memory space or by storing metadata with the pointer.


Intel discontinued its MCS-51 product line in March 2007;[29][30] however, there are plenty of enhanced 8051 products orsilicon intellectual property added regularly from other vendors.
The 8051's predecessor, the8048, was used in the keyboard of the firstIBM PC, where it converted keypresses into the serial data stream which is sent to the main unit of the computer. An Intel 8049 served a similar role in theSinclair QL. The 8048 and derivatives are still used today[update] for basic model keyboards.
The8031 was a reduced version of the original 8051 that had no internal program ROM. To use this chip, external ROM had to be added containing the program that the 8031 would fetch and execute. An 8051 chip could be sold as a ROM-less 8031, as the 8051's internal ROM is disabled by the normal state of the EA pin in an 8031-based design. A vendor might sell an 8051 as an 8031 for any number of reasons, such as faulty code in the 8051's ROM, or simply an oversupply of 8051s and undersupply of 8031s.

The8044 (as well as the ROM-less 8344 and the 8744 with EPROM) added anSDLC controller to the 8051 core (especially forBitbus applications).[31]
The8052 was an enhanced version of the original 8051 that featured 256 bytes of internal RAM instead of 128 bytes, 8 KB of ROM instead of 4 KB, and a third 16-bit timer. Most modern 8051-compatible microcontrollers include these features.
The8032 had these same features as the 8052 except it lacked internal ROM program memory.
The8751 was an 8051 with 4 KB EPROM instead of 4 KB ROM. They were identical except for the non-volatile memory type. This part was available in a ceramic package with a clearquartz window over the top of the die soUV light could be used to erase theEPROM. Related parts are: 8752 had 8 KB EPROM, 8754 had 16 KB EPROM, 8758 had 32 KB EPROM.
The80C537 (ROM-less) and80C517 (8 KB ROM) areCMOS versions, designed for theautomotive industry. Enhancements mostly include new and enhanced peripherals. The 80C5x7 has fail-safe mechanisms, analog signal processing facilities, enhanced timer capabilities, and a 32-bit arithmetic peripheral. Other features include:
More than 20 independent manufacturers produce MCS-51 compatible processors.[citation needed]
Other ICs or IPs compatible with the MCS-51 have been developed byAnalog Devices,[32] IntegralMinsk,[33]KristallKyiv,[34] andNIIETVoronezh.[13]
Today, 8051s are still available as discrete parts, but they are mostly used assilicon intellectual property cores.[35] Available in hardware description language source code (such asVHDL orVerilog) orFPGAnetlist forms, these cores are typically integrated within embedded systems, in products ranging fromUSB flash drives to washing machines to complex wireless communicationsystems on a chip. Designers use 8051 silicon IP cores, because of the smaller size, and lower power, compared to 32-bit processors likeARM Cortex-M series,MIPS and BA22.[citation needed]
Subsequent 8051 core designs have increased performance while retaining compatibility with the original MCS 51 instruction set. The original Intel 8051 was a microcode engine using 12 clocked microcode cycles per machine cycle to minimize the number of NMOS logic gates consuming power in passive resistive pull-ups. Most instructions executed in one or two machine cycles. At the typical maximum clock frequency of 12 MHz the original 8051 types execute one million single-cycle instructions, or 500,000 two-cycle instructions, per second. The change to CMOS using active P-channel FET pull-ups makes it possible to realize the core without microcode. Enhanced 8051 IP cores run at one clock cycle per machine cycle. With clock frequencies of up to 450 MHz an 8051-compatible processor can execute up to 450 million instructions per second.
This sectionneeds expansion. You can help byadding to it.(June 2021) |

Several variants with an additional 16-bitdigital signal processor (DSP) (for example forMP3 orVorbis coding/decoding) with up to 675 million instructions per second (MIPS)[46] and integratedUSB 2.0 interface[47] or as intellectual property[48] exist.
This sectionneeds expansion. You can help byadding to it.(May 2013) |
In 1996 Intel announced the MCS-151 family, an up to 6 times faster variant,[3] that's fully binary andinstruction set compatible with 8051. Unlike their 8051 MCS-151 is a pipelined CPU, with 16-bit internal code bus and is 6x the speed. The MCS-151 family was also discontinued by Intel, but is widely available in binary compatible and partly enhanced variants.
This sectionneeds expansion. You can help byadding to it.(May 2013) |
The 80251 8/16/32-bit microcontroller with 16 MB (24-bit) address-space and 6 times faster instruction cycle was introduced by Intel in 1996.[3][49] It can perform as an 8-bit 8051, has 24-bitlinear addressing, an 8-bit ALU, 8-bit instructions, 16-bit instructions, a limited set of 32-bit instructions, 16 8-bit registers, 16 16-bit registers (8 16-bit registers which do not share space with any 8-bit registers, and 8 16-bit registers which contain 2 8-bit registers per 16-bit register), and 10 32-bit registers (2 dedicated 32-bit registers, and 8 32-bit registers which contain 2 16-bit registers per 32-bit register).[50]
It features extended instructions[51] – see also the programmer's guide[52] – and later variants with higher performance,[53] also available as intellectual property (IP).[54] It is 3-stage pipelined. The MCS-251 family was also discontinued by Intel, but is widely available in binary compatible and partly enhanced variants from many manufacturers.
{{cite book}}: CS1 maint: location (link)
Media related toMCS-51 at Wikimedia Commons