8051 Microcontroller
8051 Microcontroller
MICROCONTROLLER
UCTI
Introduction
• Embedded Systems
– Operations managed behind the scenes by a
microcontroller
• Microcontroller (MCU)
– An integrated electronic computing device that
includes three major components on a single chip
• Microprocessor (MPU)
• Memory
• I/O (Input/Output) ports
Microcontroller Block diagram
UNIQUE FEATURES -8051
• Internal ROM & RAM
• I/O Ports with programmable pins
• Timers and counters
• Serial data communication
ARCHITECTURE OF 8051
• 8-bit CPU with A & B registers
• 16-bit PC & DPTR
• 8-bit PSW
• 8-bit SP
• Internal ROM – 4k bytes
• Internal RAM – 128 bytes
– 4 register banks ( each 8 registers)
– 16 bytes (bit addressable)
– 8 bytes of general purpose data memory
ARCHITECTURE OF 8051
• 32 I/O pins (port 0 – 3)
• Two 16-bit timer/counter (T0 and T1)
• Control register
(TMOD,TCON,SCON,PCON,IP&IE)
• Two external & internal interrupt sources
• Oscillator & clock circuits.
ARCHITECTURE OF 8051
Port-0
• pins of Port 0 can be used as universal
input/output, if external memory is not used.
• If external memory is used, P0 behaves as
address output (A0 – A7) when ALE pin is at
high logical level, or as data output (Data Bus)
when ALE pin is at low logical level.
Port 1
• Each of these pins can be used as either input
or output according to your needs. Also, pins 1
and 2 (P1.0 and P1.1) have special functions
associated with Timer 2.
Port 2
• If external memory is not present, pins of Port
2 act as universal input/output.
• If external memory is present, this is the
location of the higher address byte, i.e.
addresses A8 – A15. It is important to note
that in cases when not all the 8 bits are used
for addressing the memory (i.e. memory is
smaller than 64kB), the rest of the unused bits
are not available as input/output.
Port 3
• As with Port 1, each of these pins can be used as universal input or output.
• However, each pin of Port 3 has an alternative function:
• Pin 10: RXD - serial input for asynchronous communication or serial output
for synchronous communication.
• Pin 11: TXD - serial output for asynchronous communication or clock output
for synchronous communication
• Pin 12: INT0 - input for interrupt 0
• Pin 13: INT1 - input for interrupt 1
• Pin 14: T0 - clock input of counter 0
• Pin 15: T1 - clock input of counter 1
• Pin 16: WR - signal for writing to external (add-on) RAM memory
• Pin 17: RD - signal for reading from external RAM memory
CLOCK PINS
• XLAT1 and XLAT2
• Range – 1MHz – 16MHz
• T inst = C x 12 / Crystal frequency
• Input and output of internal oscillator.
• Quartz crystal controlling the frequency commonly connects
to these pins. Capacitances within the oscillator mechanism
(see the image) are not critical and are normally about 30pF.
• Instead of a quartz crystal, miniature ceramic resonators can
be used.
• In that case, manufacturers recommend using somewhat
higher capacitances (about 47 pF). New MCUs work at
frequencies from 0Hz to 50MHz+.
PIN 29: PSEN (Program Store Enable)
• MCU activates this bit (brings to low state)
upon each reading of byte (instruction) from
program memory. If external ROM is used for
storing the program, PSEN is directly
connected to its control pins.
PIN 31: EA (External Access)
• Bringing this pin to the logical state zero (mass)
designates the ports P2 and P3 for transferring
addresses regardless of the presence of the
internal memory.
• This means that even if there is a program loaded
in the MCU it will not be executed, but the one
from the external ROM will be used instead.
Conversely, bringing the pin to the high logical
state causes the controller to use both memories,
first the internal, and then the external (if
present).
PIN 30-ALE
• Before each reading of the external memory, MCU sends
the lower byte of the address register (addresses A0 – A7)
to port P0 and activates the output ALE. External register
(74HCT373 or 74HCT375 circuits are common), memorizes
the state of port P0 upon receiving a signal from ALE pin,
and uses it as part of the address for memory chip.
• During the second part of the mechanical MCU cycle,
signal on ALE is off, and port P0 is used as Data Bus. In this
way, by adding only one cheap integrated circuit, data
from port can be multiplexed and the port simultaneously
used for transferring both addresses and data.
PROGRAM COUNTER
• 16 bit register
• Hold address of byte in memory
• Automatically incremented
• Only register with no internal address
DPTR
• 16 bit register (DPH, DPL)
• No single address
• Two individual byte addresses for DPH and
DPL
A- REGISTER
• Accumulator
• 8 bit register
• Used for many (Arithmetic, logical & Bit
manipulation) operations
• Also used for all data t/f b/w 8051 & ext.
Memory
B- REGISTER
• Used for multiplication and division along with
A register
• Also used to hold data.
Program Status Word-PSW
FLAGS
• Math flags – CY, AC,
OV, P
• General purpose user
flags – F0, GF0, GF1
CY AC F0 RS0 RS1 OV - P
MEMORY