Page 1 :
Introduction to 8051 Microcontroller, 8051 is one of the first most popular microcontroller also known, as MCS-51. It was introduced by Intel in the year 1981. Initially it, came out as N-type metal-oxide-semiconductor (NMOS) based, microcontroller, but later versions were based on, complementary metal-oxide-semiconductor(CMOS), technology. These microcontrollers were named as 80C51,, where C in the name tells that it is based on CMOS technology., It is an 8-bit microcontroller which means data bus is of 8-bits., Therefore, it can process 8-bits at a time. It is used in wide, variety of embedded systems like robotics, remote controls,, automotive industry, telecom applications, power tools etc., System on a Chip :, It is referred to as System on a Chip (SoC) microcontroller because, it is a chip circuit/integrated circuit that holds many components of, a computer together on a single chip. These components includes a, CPU, memory, input output ports(I/O ports), timers and secondary, storage., Features –, There are some key features of 8051 which works as a foundation for, students to learn microcontrollers. These features include :•4, , KB on-chip ROM (Program memory)., • 128 bytes on-chip RAM (Data memory)., • 8 bit data bus (bidirectional)., • 16 bit address bus (unidirectional)., • Two 16-bit timers., • Instruction cycle of 1 microsecond with 12 MHz crystal., • Four 8-bit ports., • 128 user defined flags., • Four register banks of 8 bit each., • 16-byte bit-addressable RAM., Difference between Microprocessor and Microcontroller, , Microprocessor, , Microcontroller
Page 2 :
Microprocessor is the, heart of Computer, system., , Micro Controller is the, heart of an embedded, system., , It is only a processor, so, memory and I/O, components need to be, connected externally, , Micro Controller has a, processor along with, internal memory and, I/O components., , Memory and I/O has to Memory and I/O are, be connected, already present, and, externally, so the circuit the internal circuit is, becomes large., small., You can’t use it in, compact systems, , You can use it in, compact systems., , Cost of the entire, system is high, , Cost of the entire, system is low, , Due to external, components, the total, power consumption is, high. Therefore, it is not, ideal for the devices, running on stored, power like batteries., , As external, components are low,, total power, consumption is less. So, it can be used with, devices running on, stored power like, batteries., , Most of the, Most of the, microprocessors do not, microcontrollers offer, have power saving, power-saving mode., features., It is mainly used in, personal computers., , It is used mainly in a, washing machine, MP3, players, and embedded, systems., , Microprocessor has a, smaller number of, , Microcontroller has, more register. Hence
Page 3 :
registers, so more, the programs are easier, operations are memory- to write., based., Microprocessors are, Micro controllers arc, based on Von Neumann based on Harvard, model, architecture, It is a byproduct of the, It is a central processing development of, unit on a single silicon- microprocessors with a, based integrated chip. CPU along with other, peripherals., It has no RAM, ROM,, Input-Output units,, timers, and other, peripherals on the chip., , It has a CPU along with, RAM, ROM, and other, peripherals embedded, on a single chip., , It uses an external bus, to interface to RAM,, It uses an internal, ROM, and other, controlling bus., peripherals., Microprocessor-based, systems can run at a, very high speed, because of the, technology involved., , Microcontroller based, systems run up to, 200MHz or more, depending on the, architecture., , It’s used for general, purpose, It’s used for, applications that allow application-specific, you to handle loads of systems., data., It’s complex and, expensive, with a large, number of instructions, to process., , It’s simple and, inexpensive with less, number of instructions, to process.
Page 4 :
Overview of 8051 microcontroller family, 8051 is 8-bit microcontroller with 4 KB program memory and 128 Bytes data, memory. Other features include four 8-bit ports, two 16-bit timers and one onchip serial port., Overview of the 8051 Family :, 8051 microcontroller was initially designed by Intel Corporation in 1981. Features, of 8051 made it extremely popular in market. Because of it’s popularity and high, demand Intel allowed other manufacturers to fabricate and market different, variants of 8051 with a condition that all these variants should be code compatible, with 8051. This resulted in a lot of variants of 8051 in market, among which 8052, and 8031 are the most popular ones. Therefore, 8052 and 8031 are considered as, the family members of 8051., , •, , •, , 8052 –, 8052 is the super set of 8051 as it has all the features of 8051, with an extra timer and an extra RAM of 128 bytes., Therefore, 8052 has a total of 256 bytes of RAM and 3 timers, in all. Also all the programs written for 8051 will run on, 8052 as 8052 is super set of 8051, but it’s reverse is not true., 8031 –, 8031 is referred to as ROM-less microcontroller chip, because it has 0 K byes of on-chip ROM. For it’s operation,, 8031 requires external ROM which aids it in fetch and, execute operations. Apart from this, it shares almost all the, features of 8051., , Comparison of 8051 with its other family members :, Following table highlights the main characteristics of distinction between 8051,, 8052 and 8031 –, Characteristic, , 8051, , 8052, , 8031, , RAM, , 128 bytes 256 bytes 128 bytes, , ROM (on-chip), , 4 KB, , 8 KB, , 0 KB, , Number of Timer, , 2, , 3, , 2, , Interrupt Sources, , 6, , 8, , 6, , Serial Port, , 1, , 1, , 1
Page 5 :
Characteristic, , 8051, , Number of I/O Ports 32, , 8052, 32, , 8031, 32, , Pin diagram of 8051 Microcontroller, 8051 microcontroller is a 40 pin Dual Inline Package (DIP)., These 40 pins serve different functions like read, write, I/O, operations, interrupts etc. 8051 has four I/O ports wherein each, port has 8 pins which can be configured as input or output, depending upon the logic state of the pins. Therefore, 32 out of, these 40 pins are dedicated to I/O ports. The rest of the pins are, dedicated to VCC, GND, XTAL1, XTAL2, RST, ALE, EA’ and, PSEN’., Pin diagram of 8051 microprocessor is as given below :
Page 7 :
Description of the Pins :, , •, , •, , •, , Pin 1 to Pin 8 (Port 1) –, Pin 1 to Pin 8 are assigned to Port 1 for simple I/O, operations. They can be configured as input or output pins, depending on the logic control i.e. if logic zero (0) is applied, to the I/O port it will act as an output pin and if logic one (1), is applied the pin will act as an input pin. These pins are also, referred to as P1.0 to P1.7 (where P1 indicates that it is a pin, in port 1 and the number after ‘.’ tells the pin number i.e. 0, indicates first pin of the port. So, P1.0 means first pin of port, 1, P1.1 means second pin of the port 1 and so on). These pins, are bidirectional pins., Pin 9 (RST) –, Reset pin. It is an active-high, input pin. Therefore if the, RST pin is high for a minimum of 2 machine cycles, the, microcontroller will reset i.e. it will close and terminate all, activities. It is often referred as “power-on-reset” pin, because it is used to reset the microcontroller to it’s initial, values when power is on (high)., Pin 10 to Pin 17 (Port 3) –, Pin 10 to pin 17 are port 3 pins which are also referred to as, P3.0 to P3.7. These pins are similar to port 1 and can be used, as universal input or output pins. These pins are, bidirectional pins., These pins also have some additional functions which are as, follows:, 1. P3.0 (RXD) :, 10th pin is RXD (serial data receive pin) which is for, serial input. Through this input signal, microcontroller receives data for serial, communication., 2. P3.1 (TXD) :, 11th pin is TXD (serial data transmit pin) which is, serial output pin. Through this output signal, microcontroller transmits data for serial, communication.
Page 8 :
•, , •, , •, , •, , •, , 3. P3.2 and P3.3 (INT0′, INT1′ ) :, 12th and 13th pins are for External Hardware, Interrupt 0 and Interrupt 1 respectively. When this, interrupt is activated(i.e. when it is low), 8051 gets, interrupted in whatever it is doing and jumps to the, vector value of the interrupt (0003H for INT0 and, 0013H for INT1) and starts performing Interrupt, Service Routine (ISR) from that vector location., 4., P3.4 and P3.5 (T0 and T1) :, 14th and 15th pin are for Timer 0 and Timer 1, external input. They can be connected with 16 bit, timer/counter., 5. P3.6 (WR’) :, 16th pin is for external memory write i.e. writing data, to the external memory., 6., P3.7 (RD’) :, 17th pin is for external memory read i.e. reading data, from external memory., Pin 18 and Pin 19 (XTAL2 And XTAL1) –, These pins are connected to an external oscillator which is, generally a quartz crystal oscillator. They are used to, provide an external clock frequency of 4MHz to 30MHz., Pin 20 (GND) –, This pin is connected to the ground. It has to be provided with, 0V power supply. Hence it is connected to the negative, terminal of the power supply., Pin 21 to Pin 28 (Port 2) –, Pin 21 to pin 28 are port 2 pins also referred to as P2.0 to P2.7., When additional external memory is interfaced with the 8051, microcontroller, pins of port 2 act as higher-order address, bytes. These pins are bidirectional., Pin 29 (PSEN) –, PSEN stands for Program Store Enable. It is output, active-low, pin. This is used to read external memory. In 8031 based, system where external ROM holds the program code, this pin, is connected to the OE pin of the ROM., Pin 30 (ALE/ PROG) –, ALE stands for Address Latch Enable. It is input, active-high, pin. This pin is used to distinguish between memory chips
Page 9 :
when multiple memory chips are used. It is also used to demultiplex the multiplexed address and data signals available, at port 0., During flash programming i.e. Programming of EPROM, this, pin acts as program pulse input (PROG)., •, , •, , •, , Pin 31 (EA/ VPP) –, EA stands for External Access input. It is used to, enable/disable external memory interfacing. In 8051, EA is, connected to Vcc as it comes with on-chip ROM to store, programs. For other family members such as 8031 and 8032 in, which there is no on-chip ROM, the EA pin is connected to the, GND., Pin 32 to Pin 39 (Port 0) –, Pin 32 to pin 39 are port 0 pins also referred to as P0.0 to P0.7., They are bidirectional input/output pins. They don’t have any, internal pull-ups. Hence, 10 K? pull-up registers are used as, external pull-ups. Port 0 is also designated as AD0-AD7, because 8051 multiplexes address and data through port 0 to, save pins., Pin 40 (VCC) –, This pin provides power supply voltage i.e. +5 Volts to the, circuit., , 8051 Microcontroller Architecture, Let's see the internal architecture of 8051 Microcontroller represented in, form of block diagram as shown below:
Page 10 :
Basic components, architecture are:, , present, , internally, , inside, , 8051, , Microcontroller, , CPU (Central Processing Unit): CPU act as a mind of any processing machine., It synchronizes and manages all processes that are carried out in, microcontroller. User has no power to control the functioning of CPU. It, interprets the program stored in ROM and carries out from storage and then, performs it projected duty. CPU manage the different types of registers, available in 8051 microcontroller., Interrupts: Interrupts is a sub-routine call that given by the microcontroller, when some other program with high priority is request for acquiring the, system buses the n interrupts occur in current running program., Interrupts provide a method to postpone or delay the current process,, performs a sub-routine task and then restart the standard program again., Types of interrupt in 8051 Microcontroller:, Let's see the five sources of interrupts in 8051 Microcontroller:, o, , Timer 0 overflow interrupt - TF0, , o, , Timer 1 overflow interrupt - TF1, , o, , External hardware interrupt - INT0, , o, , External hardware interrupt - INT1, , o, , Serial communication interrupt - RI/TI, , o, , Memory: For operation Micro-controller required a program. This, program guides the microcontroller to perform the specific tasks. This, program installed in microcontroller required some on chip memory, for the storage of the program., Microcontroller also required memory for storage of data and, operands for the short duration. In microcontroller 8051 there is code, or program memory of 4 KB that is it has 4 KB ROM and it also, comprise of data memory (RAM) of 128 bytes., , o, , Bus : Bus is a group of wires which uses as a communication canal or acts, as means of data transfer. The different bus configuration includes 8, 16 or, more cables. Therefore, a bus can bear 8 bits, 16 bits all together., Types of buses in 8051 Microcontroller:
Page 11 :
Let's see the two types of bus used in 8051 microcontroller:, o, , Address Bus: 8051 microcontrollers is consisting of 16 bit address bus. It is, generally be used for transferring the data from Central Processing Unit to, Memory., , o, , Data bus: 8051 microcontroller is consisting of 8 bits data bus. It is generally, be used for transferring the data from one peripherals position to other, peripherals., , Oscillator: As the microcontroller is digital circuit therefore it needs timer, for their operation. To perform timer operation inside microcontroller it, required externally connected or on-chip oscillator. Microcontroller is used, inside an embedded system for managing the function of devices., Therefore, 8051 uses the two 16 bit counters and timers. For the operation, of this timers and counters the oscillator is used inside microcontroller., , Internal RAM structure of 8051 controller, 8051 Micro controller is 8-bit controller.it contain 128Byte of internal RAM.internal, RAM divided into three section., •, •, •, , 32 bytes-Register Bank., 16 Byte-bit addressable area., 80 byte-Scratch pad area & SFR.
Page 12 :
below diagram show architecture of RAM, , 32 Byte-Register Bank, there are four register bank into RAM.each register bank contain 8 registers of 1byte.so total, 32 register in register bank.by default register bank 0 is selected.to change the register bank, we have to set value of two register selection bit in PSW register., , 16Byte for bit addressable Area., In RAM there are 16 byte area in which 128 bit we can accessed by suitable instruction.the, address range of bits addressable area is 00h (LSB of first byte of 20h ) to 7Fh(MSB of last, byte if 2Fh)., remaining 80 bytes are general purpose area which are shared with DATA and SFR (special, function register)upper 128 byte of RAM accessed indirect addressing while SFR accessed, by direct addressing only.SFR contain special register like ACC,B,IE,IP,IE etc.below diagram, show memory allocation for SFR.
Page 13 :
8051 Microcontroller Special, Function Registers (SFRs), The 8051 Microcontroller Special Function Registers act as a control table that monitor, and control the operation of the 8051 Microcontroller. If you observe in Internal RAM, Structure, the Address Space from 80H to FFH is allocated to SFRs., Out of these 128 Memory Locations (80H to FFH), there are only 21 locations that are, actually assigned to SFRs. Each SFR has one Byte Address and also a unique name which, specifies its purpose., Since the SFRs are a part of the Internal RAM Structure, you can access SFRs as if you, access the Internal RAM. The main difference is the address space: first 128 Bytes (00H, to 7FH) is for regular Internal RAM and next 128 Bytes (80H to FFH) is for SFRs., , Categories of 8051, Microcontroller Special Function Registers, All the 21 8051 Microcontroller Special Function Registers (SFRs) along with their, functions and Internal RAM Address is given
Page 14 :
in the following table., , There are many ways to categorize these 21 Special Function Registers but I find, the following way as an appropriate one. The 21 Special Function Registers of, 8051 Microcontroller are categorized in to seven groups. They are:, Math or CPU Registers: A and B, Status Register: PSW (Program Status Word), Pointer Registers: DPTR (Data Pointer – DPL, DPH) and SP (Stack Pointer), I/O Port Latches: P0 (Port 0), P1 (Port 1), P2 (Port 2) and P3 (Port 3), Peripheral Control Registers: PCON, SCON, TCON, TMOD, IE and IP
Page 16 :
Flag Bit, , Bit, Address, , Description, , Cy, , D7H, , Carry Flag. It is affected by, executing instructions like Add,, Sub, rotate through carrying etc., It also be used as the 1-bit, accumulator, , Ac, , D6H, , Auxiliary Carry Flag. This is used, for BCD operations. This flag is, not directly used by the user., , F0, , D5H, , It is user defined flag bit. This, flag is general purpose., , RS1, and, RS1, , D4H and, D3H, , These two bits are used for, register select. The four register, banks can be selected by these, two flags., , Ov, , D2H, , This is the overflow flag. When, after addition or subtraction the, result is outside the signed 8-bit, range (-128 to 127), this flag is, enabled, , X, , D1H, , This is reserved for future use., , P, , D0H, , This is the parity flag. After, executing an instruction, it, checks the number of 1s in the, accumulator and based on that, it is enabled or disabled.
Page 17 :
Program Memory (ROM) of 8051, Microcontroller, In 8051 Microcontroller, the code or instructions to be executed are stored in the, Program Memory, which is also called as the ROM of the Microcontroller. The, original 8051 Microcontroller by Intel has 4KB of internal ROM., Some variants of 8051 like the 8031 and 8032 series doesn’t have any internal, ROM (Program Memory) and must be interfaced with external Program Memory, with instructions loaded in it., Almost all modern 8051 Microcontrollers, like 8052 Series, have 8KB of Internal, Program Memory (ROM) in the form of Flash Memory (ROM) and provide the, option of reprogramming the memory., , In case of 4KB of Internal ROM, the address space is 0000H to 0FFFH. If the, address space i.e., the program addresses exceed this value, then the CPU will, automatically fetch the code from the external Program Memory.
Page 18 :
For this, the External Access Pin (EA Pin) must be pulled HIGH i.e., when the EA, Pin is high, the CPU first fetches instructions from the Internal Program Memory, in the address range of 0000H to 0FFFFH and if the memory addresses exceed, the limit, then the instructions are fetched from the external ROM in the address, range of 1000H to FFFFH., , There is another way to fetch the instructions: ignore the Internal ROM and fetch, all the instructions only from the External Program Memory (External ROM). For, this scenario, the EA Pin must be connected to GND. In this case, the memory, addresses of the external ROM will be from 0000H to FFFFH.⁸