The Intel MCS-51 (commonly termed 8051, typically pronounced eight-oh-five-one) is a single chip microcontroller (MCU) series developed by Intel in 1980 for use in embedded systems. The architect of the Intel MCS-51 instruction set was John H. Wharton.[1][2] Intel's original versions were popular in the 1980s and early 1990s, and enhanced binary compatible derivatives remain popular today. It is an example of a complex instruction set computer (but also possessing some of the features of RISC architectures, such as a large register set and register windows) and has 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 predecessor Intel 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 enhanced 8-bit MCS-151 and the 8/16-bit/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 a digital signal processor (DSP). Beyond these physical devices, several companies also offer MCS-51 derivatives as IP cores for use in field-programmable gate array (FPGA) or application-specific integrated circuit (ASIC) designs.
Important features and applications
8-bit arithmetic logic unit (ALU) and accumulator, 8-bit registers (one 16-bit register with special move instructions), 8-bit data bus and 2×16-bit address buses, program counter, data pointer, and related 8/11/16-bit operations; hence it is mainly an 8-bit microcontroller
Boolean processor with 17 instructions, 1-bit accumulator, 32 registers (4x8-bit, bit-addressable) and up to 144 special 1 bit-addressable RAM variables (18x8-bit)[4]
- Multiply, divide and compare instructions
- Four fast switchable register banks with eight registers each (memory mapped)
- Fast interrupt with optional register bank switching
- Interrupts and threads with selectable priority[5]
- 128 or 256 bytes of on-chip RAM (IRAM)
- Dual 16-bit address bus; it can access 2×216 memory locations: 64 KB (65,536 locations) each of ROM (PMEM) and external RAM (XRAM), using two memory buses in a Harvard architecture.
- On-chip ROM (not included on 803x variants)
- Four (three full) 8-bit bi-directional input/output ports, bit addressable
- UART (serial port)
- Two 16-bit counter/timers
- Power saving mode (on some derivatives)
One feature of the 8051 core is the inclusion of a boolean processing engine, which allows bit-level boolean logic operations to be carried out directly and efficiently on select internal registers, ports and select RAM locations. Another feature is the inclusion of four bank selectable working register sets, which greatly reduce the time required to perform the context switches to enter and leave interrupt service routines. With one instruction, the 8051 can switch register banks, avoiding the time-consuming task of transferring the critical registers to RAM.
Once a UART, and a timer if necessary, has been configured, the programmer needs only write a simple interrupt routine to refill the send shift register whenever the last bit is shifted out by the UART and/or empty the full receive shift register (copy the data somewhere else). The main program then performs serial reads and writes simply by reading and writing 8-bit data to stacks.
Derivative features
As of 2013, new derivatives are still being developed by many major chipmakers, and major compiler suppliers such as IAR Systems, Keil and Altium Tasking[6] continuously release updates.
MCS-51 based microcontrollers typically include one or two UARTs, two or three timers, 128 or 256 bytes of internal data RAM (16 bytes of which are bit-addressable), up to 128 bytes of I/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 MHz clock 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, and are thus capable of an even greater number of instructions per second. All Silicon Labs, some Dallas (now part of Maxim Integrated) and a few Atmel (now part of Microchip) devices have single cycle cores.[7][8][9]
8051 variants may include built-in reset timers with brown-out detection, on-chip oscillators, self-programmable flash ROM program memory, built-in external RAM, extra internal program storage, bootloader code in ROM, EEPROM non-volatile data storage, I2C, SPI, and USB host interfaces, CAN or LIN bus, ZigBee or Bluetooth radio modules, PWM generators, analog comparators, analog-to-digital and digital-to-analog converters, RTCs, extra counters and timers, in-circuit debugging facilities, more interrupt sources, extra power saving modes, more/less parallel ports etc. Intel manufactured a mask programmed version, 8052AH-BASIC, with a BASIC 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 the Honeywell 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., from Cobham (formerly Aeroflex) 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.
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 a Harvard 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 a Von 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
Internal RAM (IRAM) has an 8-bit address space, using addresses 0 through 0xFF. IRAM from 0x00 to 0x7F contains 128 directly adressible 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 the PUSH and POP operations; and *CALL and RET operations.
The original 8051 has only 128 bytes of IRAM. The 8052 added IRAM from 0x80 to 0xFF, which can only 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 80-FF 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
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 timer 2 registers 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.
Register windows
The 32 bytes in IRAM from 0x00–0x1F contains space for four eight-byte register windows, which the 8 registers R0–R7 map to. The currently active window is determined by a two-bit address contained in the program status word.
Bit registers
The 16 bytes (128 bits) at IRAM locations 0x20–0x2F contains 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 on 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
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 as lookup tables in program memory, retrieved by the MOVC A,@A+DPTR or MOVC A,@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 and ACALL) slightly reduce the size of code that accesses local (within the same 2 KB) program memory.[19]
When code larger than 64K 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 32K of code, and are always resident.
External data memory
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 the MOVX (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 the MOVX A,@R0, MOVX A,@R1, MOVX @R0,A, and MOVX @R1,A instructions. The full 64KB may be accessed using MOVX A,@DPTR and MOVX @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 64K 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:
Stack pointer, SP (0x81)
This is an 8-bit register used by subroutine call and return instructions. The stack grows upward; the SP is incremented before pushing, and decremented after popping a value.
Data pointer, DP (0x82–83)
This is a 16-bit register that is used for accessing PMEM and XRAM.
Program status word, PSW (0xD0)
This contains important status flags, by bit number:
Parity, P. Gives the parity (XOR of the bits) of the accumulator, A.
User defined, UD. May be read and written by software; not otherwise affected by hardware.
Overflow flag, OV. Set when addition produces a signed overflow.
- Register select 0, RS0. The low-order bit of the register bank. Set when banks at 0x08 or 0x18 are in use.
- Register select 1, RS1. The high-order bit of the register bank. Set when banks at 0x10 or 0x18 are in use.
- Flag 0, F0. May be read and written by software; not otherwise affected by hardware.
- Auxiliary carry, AC. Set when addition produces a carry from bit 3 to bit 4.
- Carry bit, C. Often used as the general register for bit computations, or the "Boolean accumulator".
- Accumulator, A (0xE0)
- This register is used by most instructions.
- B register (0xF0)
This is used as an extension to the accumulator for multiply and divide instructions.
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 common negative (N), or zero (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 MCS51 UARTs could send 9 bits.
Comments
Post a Comment