You are on page 1of 33

INTRODUCTION TO 8051

MICROCONTROLLER
 DIFFERENCES BETWEEN MICROCONTROLLER AND
MICROPROCESSOR

 BASIC INTRODUCTION

 INTRODUCTION TO 8051

 FEATURES OF 8051

 INTERNAL MEMORY OF 8051

 SPECIAL FUNCTION REGISTER


DIFFERENCES BETWEEN MICROPROCESSOR AND
MICROCONTROLLER
INTRODUCTION
 A microcontroller is a small computer device that is present in
a single Integrated Circuit which is dedicated to perform one
task and execute one specific application.
 It contains memory, programmable input/output peripherals
as well as a processor. The microcontrollers are mostly
designed for embedded applications.
 These microcontrollers are available in different types i.e. 8bit,
16bit, 32bit. They are designed and implemented to execute a
specific function like displaying characters on LCD.
 The most important part in any microcontroller is the Central
Processing Unit which is ranging from 4bit to 64bit. The
programs can be stored in various memory segments like
RAM, ROM, EPROM, and EEPROM.
INTRODUCTION TO 8051 MICROCONTROLLER
 8051 is an 8-bit microcontroller invented by Intel. It was
advanced for math and single Boolean operations.
 Initially after 8051 microcontrollers was invented by Intel and
became popular, they slowly began to enhance their features
with various other manufacturers.
 The various versions of microcontrollers have been invented
with different speeds and different storage memories.
 The 8051 microcontroller is considered to be the basic
microcontroller because it is easy to integrate. Also this 8051
is considered to be the cost effective microcontroller.
 Almost all the microcontrollers support the dual inline
package consisting of 40 pins. Also available in QFP, TQFP,
PQFP.
Choosing a microcontroller:
 There are four major 8-bit microcontrollers from Freescale,
Intel, Zilog, and Microchip technology.
 The most important criteria for choosing a microcontroller are:
 Meeting the computing needs of the task very efficiently.
 Availability of software development tools like compiler, debugger,
and assembler.
 Wide availability and reliable sources of the microcontroller.
 Also the other factors that are to be considered are speed,
packaging, power consumption, amount of RAM and ROM,
number of I/O pins and timer.
 The software availability should be in such a way that it
should be able to support the chip. The software that is used
can also be a third party vendor.
 Wide availability suggest that along with Intel, various other
companies can also manufacture the 8051 microcontroller.
FEATURES OF 8051 MICROCONTROLLER
 The 8051 microcontroller is an 8-bit microcontroller because
the ALU inside the 8051 can perform maximum of 8-bit
operations. It has two registers A and B.

 It has internal 4KB of internal ROM and internal RAM of 128


bytes. Also it has 16 bit PC and data pointer along with 8-bit
PSW.

 It has two 16 bit counters/timers and four 8 bit ports i.e.


P0,P1,P2,P3.

 It has 3 internal interrupts and 2 external interrupts and 1 serial


port.

 Has oscillator and clock circuits.


ARCHITECTURE OF MICROCONTROLLER
CPU Registers:
 8051 internally contain 34 general purpose registers. Out of
these 34, two registers are A and B. The remaining 32
registers are bank registers.
 Register A is called the accumulator register which is going to
hold the result immediately. In case of multiplication or
division, the result will be stored inside this A register.
 Register B is generally used to store the temporary data. In
case of multiplication of 8 bit, the result will be 16 bit. So 8 bit
will be stored in A register and remaining 8 bits will be stored
in B register.
 In case of division operation, quotient will be stored in A
register and remainder will be stored in B register.
Program Status Word (PSW):
 This PSW in the 8051 is similar to the flag register in 8086
processor. This PSW will represent the current status of the
processor.
 The PSW contain different flag bits which represent the
current status. The representation of PSW is shown below.
Program Counter (PC):
 Program Counter is mainly used for holding address of the
next instruction to be executed.

 Assume that a processor is executing an instruction at 2000


address location. The next instruction that is to be started is at
2002 address location. So during the execution of 2000
address location, the PC loads the address 2002 that is to be
executed next.

 The PC is 16 bits wide. So with the PC we can access up to 64


KB i.e. from 0000 to FFFF
Data Pointer (DPTR):
 It is a 16 bit register.

 It is mainly used to hold the address of the data in memory. If


any external memory is connected to the 8051, then the
registers of the external memory have to be accessed using this
DPTR.

 The DPTR can be accessed separately i.e. DPH (higher 8 bit)


and DPL (lower 8 bit).

 So the DPTR can be used either as a 16 bit register or as a


combination of two 8 bit registers.
Stack and Stack Pointer:
 Stack is a portion of RAM which is mainly used for holding
