Microcontroller 8051
Microcontroller 8051
Microcontroller 8051
Microcontroller 8051
2 A microcomputer system
ADDRESS BUS
CONTROL BUS
CPU
ROM RAM Interfacing Circuits
(Microprocessor)
IO and other
peripheral devices
(Timers, UART, KBDC,
Interrupt controllers,
DATA BUS
3 Microprocessors
ALU
ACCUMULATOR
PROGRAM
STACK POINTER
COUNTER REGISTERS
IO PORTS
TIMER/COUNTER
ALU
ACCUMULATOR IO PORTS
REGISTERS
INTERNAL SERIAL IO PORT
ROM
INTERNAL RAM
INTERRUPT
CIRCUITS
STACK POINTER
IC name Features
8031 0 Byte ROM, 128 Byte RAM, 2 – 16 bit counters
8032 0 Byte ROM, 256 Byte RAM, 3 – 16 bit counters
8051 4K Byte MROM, 128 Byte RAM, 2 – 16 bit counters
8052 8K Byte MROM, 256 Byte RAM, 3 – 16 bit counters
8751 4K Byte EPROM, 128 Byte RAM, 2 – 16 bit counters
8752 8K Byte EPROM, 256 Byte RAM, 3 – 16 bit counters
8951 4K Byte Flash ROM, 128 Byte RAM, 2 – 16 bit counters
8952 8K Byte Flash ROM, 256 Byte RAM, 3 – 16 bit counters
11 8051 Microcontroller Features
First member of MCS51 family of Intel microcontrollers
40 pin, +5V single supply, 1-16 MHz
Harvard Architecture
4K factory masked ROM, 128 Byte RAM
4 Nos of 8 bit IO ports
2 nos of 16 bit timers
Serial Interface (USART)
64K external code memory space
64K external data memory space
Operates on single bits
210 bit addressable locations available
4 µs Multiply/Divide facility
ARCHITECTURE
of
12
Intel 8051
Architecture Block
Diagram
13 of 8051
Internal ROM and RAM
I/O Ports with programmable pins
Timers/counters modules
Serial data communication modules
Eight bit CPU with registers A (Accumulator) and B
Sixteen bit program counter (PC) and Data pointer
(DPTR)
Eight bit program status word (PSW)
Eight bit stack pointer (SP)
Internal ROM or EPROM (8751) of 0 (8031) to 4K (8051)
Internal RAM of 128 Bytes:
Four register banks each containing 8 registers
Sixteen bytes, which may be addressed at bit level
Eighty bytes of general purpose data memory
32 I/O pins arranged as 4 eight bit ports P0-P3
Two 16 bit timers/counters
Full duplex serial data receiver/transmitter: SBUF
Control registers TCON, TMOD, SCON, PCON, IP, and IE
Two external and three internal interrupt sources
Oscillator and clock circuits
Programming
model
14 of 8051
• ‘*’ indicates the register is
both byte and bit
addressable
• The registers of 8051 can be
identified by their 8 bit
internal address
• Program counter PC do not
have internal 8 bit addresses
assigned to it
• DPTR as a 16 bit register is
not assigned any internal
address. However DPH and
DPL have their internal 8 bit
address
Pin configuration
Four eight bit ports are available; P0, P1, P2, P3.
The pins of each port are marked by Px.y (P3.0:
port 3 pin 0). Thus 32 pins may be used for I/O
purpose
Port 0 can also act as 8 bit multiplexed address
data bus when external memory is connected
Port 1 is a dedicated I/O port
Port 2 is again multifunctional with IO function
and can also be used to provide higher order
address when external memory is connected.
Port 3 can be used as an IO port. It can also be
used to provide pins to the external world for
interrupt, timers, USART and memory controls
Rest of the pins are for connecting crystal, power
supply, ground, enabling external ROM access,
ALE and EA-bar signals
15
8051 oscillator and clock
16
17 Program counter (PC)
Points to the 16 bit memory address (internal or external) from where next
instruction word has to be fetched.
Auto-increments after each and every code fetch operation
Is not under programmers’ control.
The status of EA-bar pin affects the operation of memory selection as
follows:
If EA-bar is tied high (disabled state):
Internal ROM will be considered for code fetch if address range in PC is (0000H – 0FFFH)
If PC address is in range (1000H-FFFFH) then external ROM will be selected for code
fetch
PORT 0
Can be configured as input-output port
If used as an output port, external pull-up resistance must be connected between port
pins and supply to allow valid logic states to appear as output information on the
concerned port/port pins .
Best use as an input port/pin
If external memory is connected, port 0 pins can be used as lower order address-
data multiplexed pins (AD7-AD0)
Internal circuitry of port 0 determines how the pins should behave depending on
the instruction to be executed, memory pointers used, value of address and
status of 𝐸𝐴 signal.
• When data transfer operation is required:
• Input Pin: Port 0 Circuit
• If D=1
27 • Then:
• Q-bar=0
• Both T1 and T2 OFF
• Thus Pin0.x floats and acts as input
pin
• The pin status may be read when
“Read pin data” signal is activated
internally
• Output Pin:
• An external pull-up resistance must be
connected between Pin 0.X and Vcc, so that
pins of port 0 provides a stable voltage output
• If D=1
• Then:
• Q-bar=0
• Both T1 and T2 OFF
• But Pin0.x will produce valid logic
HIGH state if the external pull-up
resistor is connected
• P0.X=HIGH
• If D=0
• Then:
• Q-bar=1
• T1 OFF and T2 ON
• Thus Pin0.x will produce valid logic
LOW state if external pull-up resistor
is connected
• P0.X=LOW
• The best use of PORT0 is as an input port
28 Port 0 Circuit: Address output operation
• When an external memory has to be connected t0 8051,
PORT0 pins will be used to provide lower order address/data
to port 0 pins
• When address output to external memory operation is
selected:
• No external pull-up resistance is required
• Internal control signals switch the address lines to the
gates of the FET:
• If D=1
• Then:
• Q-bar=0
• T1 ON and T2 OFF
• Thus Pin0.x will produce logic HIGH
• If D=0
• Then:
• Q-bar=1
• T1 OFF and T2 ON
• Thus Pin0.x will produce logic LOW
• After address status is provided on port 0 pins ALE pin
status will change accordingly.
• After ALE again goes low the pins of port 0 are turned
around to be data pins again.
• To read data, internal control logic sets the port pins to
logic -1 (configured as input).
• To write data port latches will supply required logic
states to be written to external memory connected.
29 PORT 1 Circuit
30 PORT 2 Circuit
PORT 3 Circuit
31