CT 321: Microcontroller Systems: by Dr. R.J. Mwifunyi
CT 321: Microcontroller Systems: by Dr. R.J. Mwifunyi
4/5/24
2
8051 Microcontroller architecture
Introduction to MCS -51 Family microcontrollers
4/5/24
3
8051 Microcontroller architecture
Introduction to MCS -51 Family microcontrollers
4/5/24
4
8051 Microcontroller architecture
Architectural block Diagram
4/5/24
5
8051 Microcontroller architecture
Architectural block Diagram
q Architecture of 8051 microcontroller has following features
n 4 Kb of ROM is not much at all.
n 128 bytes of RAM (including SFRs) satisfies the user's basic needs.
n 4 ports having in total of 32 input/output lines are in most cases sufficient to
make all necessary connections to peripheral environment.
q The whole configuration is obviously thought of as to satisfy the
needs of most programmers working on development of
automation devices.
q Advantages:
n Nothing is missing and nothing is too much. In other words, it is
and ports which completely use all resources and enable further
upgrade.
4/5/24
6
8051 Microcontroller architecture
Pin diagram and Pin Functions
4/5/24
7
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Pin out Description
n Pins 1-8: Port 1 each of these pins can be configured as an
input or an output.
n Pin 9: RESET A logic one on this pin disables the
microcontroller and clears the contents of most registers. In
other words, the positive voltage on this pin resets the
microcontroller. By applying logic zero to this pin, the program
starts execution from the beginning.
n Pins10-17: Port 3 Similar to port 1, each of these pins can
serve as general input or output. Besides, all of them have
alternative functions:
4/5/24
8
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Pin out Description
n Pin 10: RXD Serial asynchronous communication input or
Serial synchronous communication output.
n Pin 11: TXD Serial asynchronous communication output or
Serial synchronous communication clock output.
n Pin 12: INT0 Interrupt 0 inputs.
n Pin 13: INT1 Interrupt 1 input.
n Pin 14: T0 Counter 0 clock input.
n Pin 15: T1 Counter 1 clock input.
n Pin 16: WR Write to external (additional) RAM.
n Pin 17: RD Read from external RAM.
4/5/24
9
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Port 3
4/5/24
10
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Pin 18, 19: X2, X1 Internal oscillator input and
output.
q A quartz crystal which specifies operating frequency
(normally 12 MHz) is usually connected to these pins.
q
4/5/24
11
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Pin 20: GND Ground.
n Pin 21-28: Port 2 If there is no intention to use
external memory then these port pins are
configured as general inputs/outputs.
q In case external memory is used, the higher address
byte, i.e. addresses A8-A15 will appear on this port.
q Even though memory with capacity of 64Kb is not used,
which means that not all eight port bits are used for its
addressing, the rest of them are not available as
inputs/outputs.
4/5/24
12
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Pin out Description
n Pin 29: PSEN If external ROM is used for storing program then
a logic zero (0) appears on it every time the microcontroller
reads a byte from memory.
n Pin 30: ALE(Address Latch Enable). Prior to reading from
external memory, the microcontroller puts the lower address
byte (A0-A7) on P0 and activates the ALE output. After
receiving signal from the ALE pin, P0 used as a memory chip
address. Immediately after that, the ALE pin is returned its
previous logic state and P0 is now used as a Data Bus.
n In other words, this port is used for both data and address
transmission.
n Generally , it is used for demultiplexing the address and data
signal of Port 0.
4/5/24
13
8051 Microcontroller architecture
Pin diagram and Pin Functions
n Pin out Description
n Pin 31: EA-External Access input is used to enable or disable
external memory interfacing. If there is no external memory
requirement, this pin is always held high.
n Pin 32-39: Port 0 Similar to P2, if external memory is not used,
these pins can be used as general inputs/outputs.
n Otherwise, P0 is configured as address output (A0-A7) when
the ALE pin is driven high (1) or as data output (Data Bus)
when the ALE pin is driven low (0).
n Pin 40: VCC +5V power supply.
4/5/24
14
8051 Microcontroller architecture--Registers
q Register are used to store information temporarily, while the
information could be
n a byte of data to be processed, or
n an address pointing to the data to be fetched
q The vast majority of 8051 register are 8-bit registers
n There is only one data type, 8 bits
q The 8 bits of a register are shown from MSB D7 to the LSB
D0
n With an 8-bit data type, any data larger than 8 bits must be
broken into 8-bit chunks before it is processed
4/5/24
15
8051 Microcontroller architecture--Registers
q Types
n General Purpose Registers
n Special Purpose Registers
4/5/24
16
8051 Microcontroller architecture
Special Function Registers
q Special Function Registers (SFRs) are a sort of control table used
for running and monitoring the operation of the microcontroller.
4/5/24
17
8051 Microcontroller architecture
Special Function Registers
q Each of these registers as well as each bit they include,
has its name, address in the scope of RAM and
precisely defined purpose such as timer control,
interrupt control, serial communication control etc.
4/5/24
18
8051 Microcontroller architecture
Special Function Registers
q Most of the 128 addresses from 80H to FFH are not
defined except 21.
q Rest of locations is intentionally left unoccupied in order to
4/5/24
19
8051 Microcontroller architecture
Special Function Registers
q Example
q SETB 0EOH
4/5/24
20
8051 Microcontroller architecture
Special Function Registers
n Program Status Word (PSW) Register
4/5/24
21
8051 Microcontroller architecture
Special Function Registers
n Program Status Word (PSW) Register
n PSW register is one of the most important SFRs.
n PSW is at address D0H contains status bits.
n It contains several status bits that reflect the current state of the
CPU.
n Besides, this register contains Carry bit, Auxiliary Carry, two register
bank select bits, Overflow flag, parity bit and user-definable status
flag.
n P - Parity bit. If a number stored in the accumulator has odd number
of 1s then this bit will be automatically set (1), otherwise it will be
cleared (0).
n It is mainly used during data transmit and receive via serial
communication.
n Bit 1. This bit is intended to be used in the future versions of
microcontrollers.
4/5/24
22
8051 Microcontroller architecture
Special Function Registers
n Program Status Word (PSW) Register
n OV Overflow occurs when the result of an arithmetical operation is
larger than 255 and cannot be stored in one register. Overflow
condition causes the OV bit to be set (1). Otherwise, it will be cleared
(0).
4/5/24
23
8051 Microcontroller architecture
Special Function Registers
n Program Status Word (PSW) Register
n RS0, RS1 - Register bank select bits. These two bits are used to
select one of four register banks of RAM. By setting and clearing
these bits, registers R0-R7 are stored in one of four banks of RAM.
Enabling register bank 3
4/5/24
24
8051 Microcontroller architecture
Special Function Registers
n Program Status Word (PSW) Register
n CY - Carry Flag is the (ninth) auxiliary bit used for all arithmetical
operations and shift instructions.
4/5/24
25
8051 Microcontroller architecture
Special Function Registers
4/5/24
26
8051 Microcontroller architecture
Special Function Registers
4/5/24
27
8051 Microcontroller architecture
Special Function Registers
n Stack Pointer (SP) Register
n A value stored in the Stack Pointer, points to the first free stack
address and permits stack availability.
n Stack operations includes “pushing” data on the stack and “popping”
data off the stack
n Pushing increment the value in the Stack Pointer by 1 before writing
data.
n Likewise, Popping from the stack reads data and then decrement
the SP.
n Upon any reset and power-on, the value 7 is stored in the Stack
Pointer, which means that the space of RAM reserved for the stack
starts at this location.
n If another value is written to this register, the entire Stack is moved to
the new memory location.
4/5/24
28
8051 Microcontroller architecture
Special Function Registers
n Stack Pointer (SP) Register
n The 8051 stack is kept in internal RAM and is limited to addresses
accessible by indirect addressing modes.
n Example: Initialize the stack at 60H, the following instruction is used
n MOV SP, #5FH
4/5/24
29
8051 Microcontroller architecture
Special Function Registers
4/5/24
30
8051 Microcontroller architecture
Special Function Registers
n SETB P1.7
n Might turn the motor on , and
n CLR P1.7
n Might turn off
n These instructions the same
4/5/24
32
8051 Microcontroller architecture
Special Function Registers
n Timer Registers
n The 8051 microcontroller has 2 timers/counters (16-bit) called T0 and
T1.
n Their main purpose is to measure time and count external events
and also for generating clock pulses to be used in serial
communication, so called Baud Rate.
n If the timer is properly programmed, the value stored in its register
will be incremented (or decremented) with each coming pulse, i.e.
once per each machine cycle.
4/5/24
33
8051 Microcontroller architecture
Special Function Registers
4/5/24
34
8051 Microcontroller architecture
Special Function Registers
n Interrupt Registers
4/5/24
35
8051 Microcontroller architecture
Special Function Registers
4/5/24
36
8051 Microcontroller architecture
Special Function Registers
n The R Registers (R0-R7)
q This is a name for 8 general-purpose registers (R0, R1, R2
...R7).
q They occupy 4 banks within RAM and are used for temporary
storing variables and intermediate results during operation.
q The active banks depend on two bits of the PSW Register.
q Active bank is a bank the registers of which are currently used.
4/5/24
37
8051 Microcontroller architecture
Special Function Registers
n The R Registers (R0-R7)
q Suppose it is necessary to perform some arithmetical
operations upon numbers previously stored in the R registers:
(R1+R2) - (R3+R4). A register for temporary storing results of
addition is needed.
q This is how it looks in the program:
n MOV A,R3; Means: move number from R3 into accumulator
n ADD A,R4; Means: add number from R4 to accumulator (result remains
in accumulator)
n MOV R5,A; Means: temporarily move the result from accumulator into
R5
n MOV A,R1; Means: move number from R1 to accumulator
n ADD A,R2; Means: add number from R2 to accumulator
n SUBB A,R5; Means: subtract number from R5 (there are R3+R4)
4/5/24
38
8051 Microcontroller architecture
Special Function Registers
n The R Registers (R0-R7)
q Example: The following three instructions enable the register
bank3 and then move the contents of R7 to the accumulator
4/5/24
39
8051 Microcontroller architecture-Oscillator and clock circuit
n The 8051 requires an external oscillator circuit.
n The oscillator circuit usually runs around 12 MHz, although the
effective cycle rate at 1 MHz (for a 12 MHz clock) to 3.33 MHz (for
the maximum 40 MHz clock).
n The oscillator circuit generates the clock pulses so that all
4/5/24
40
8051 Microcontroller architecture--Reset circuit
q The 8051 is reset by holding RST high for at least two machine
cycles and then returning it low.
q RST may be manually activated using a switch, or may be
activated upon power-up using a R-C (Resister-capacitor) network
4/5/24
41
8051 Microcontroller architecture--Reset circuit
q The state of all the 8051 registers after a system reset is as follows
q The most important of these registers, perhaps, is the program counter, which
is loaded with 000H.
q When RST returns low, program execution always begins at the first location
in code memory: address 000H.
q The content of on-chip RAM is not affected by reset operation.
4/5/24
42
8051 Microcontroller architecture--I/O Port circuits
q All 8051 microcontrollers have 4 I/O ports each comprising
8 bits which can be configured as inputs or outputs.
q Accordingly, in total of 32 input/output pins enabling the
4/5/24
43
8051 Microcontroller architecture--I/O Port circuits
q Similarly, in order to configure a microcontroller pin as an
input, it is necessary to apply a logic one (1) to appropriate
port.
q In this case, voltage level on appropriate pin will be 5V (as
4/5/24
44
8051 Microcontroller architecture-- Memory organization
q Most microprocessors implements a shared memory
space for data and programs.
q This is reasonable, since programs are usually stored on a
disk and loaded into RAM for execution; thus the data and
programs resides in the system RAM
q Microcontrollers on the other hand are rarely used as the
control-oriented design.
q There is limited memory, and there is no disk drive or disk
operating system.
q The control program must reside in ROM.
4/5/24
45
8051 Microcontroller architecture-- Memory organization
q The 8051 has two types of memory and these are Program
Memory and Data Memory.
q Program Memory (ROM) is used to permanently save the
program being executed, while Data Memory (RAM) is used for
temporarily storing data and intermediate results created and
used during the operation of the microcontroller.
q Depending on the model in use (we are still talking about the 8051
microcontroller family in general) at most a few Kb of ROM and 128
or 256 bytes of RAM is used.
q However…All 8051 microcontrollers have a 16-bit addressing bus
and are capable of addressing 64 kb memory.
q It is neither a mistake nor a big ambition of engineers who were
working on basic core development.
q It is a matter of smart memory organization which makes these
microcontrollers a real “programmers’ goody“.
4/5/24
46
8051 Microcontroller architecture-- Memory organization
q Program Memory (ROM)
n All models have a few Kbyte ROM embedded though a memory
state:
n EA= 0 -; the microcontroller ignores internal program memory and executes
only the program stored in external memory.
n EA = 1; the microcontroller executes first the program from built-in ROM
and then the program stored in external memory.
4/5/24
47
8051 Microcontroller architecture-- Memory Organization
4/5/24
48
8051 Microcontroller architecture-- Memory organization
q Data memory: is used to store data temporarily.
q RAM in 8051 family has many registers such as hardware counters
and timers, input/output ports, serial data buffers etc.
q The first block consists of 4 banks each including 8 registers denoted
by R0-R7.
q The next memory block (address 20h-2Fh) is bit- addressable which
means that each bit has its own address (0-7Fh).
q Since there are 16 such registers, this block contains in total of 128
bits with separate addresses.
q The third group of registers occupies addresses 2Fh-7Fh.
4/5/24
49
8051 Microcontroller architecture-- Memory organization
q Data memory.
4/5/24
50
8051 Microcontroller architecture-- Memory organization
q Internal memory
q The internal memory consists of on-chip ROM and on-chip RAM.
q The on-chip RAM contains a rich arrangement of general purpose
storage, bit-addressable storage, register banks and special
function registers.
4/5/24
51
8051 Microcontroller architecture-- Memory organization
q Internal memory---- 8031 Memory Space
4/5/24
52
8051 Microcontroller architecture-- Memory organization
q Internal memory---- 8051 On-chip data memory
4/5/24
53
8051 Microcontroller architecture-- Memory organization
q Internal memory----General Purpose RAM
4/5/24
54
8051 Microcontroller architecture-- Memory organization
q Internal memory----Bit Addressable RAM
q Not that “bit address 67H” is the MSB at “byte address 2CH”
4/5/24
55
8051 Microcontroller architecture-- Memory organization
q Internal memory----Register Banks
4/5/24
56
8051 Microcontroller architecture-- Memory organization
q Memory expansion—External memory
q It is important that microcontrollers have expansion
4/5/24
57
8051 Microcontroller architecture-- Memory organization
q Memory expansion—External memory
q Peripheral interface ICs can also be added to expand the
I/O capability.
q When external memory is used, Port 0 is unavailable as an
I/O port.
q It becomes multiplexed address (A0-A7) and data (D0-D7)
4/5/24
58
8051 Microcontroller architecture-- Memory organization
q Memory expansion—External memory
q Multiplexing the address and data buses
4/5/24
59
8051 Microcontroller architecture-- Memory organization
q Memory expansion—External memory
q Multiplexing the address and data buses
q
• During first half of the cycle,
the low-byte of the address is
provided on Port 0 and is
latched using ALE.
• A 74HC373 latch holds the
low-byte of the address stable
for the duration of the memory
cycle.
• During second half of the
memory cycle, Port 0 is used
as data bus and data are read
or written depending on the
operation.
4/5/24
60
8051 Microcontroller architecture-- Memory organization
q Memory expansion
4/5/24
61
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- accessing the external Code Memory
q External code memory is read-only memory enabled by the PSEN signal.
q When external EPROM is used, ports 0 and 2 are unavailable as general
purpose I/O ports.
q The hardware connections for external EPROM memory is as follows
4/5/24
62
8051 Microcontroller architecture-- Memory organization
n
4/5/24
63
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- accessing the external Code Memory
4/5/24
64
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- accessing the external Data Memory
q External Data memory is read/write memory enabled by RD and
WR-the alternative pin functions for P3.7 and P3.6.
q The only access to external memory is with the MOVX instruction,
using the 16-bit data pointer (DPTR), R0 or R1 as address register.
q RAMs may be interfaced to the 8051 the same way as EPROM
except thar RD line connect to the RAM’s output enable OE line
and WR connect to the RAM’s write W line.
q The connectios for the address and data bus are the same as for
EPROMs.
q Using Ports 0 and 2, up to 64K bytes data RAM can be connected
to 8051.
4/5/24
65
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- accessing the external Data Memory
q Example: a 1K byte RAM interfaced to the 8051
Interface to 1K RAM
4/5/24
66
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- accessing the external Data Memory
q A timing diagram for a read operation to external data memory is
as follows
4/5/24
67
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- Address decoding
4/5/24
68
8051 Microcontroller architecture-- Memory organization
q Memory expansion--- Address decoding
q Example of system with multiple 2764 EPROMs and 6264 8K
RAMs
4/5/24
69
8051 Microcontroller architecture
q Reading Assignment
q General Purpose Registers
q Power Control Registers
q Overlapping the External Code and Data Spaces
4/5/24
70
End!!!!
4/5/24 71