the temporary information like data or an address.
 Stack Pointer is a register which is similar to PC or DPTR. But
SP holds the address of stack locations.
 The SP is an 8-bit register which can hold the minimum value
of 00 and the maximum value of FF.
 The instructions that are executed on the stack memory are
PUSH and POP. During the PUSH operation, the SP gets
incremented by 1 and then the data value gets pushed onto the
stack. If POP instruction is used, the data value which is
pointing w.r.t SP is removed and then value gets decremented
by 1.
 When the 8051 is powered up, the SP register contains the
value 07. This indicates that 08h is the first location used for
the stack by the 8051.
INTERNAL MEMORY OF 8051
 There are 128 bytes of RAM in 8051. The 128 bytes of RAM
inside the 8051 are assigned addresses 00 to 7Fh. These 128
bytes are divided into different groups.

 A total of 32 bytes from locations 00 to 1Fh are set aside for


register banks and the stack.

 A total of 16 bytes from locations 20h to 2Fh are set aside for
bit addressable read/write memory.

 A total of 80 bytes from locations 30h to 7Fh are used for read
and write storage which is known as scratch pad. These 80
locations of RAM are used for storing the data and parameters
of 8051 programmers.
Register banks in 8051:
 A total of 32 bytes of RAM are set aside for the register banks
and stack. These 32 bytes are divided into 4 banks of registers
in which each bank has 8 registers, R0-R7.
 The register bank 0 has the RAM locations from 0 to 7 where
R0 is the RAM location 0, R1 is the RAM location 1 and so
on.
 The register bank 1 has the RAM locations from 08 to 0Fh
where the registers start from R0 to R7.
 The third bank of registers R0 to R7 starts from memory
location 10h and goes to memory location 17h.
 The fourth bank of registers R0 to R7 starts from memory
location 18h to 1Fh.
 The register bank 1 uses the same memory space as the stack
which indicates that no other memory area can be used for the
stack.
Default register bank:
 The RAM locations 00-1Fh are set aside for four register
banks. Among these 4 register banks, when the 8051 is
powered up, there will be only one register bank which can be
accessed.
 The register bank that can be accessed on power up is the
register bank 0 which has the RAM locations starting from 00
to 07h.
How to switch register banks:
 Register bank 0 is the default when 8051 is powered up. If we
want to switch from one register bank to other, then it can be
done using PSW register.
 Bits D4 and D3 of the PSW are used to select the desired
register bank as shown in the table below.
 The PSW.4 and PSW.3 are bit addressable instructions which
can be accessed using SETB and CLR.
 For example, SETB PSW.3 will make PSW.3=1 and select
bank register 1.
Example Program:
External Memory:
 External RAM or ROM can be interfaced to the 8051
microcontroller.

 This will be done when the internal RAM and ROM memory
available on chip is not sufficient. The amount of external
RAM memory that can be added is up to 64KB.

 When the external RAM and ROM are interfaced then they
can be interfaced using 16 bit PC and the DPTR.

 PC can be used when external ROM is interfaced and DPTR


can be used when external RAM is interfaced.

 64KB can be interfaced because the controller provide 16


address lines where 2^16 is equal to 64KB.
SPECIAL FUNCTION REGISTER
 Along with the various registers, 8051 is provided with some
special function registers which are from the locations 80 to
FFh.

 All the registers in the SFR are known as memory mapped


registers because each and every register is provided with an
address.

 All the locations from 80 to FFh cannot be used as SFR’s


because 8051 contain only 21 SFR’s.

 21 SFR’s indicate that only 21 memory locations can be used


out of the 128 locations. Remaining locations are reserved or
unused locations.
 In the above list of special function registers, those marked
with * indicate that they are bit addressable.

 One easy way to identify the bit addressable registers is that


the address for each register those ending with 0 or 8 are the
bit addressable registers.

 Bit addressable registers indicate that the locations in that


particular register can be accessed bit wise.

 The SFR space contains special purpose CPU registers, I/O


ports, interrupt control, timers, and serial I/O.
CPU registers:
ACC – Accumulator
B - B register
PSW - Program Status Word
SP - Stack Pointer
DPTR - Data Pointer (DPH, DPL)
Interrupt Control:
IE - Interrupt Enable
IP - Interrupt Priority
I/O Ports:
P0 - Port 0
P1 - Port 1
P2 - Port 2
P3 - Port 3
Timers:
TMOD - Timer mode
TCON - Timer control
TH0 - Timer 0 High byte
TL0 - Timer 0 Low byte
TH1 - Timer 1 High byte
TL1 - Timer 1 Low byte
Serial I/O:
SCON - Serial port control
SBUF - Serial data register
Other:
PCON - Power Control

You might also like