0% found this document useful (0 votes)
99 views45 pages

8051 Microcontroller

Uploaded by

Malar M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views45 pages

8051 Microcontroller

Uploaded by

Malar M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

8051 Microcontroller

Microcontroller Vs Microprocessor
Microcontroller Vs Microprocessor


Microprocessor is heart of Computer system.

Micro Controller is a heart of embedded
system.
8051 - Introduction
• It is introduced by INTEL in the Year 1981

• It is Based on Harvard architecture.

• Initially the 8051 microcontroller was made up of NMOS technology which consumed
more power. To overcome this issue , INTEL relaunched the 8051 microcontroller using
CMOS technology and named it as 80C51

• After the Success of the 8051 microcontrollers , INTEL allowed other manufacturers to
develop 8051 microcontrollers under their own brand.

• Microchip, Zilog, Atmel, Philips, Siemens released products under their brand name.

• Coding for 8051 can be written in Assembly language and also in C language
8051
Altera
Suppliers
Infineon
Analog Devices Intel
Lattice Semiconductor
Atmel
Maxim Integrated
Cypress Semiconductor Microchip Technology
Dallas Semiconductor National Semiconductor
ELAN Microelectronics Corp. NEC
NXP Semiconductors
Energy Micro
Panasonic
EPSON Semiconductor
Free scale Semiconductor
Fujitsu
Hyperstone
8051 Pin Configuration
Features of 8051
•4KB bytes on-chip program memory (ROM)
•128 bytes on-chip data memory (RAM)
•Four register banks
•128 user defined software flags
•8-bit bidirectional data bus
•16-bit unidirectional address bus
•32 general purpose registers each of 8-bit
•16 bit Timers (usually 2, but may have more or less)
•Three internal and two external Interrupts
•Four 8-bit ports,(short model have two 8-bit ports)
•16-bit program counter and data pointer
•8051 may also have a number of special features such
as UARTs, ADC, Op-amp, etc
Review
• NO Pins in 8051
40
Power Supply for 8051
5v
Ground Pin Number in 8051
20
Power Pin Number in 8051
40
Number of Ports in 8051
4
Ram Size
128 Bytes
Rom Size
4kb
GPIO Ports
GPIO – General Purpose input and Output Ports

8051 has 4 Ports

i)Port 0 (Pin 39 -32)


ii)Port 1 (Pin 1 -8)
iii)Port 2 (Pin 21 -28)
iii)Port 3 (Pin 10 -17)
Port 0
Port 0 (pin 32 – 39)
• PORT 0 Has 8 GPIO pins (P0.0 to P0.7)
• PORT 0 is also designated as AD0 to AD7 i.e Port 0 will be used
for both address and Data
• Port 0 Should be connected to Pullup resistor (Note: There is
no need of Pullup Resistor for other Ports Port1,Port 2 and
Port3)
Port 1 (pin 1 – 8)
PORT 1 Has 8 GPIO pins (P1.0 to P1.7)
PORT 1 is configured as Input port by Default
PORT 1 doesn’t need Pullup resistor as it is internally connected
Port 2 (pin 21 – 28)
PORT 2 Has 8 GPIO pins (P2.0 to P2.7)
PORT 2 is also designated as address Bus (A8 to A15) , it should
be used along with PORT 0 while accessing 16 bit address
PORT 2 doesn’t need Pullup resistor as it is internally connected
Port 3 (pin 10 – 17)
• PORT 3 Has 8 GPIO pins (P3.0 to P3.7)
• PORT 3 has Some Special Functions.
• 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.
• PORT 3 doesn’t need Pullup resistor as it is internally connected
P3 Bit Function Pin
P3.0 RxD 10
P3.1 < TxD 11
P3.2 < Complement of INT0 12
P3.3 < INT1 13
P3.4 < T0 14
P3.5 < T1 15
P3.6 < WR 16
P3.7 < Complement of RD 17
Review
• Number of Ports
4
Which Port is Dedicated only for GPIO ?
Port 1
Which Port have Data Bus ?
Port 0
Which Ports have Address Bus ?
Port 0 & 2
Which Port Have Special Function ?
Port 3
Which Port Need Pull Up Resistor?
Port 0
8051 Pin Connection Diagram
•Pin 40 V − provides supply to the Chip and it is +5 V.
cc
•Pin 20 Gnd − provides ground for the Reference.
•XTAL1, XTAL2 (Pin no 18 & Pin no 19) − 8051 has on-
chip oscillator but requires external clock to run it. A
quartz crystal is connected between the XTAL1 & XTAL2
pin of the chip. This crystal also needs two capacitors of
30pF for generating a signal of desired frequency.
• 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 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.
8051 Pin Connection Diagram
Pin 29 (PSEN) –PSEN stands for Program Store Enable. It is
output, active-low pin. This is used to read external
memory.
Pin 30 (ALE/ PROG) – ALE stands for Address Latch Enable.
It is input, active-high pin.
Address Latch Enable ALE (Pin no 31) indicates if P0 has
address or data. When ALE = 0, it provides data D0-D7, but
when ALE = 1, it has address A0-A7.
Microcontroller Vs Microprocessor
Micro Controller

