Module 4
Module 4
Introduction to 8051
CONTENTS
Introduction to microcontroller
Difference between microcontroller and microprocessor
8051 :
• architecture
• pin diagram of 8051
• memory organization
• special function registers
• I/O pins ,timers, interrupts, serial interface
• power consumption, external interface of the standard 8051
What is a Microcontroller?
• A microcontroller (MCU) is a
small, self-contained
microcomputer that is usually
designed to run a single basic
program repeatedly.
• It's a compact integrated circuit
(IC) device that's used to control
other parts of an electronic
system.
Difference between Microprocessor and
Microcontroller
• The 8051 microcontroller architecture is an 8-bit architecture designed by Intel
in 1981.
• It has a Harvard architecture design, with separate memory buses for
instruction and data.
• The 8051's central processing unit (CPU) is the brain of the microcontroller,
responsible for executing instructions and performing arithmetic and logical
operations. The CPU consists of an ALU, accumulator, registers, and a
program counter.
• The 8051 is called an 8-bit microcontroller because it processes 8 bits of data
every machine cycle. All assembly instructions happen 8-bits at a time, and all
internal registers are 8-bit in size.
• The 8051 is widely used in embedded systems due to its simplicity and
versatility.
• The 8051 microcontroller has a Complex Instruction Set Computer (CISC)
architecture.
• The 8051 microcontroller has the following features:
• 4 KB on-chip ROM (Program memory)
Central Processor Unit (CPU) is the brain of any processing device of the
microcontroller.
It monitors and controls all operations that are performed on the Microcontroller
units.
The User has no control over the work of the CPU directly.
It reads program written in ROM memory and executes them and do the
expected task of that application.
INTERRUPT CONTROL
There are five interrupt sources in 8051 Microcontroller and interrupt
control section control all these interrupts.
Two external interrupts (INT0 & INT1), two timer (TF0 & TF1) interrupts
and one serial port (RI / TI) interrupt.
Since the 8051 has an 8-bit architecture, each 16-bit is accessed as two
separate registers of low byte and high byte.
SERIAL PORT
Pins 32-39: Port 0 (P0.0 to P0.7) – In addition to serving as I/O port, lower order address and data bus
signals are multiplexed with this port (to serve the purpose of external memory interfacing). This is a bi
directional I/O port (the only one in 8051) and external pull up resistors are required to function this port as
I/O.
Pin-31:- ALE - Address Latch Enable. It is especially used for 8031 IC to connect it to the external memory.
It can be used while deciding whether P0 pins will be used as Address bus or Data bus. When ALE = 1, then
the P0 pins work as Data bus and when ALE = 0, then the P0 pins act as Address bus.
Pin-30:- EA - External Access input is used to enable or disallow external memory interfacing. If there is no
external memory requirement, this pin is pulled high by connecting it to Vcc.
Pin- 29:- PSEN or Program Store Enable. This is an active low pin, i.e., it gets activated after applying a low
pulse. It is an output pin and used along with the EA pin in 8031 based (i.e. ROMLESS) Systems to allow
storage of program code in external ROM.
Pins- 21-28: Port 2 (P 2.0 to P 2.7) – in addition to serving as I/O port, higher order address bus signals are
multiplexed with this quasi bi directional port.
Pin 20:- Vss – it represents ground (0 V) connection.
Pins 18 and 19:- XTAL1 & XTAL2 Used for interfacing an external crystal to provide system clock.
Pins 10 – 17:- Port 3 (P 3.0 to P 3.7) It is also of 8 bits and can be used as Input/Output. This port provides some
extremely important signals.
P3.0 and P3.1 are RxD (Receiver) and TxD (Transmitter) respectively and are collectively used for Serial
Communication.
P3.2 and P3.3 pins are used for external interrupts. P3.4 and P3.5 are used for timers T0 and T1 respectively.
P3.6 and P3.7 are Write (WR) and Read (RD) pins.
Pin 9:- RESET pin is used to set the 8051 microcontroller to its initial values, while the microcontroller is
working or at the initial start of application. The RESET pin must be set high for 2 machine cycles.
Pins 1 – 8:- Port 1 (P 1.0 to P 1.7). It is an 8-bit port (pin 1 through 8) and can be used either as input or
output. Unlike other ports, this port does not serve any other functions. Port 1 is an internally pulled up,
quasi bi directional I/O port.
The 8051 microcontroller's memory is divided into four types:
•Program memory
Also known as ROM, this memory is used to permanently save the program that is being
executed.
•Data memory
Also known as RAM, this memory is used to temporarily store intermediate results and
variables.
REGISTER BANKS
At a time only one register bank is selected (using RS1 & RS0
bits in PSW register) for operations and the registers inside
the selected bank are accessed using mnemonics R0..R1.. etc.
The Bit Addressable area of the RAM is 16 bytes (128 bits) next to register
banks of Internal RAM located between 20h and 2Fh. In all there are 128 bits
numbered 00h to 7Fh.
Being bit variables any one variable can have a value 0 or 1. A bit variable
can be set with a command such as SETB and cleared with a command such
as CLR.
Example instructions are
SETB 25h ; sets the bit 25h (becomes 1)
CLR 25h ; clears bit 25h (becomes 0)
Bit addressable area is mainly used to store bit variables from application
program, like status of an output device like LED or Motor (ON/OFF) etc.
We need only a bit to store this status and using a complete byte addressable
area for storing this is really bad programming practice, since it results in
wastage of memory.
DATA MEMORY – SFRs (Special Function Registers)
The SFR registers are located within the Internal Memory in the address range 80h to FFh.
Each SFR has a very specific function. Note some of the SFR registers are bit addressable.
Although 128 byes of the SFR address space is defined only 21 SFR registers are defined in the
standard 8051.
Rest of locations are intentionally left unoccupied in order to enable the manufacturers to
further develop microcontrollers keeping them compatible with the previous versions.
Main function of SFR is to control timers, counters, serial I/O, port I/O, and peripherals that
are present in 8051 microcontroller.
The 21 Special Function Registers of 8051 Microcontroller are
categorized in to seven groups.