8051 Microcontroller
Dr. Soumitra K Nayak
School of Electrical and Electronics Engineering
VIT Bhopal University
Module - 3
8051 Microcontroller:
• Intel MCS – 51 family features
• 8051 - organization and architecture & Pin Diagram
• Registers
• Addressing modes & Instruction set (conditional instructions, I/O
Programming, Arithmetic logic instructions, single bit instructions)
• Timers and Counters
• Serial communication
• Interrupt handling.
Why Microcontroller !
Its not exaggerated to say that, there are no electronic gadget on the earth today which are
being designed without a Microcontroller.
Example: communication devices, digital entertainment, portable devices etc…
• Personal information products: Cell phone, pager, watch, pocket recorder, calculator
• Laptop components: mouse, keyboard, modem, fax card, sound card, battery charger
• Home appliances: door lock, alarm clock, thermostat, air conditioner, TV remote, VCR, small
refrigerator, exercise equipment, washer/dryer, microwave oven
• Industrial equipment: Temperature/pressure controllers, Counters, timers, RPM Controllers
• Toys: video games, cars, dolls, etc.
Basic Components of a Microcontroller
• Good designers should always know what
type of controller they are using, their
architecture, Pros & cons, ways to reduce
production costs, and product reliability etc.
Microcontroller :
• A smaller computer
CPU RAM ROM
• On-chip RAM, ROM, I/O ports...
• Example: Motorola’s 6811, Intel’s 8051, Serial
I/O Timer COM
Zilog’s Z8 and PIC 16X Port Port
Limitations of Microprocessor
• The overall system cost is high
• A large sized PCB is required for assembling all the components
• Overall product design requires more time
• Physical size of the product is big, no RAM, ROM, I/O on CPU chip itself
• A discrete components are used, the system is not reliable
Advantages of Microcontroller based System
• As the peripherals are integrated into a single chip, the overall system cost is very less
• The product is of small size compared to micro processor based system
• The system design now requires very little efforts
• As the peripherals are integrated with a microprocessor the system is more reliable
• Though microcontroller may have on chip ROM, RAM and I/O ports, addition ROM,
RAM I/O ports may be interfaced externally if required
• On chip ROM provide a software security
Evolution of Microcontroller
• In the year 1976, Motorola created a Microprocessor chip called 6801 which replaced its
brother 6800 with certain add-on chips to make a computer. This paved the way for the new
revolution in the history of chip design and gave birth to a new entity called
MICROCONTROLLER.
• The INTEL bagged the credit of producing the first Microcontroller 8048 with a CPU and 1K
bytes of EPROM, 64 Bytes of RAM an 8-Bit Timer and 27 I/O pins in 1976.
• Then followed the most popular controller 8051 in the year 1980 with 4K bytes of ROM,128
Bytes of RAM , a serial port, two 16-bit Timers , and 32 I/O pins.
• The 8051 family has many additions and improvements over the years and remains a most
sought after tool for todays circuit designers.
Evolution of Microcontroller
• INTEL introduced a 16 bit controller 8096 in the year 1982
• Later INTEL introduced 80c196 series of 16-bit microcontrollers for mainly industrial
applications
• Microchip, another company has introduced a microcontroller PIC 16C64 an 8-bit in the
year 1985.
• 32-bit microcontrollers have been developed by IBM and Motorola-MPC 505 is a 32-bit
RISC controller of Motorola
• The 403 GA is a 32 -bit RISC embedded controller of IBM
ARM Microcontroller
• ARM company (Advanced RISC machines) has developed and
introduced 32 bit controllers which are high-end application devices,
especially communication devices like mobiles , iPod etc..
(Ref: www.arm.com)
Types of Microcontroller
Types of Microcontroller
• Atmel
• ARM Motorola
•8-bit
• Intel •68HC05
•8-bit •68HC08
•8XC42 •68HC11
•MCS48 •16-bit
•MCS51
•8xC251
•68HC12
•68HC16
•16-bit
•MCS96 •32-bit
•MXS296 •683xx
• National Semiconductor •Texas Instruments
•COP8 •TMS370
• Microchip •MSP430
•12-bit instruction PIC •Zilog
•14-bit instruction PIC •Z8
•PIC16F84 •Z86E02
•16-bit instruction PIC
• NEC
MCS-51 “Family” of Microcontrollers
Feature 8031 8051 8052 8751
ROM NO 4KB 8KB 4KB UV EPROM
RAM (Bytes) 128 128 256 128
TIMERS 2 2 3 2
I/O PINS 32 32 32 32
SERIAL PORTS 1 1 1 1
INTERRUPT 6 6 8 6
SOURCES
8051 Features
• 4K bytes internal ROM
• 128 bytes internal RAM
• Four 8-bit I/O ports (P0 - P3).
• Two 16-bit timers/counters
• One serial interface
• 64k external memory for code(program) (Only Read)- PSEN
• 64k external memory for data (read and write) – RD/WR
8051 Features
• Code memory is selectable by EA (internal or
external)
• May have external memory as code and data
• Only 1 on-chip oscillator (external crystal)
• 6 interrupt sources ( 3 internal, 2 external,
RESET)
8051 Block Diagram
8051 Architecture Diagram
8051 Microcontroller Architecture Features
• 32 I/O Pins (Input / Output Pins) – Arranged as 4 Ports: P0, P1, P2 and P3.
• 8- bit Stack Pointer (SP) and Processor Status Word (PSW).
• 16 – bit Program Counter (PC) and Data Pointer (DPTR).
• Two 16 – bit Timers / Counters – T0 and T1.
• Control Registers – SCON, PCON, TCON, TMOD, IP and IE.
• Serial Data Transmitter and Receiver for Full – Duplex Operation – SBUF.
• Interrupts: Two External and Three Internal, RESET.
• Oscillator and Clock Circuit.
8051 Pin Diagram
• The 8051 is a 40 pin device, but
out of these 40 pins, 32 are used
for I/O.
• 24 of these are dual purpose,
i.e. they can operate as I/O or a
control line or as part of address
or data bus.
8051 Pin Diagram
• P0.0 to P3.7- 4 ports P0, P1, P2, P3
• XTAL1 and XTAL2- External
oscillator(quartz).
• RST- reset the microcontroller
• PSEN – “Program Store ENable” --
Enabling the external program memory
• RD - Reading from the external data
memory.
• WR- writing to the external memory.
• EA – “External Access enable” –
External code memory
• ALE – Address Latch Enable
• T0, T1 – Timer
• INT0 , INT1 – External Interrupt
• RXD, TXD- Serial input and output
8051 Pin Diagram
• Vcc – pin 40, Provides supply voltage to the chip. +5V
• GND – Pin 20 ground.
• PSEN - It is active low O/P signal. It is used to enable external program memory (ROM). When this
is low, then external program memory becomes enabled and microcontroller read content of
external memory location.
• EA - pin is for forcing the controller to use the external program memory. When it is connected to
ground , controller will fetch data from external memory.
• ALE- Address Latch Enable Pin. Using this Pins, external address can be separated from data (as
they are multiplexed by 8051).
• RST- Reset Input Pin. It is an active HIGH Pin i.e. if the RST Pin is HIGH for a minimum of two
machine cycles, the microcontroller will be reset. During this time, the oscillator must be running.
External Memory Access
8051 CPU Registers
• A (8-bit Accumulator)
• B (8-bit register for Multiplication & Division)
• PSW (8-bit Program Status Word) (same function as flag in 8086)
• SP (8-bit Stack Pointer)
• PC (16-bit Program Counter)
• DPTR (16-bit Data Pointer), DH, DL – 8 bit each
8051 Special Function Registers
• 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
• Peripheral Data Registers: TL0, TH0, TL1, TH1 and SBUF
8051 Microcontroller Memory
• 8 – bit CPU with two Registers A (Accumulator) and B.
• Internal ROM of 4K Bytes – It is a flash memory that supports in – system
programming.
• Internal RAM of 256 Bytes – The first 128 Bytes of the RAM i.e. 00H to 7FH is again
divided in to 4 banks with 8 registers (R0 – R7) in each bank, 16 bit addressable
registers and 80 general purpose registers.
• The higher 128 Bytes of the RAM i.e. 80H to FFH consists of SFRs or Special Function
Registers. Using SFRs we can control different peripherals like Timers, Serial Port, all
I/O Ports, etc.
On-chip memory Internal RAM
The internal RAM or Data
Memory of the 8051
Microcontroller is divided in to:
1. General Purpose Registers
2. Bit Addressable Registers
3. Register Banks
4. Special Function Registers
or SFRs.
Internal RAM Structure
On-chip memory Internal RAM
• Four register bank each with R0-R7 can be selected using PSW (RS0 and RS1) from 00h – 1Fh,
32 bytes.
• R0-R7 of bank 0 (00h-07h) is the default register bank .
• Register bank-1 is used as stack.
• Only 16 bytes are bit addressable out of 128 byte of RAM, from 20H to 2FH.
• These 16 bytes provide 16*8 = 128 bits of RAM bit address ability, addressed from 00H to 7FH.
• The rest must be accessed in byte format.
• Internal RAM location 20h – 2Fh are both bit and byte addressable.
• 80 bytes from 30h – 7Fh are used for read/write storage.
On-chip data memory - Internal RAM