ALU ROM RAM

Timer I/O Port I/O Port

Microprocessor is heart of Computer system. Micro Controller is a heart of embedded system.




The microprocessor is a single-chip CPU.

The microcontroller is a single-chip

RAM and ROM are not incorporated within microcomputer system
chip

RAM is smaller, but it is enough for small

Multi Tasking applications.(If it is not sufficient, then external
memory may be added in the microcontroller-
based system)

Single Tasking
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


ALU

The ALU performs 8-bit arithmetic and logical operations when the operands are held at the temporary registers TMP1
and TMP2.
These temporary registers cannot be accessed by users.
The output of the ALU is stored in the accumulator in most of the arithmetic and logical operations with few exceptions.
Apart from addition and subtraction operations, the 8051 microcontroller also performs multiplication and division
operations.
The logical operations such as AND, OR, NOT, Ex-OR operations are also performed in ALU.
Accumulator
• The accumulator register (ACC) acts as an operand register.
• ACC is commonly used for data transfer and arithmetic instructions.
• The accumulator is also bit addressable.
• After any arithmetic operations, the result is stored in ACC.
B register
• The B register is used during multiply and divide operations to store the second operands for multiply and
divide instructions MUL AB and DIV AB respectively.
• After multiplication and division, a part of the result such as upper 8 bits of multiplication result and
remainder in case of division are stored in the B register.
• This register is commonly used as a temporary register
• This register is also bit addressable.
• It can be used as a general-purpose register except for MUL and IDIV instructions.
PSW(Program Status Word)

• This is a special function register.


• This register consists of the different status bits that reflect the current state of microcontroller.
• It contains the Carry (CY), the Auxiliary Carry(AC), the two register bank select bits (RS1 and RS0), the
Overflow flag (OV), a Parity bit(P), and two user-definable status flags.
• The carry bit serves the function of a carry bit in arithmetic operations and it also serves as the accumulator
for a number of Boolean operations.
• The auxiliary carry bit is used in addition of BCD numbers. This bit is set if a carry is generated out of bit 3
into bit 4. F0 is a general-purpose flag bit available for user applications.
• . The bits RS1 and RS0 are used to select the register bank from four register banks
• The overflow flag is used for signed arithmetic operation to determine whether the result is out of range after
a signed arithmetic operation.
• The parity bit reflects the number of 1s in the accumulator. When the accumulator contains an odd number of
1s, P = 1. If the accumulator contains an even number of 1s, P = 0.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Stack Pointer (SP)
• This is an 8-bit register.
• SP is incremented before the data is stored onto the stack using
PUSH/POP instructions execution.
• During a PUSH operation, first increment SP and the copy data.
• In a POP operation, initially copy data and then decrement SP.
• The 8-bit address of the stack top is stored in this register.
• The stack can be located anywhere in the on-chip 128-byte RAM.
• Stack Pointer __________ bit Register
• What is Push Operation ?
• What is POP Operation ?
• Where Does Stack Pointer Located?
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Data Pointer (DTPR)
• DTPR is 16-bit register.
• It consists of a higher byte (DPH) and a lower byte (DPL) of a 16-bit external data
RAM address.
• It can be accessed as two 8-bit registers or a 16-bit register.
• DTPR has been given two addresses in the special function register bank.
• DPTR is very useful for string operations and look-up table operations.
• With 16-bit DPTR, a maximum of 64 K of off-chip data memory and a maximum of
64 K of off-chip program memory can be addressed.
• This can be used as a general-purpose register also.
• To increment the contents of DPTR, the INC DPTR instruction is executed. But, there
is no such instruction in 8051 to decrement the DPTR.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Serial Port Data Buffer

• The serial port data buffer internally consists of two independent


registers such as transmit buffer and receive buffer at the same
location.
• The transmit buffer is a parallel-in serial-out register.
• The serial data receive buffer is a serial-in parallel-out register.
• The serial data buffer is identified as SBUF.
• If data is moved to SBUF, it goes to the transmit buffer and sets serial
transmission.
• When data is moved from SBUF, it receives serial data from the receive
buffer.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Timing Registers
• There are two 16-bit timing registers in 8051.
• The 16-bit timer register can be accessed as their lower and upper bytes.
• The TH0 and TL0 represent the lower byte and higher byte of the timing register 0
respectively.
• In the same way, TH1 and TL1 represent the lower byte and higher byte of the timing
register 1 respectively.
• All timing registers can be accessed by using the four different addresses allotted to them.
• The operation of the timing register may be timing or counting.
• There is a Timer Control (TCON) and a Timer Mode (TMOD) Registers to configure all
timers/counters in various modes.
• These timers can be used to measure pulse width from 1ms to 65 ms, generate longer time
delays and time intervals also.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Control Registers
• The control register consists of special function registers such as
Interrupt Priority (IP), Interrupt Enable (IE), Timer Mode (TMOD),
Timer Control (TCON), Serial Port Control (SCON) and Power
Control (PCON).
• All of these registers have allotted addresses in the special function
register bank of the 8051 microcontroller.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Timing and Control Unit
• The timing and control unit generates all the
necessary timing and control signals required for the
internal operation of the microcontroller.
• This unit also generates necessary control signals
ALE, , and
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Instruction Register
• This register is used to decode the opcode of any instruction to
be executed.
• After decoding, this register sends the decoded information to the
timing and control unit to generate necessary signals for the
execution of the specified instruction.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


Program Address Register
• This is an on-chip EPROM and a basic circuit mechanism
to internally address it.
RAM
• This block provides internal 128 bytes of RAM.
RAM Address Register
The RAM address register is used to generate address of RAM
internally.
P0.0 – P0.7 P2.0 – P2.7

Port 0 Drivers Port 2 Drivers


16 bit address Bus

8 bit Data Bus


RAM Address
EPROM/ROM Port 0 Latch Port 2 Latch RAM Register

8 bit Data Bus

B Register ACC
Program
Address TMP1 TMP2 Stack Pointer
Register

Buffer PCON SCON TMOD TCON


TH0 TL0 TH1 TL1 ALU
PC
Incrementor SBUF IE IP T2CON

Program
Interrupt, Serial Port and
PSW
Counter Timer Block PSEN
Instruction Timing & ALE
DPTR Register Control EA
8 bit Data Bus RST

Port 3 Latch Port 1 Latch


Oscillator
Port 3 Drivers Port 1 Drivers

P3.0 – P3.7 P1.0 – P1.7


SFR (Special Function Register)
• This register bank is a set of registers, which
can be addressed using their respective
addresses.
Memory Organization
• Program Memory - Read Only Memory (ROM) is a type of memory
used to permanently save the program being executed.
• Data Memory - Random Access Memory (RAM) is a type of memory
used for temporary storing data and intermediate results created and
used during the operation of the microcontrollers.

You might also like