Module 4
Module 4
8051 ARCHITECTURE
INTRODUCTION TO
INTEL MCS 51 µC
1
INTEL MCS 51 MICROCONTROLLER
MODULE - 2 2
INTEL MCS 51 MICROCONTROLLER
FEATURES
8-bit CPU
64K bytes on-chip program memory (ROM)
128 bytes on-chip data memory (RAM)
32 I/O pins arranged as four 8-bit ports (P0 - P3)
32 general purpose registers each of 8-bit
Special Function Registers (SFRs) of 128 bytes
16-bit Program Counter
8-bit Processor Status Word (PSW) & Stack Pointer
Two 16-bit timer/counters : T0 and T1
Two external and three internal vectored interrupts
One full duplex serial I/O (UART)
MODULE - 2 3
INTEL MCS 51 MICROCONTROLLER
MODULE - 2 4
INTEL MCS 51 MICROCONTROLLER
MODULE - 2 6
INTEL MCS 51 MICROCONTROLLER
ATMEL
ANALOG DEVICES
ST MICROELECTRONICS
DALLAS
MAXIM
SILICON LABS
TEXAS INSTRUMENTS
MICROCHIP
ZILOG
MODULE - 2 7
INTEL MCS 51 MICROCONTROLLER
AT89C2051 2K 128 32 3 8 3V 20
AT89LV51 4K 128 32 2 6 3V 40
AT89LV52 8K 128 32 3 8 3V 40
MODULE - 2 8
8051
MICROCONTROLLER
PIN DETAILS
8051 MICROCONTROLLER PIN DETAILS
MODULE - 2 10
8051 MICROCONTROLLER PIN DETAILS
The other two pins, PSEN and ALE, are used mainly in 8031-
based systems.
MODULE - 2 11
8051 MICROCONTROLLER PIN DETAILS
8051 SCHEMATICS
MODULE - 2 12
8051 MICROCONTROLLER PIN DETAILS
MODULE - 2 13
8051 MICROCONTROLLER PIN DETAILS
Pin-40 : Vcc is the main power source. Usually its +5V DC.
MODULE - 2 14
8051 MICROCONTROLLER PIN DETAILS
MODULE - 2 17
8051 MICROCONTROLLER PIN DETAILS
MODULE - 2 18
8051
MICROCONTROLLER
ARCHITECTURE
8051 MICROCONTROLLER
ARCHITECTURE
8051 ARCHITECTURE (Simplified)
MODULE - 2 19
8051 MICROCONTROLLER
ARCHITECTURE
8051
ARCHITECTURE
(Detailed)
MODULE - 2 20
8051 MICROCONTROLLER
ARCHITECTURE
CENTRAL PROCESSING UNIT (CPU)
Central Processor Unit (CPU) is the brain of any processing
device of the microcontroller.
The User has no control over the work of the CPU directly.
Two external interrupts (INT0 & INT1), two timer (TF0 &
TF1) interrupts and one serial port (RI / TI) interrupt.
The 8051 has two types of memory and these are Program
Memory and Data Memory.
MODULE - 2 33
8051 MEMORY ORGANIZATION
DATA MEMORY – REGISTER BANKS
Registers are used to store data or operands during executions.
Register banks form the lowest 32 bytes on internal RAM
memory.
At a time only one register bank is selected (using RS1 & RS0
bits in PSW register) for operations and the registers inside the
selected bank are accessed using mnemonics R0..R1.. etc.
MODULE - 2 36
8051 MEMORY ORGANIZATION
DATA MEMORY – BIT ADDRESSABLE AREA
The 8051 supports a special feature which allows access to
bit variables. This is where individual memory bits in Internal
RAM can be set or cleared.
The Bit Addressable area of the RAM is 16 bytes (128 bits)
next to register banks of Internal RAM located between 20h
and 2Fh. In all there are 128 bits numbered 00h to 7Fh.
Being bit variables any one variable can have a value 0 or 1.
A bit variable can be set with a command such as SETB and
cleared with a command such as CLR.
MODULE - 2 37
8051 MEMORY ORGANIZATION
DATA MEMORY – BIT ADDRESSABLE AREA
MODULE - 2 38
8051 MEMORY ORGANIZATION
DATA MEMORY – BIT ADDRESSABLE AREA
Example instructions are
SETB 25h ; sets the bit 25h (becomes 1)
CLR 25h ; clears bit 25h (becomes 0)
Each SFR has a very specific function. Note some of the SFR
registers are bit addressable.
Each SFR has an address (within the range 80h to FFh) and a
name which reflects the purpose of the SFR.
MODULE - 2 42
8051 MEMORY ORGANIZATION
DATA MEMORY – SFRs
Although 128 byes of the SFR address space is defined only
21 SFR registers are defined in the standard 8051.
MODULE - 2 44
8051 MEMORY ORGANIZATION
DATA MEMORY – SFRs
MODULE - 2 45
8051 MEMORY ORGANIZATION
SFRs A- Register
MODULE - 2 48
8051 MEMORY ORGANIZATION
SFRs B- Register
It is special 8-bit math register and it is bit and byte
accessible.
It is used in conjunction with A register as an input operand
for ALU to perform multiplication and division operation.
It can also be used as general purpose register to store 8-
bit data.
MODULE - 2 49
8051 MEMORY ORGANIZATION
SFRs - PSW REGISTER
It is 8 bit register and it is bit and byte accessible.
MODULE - 2 51
8051 MEMORY ORGANIZATION
SFRs - PSW REGISTER
CY, the carry flag: This flag is set whenever there is a carry out from
the D7 bit. This flag bit is affected after an 8-bit addition or
subtraction.
F0, the Flag 0 : The PSW.5 and PSW.1 bits are general-purpose
status flag bits and can be used by the programmer for any purpose.
In other words, they are user definable.
MODULE - 2 52
8051 MEMORY ORGANIZATION
SFRs - PSW REGISTER
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.
MODULE - 2 53
8051 MEMORY ORGANIZATION
SFRs - PSW REGISTER
OV, overflow flag:
This flag is set whenever the result of a signed number operation
is too large, causing the high-order bit to overflow into sign bit.
In general, the carry flag is used to detect errors in unsigned
arithmetic operations.
The overflow flag is only used to detect errors in signed
arithmetic operations
P, the parity flag: The parity flag reflects the number of 1 s in the A
(accumulator) register only. If the A register contains an odd number
of 1’s, then P = 1. Therefore, P = 0 if A has an even number of 1s.
MODULE - 2 54
8051 MEMORY ORGANIZATION
SFRs - P0, P1, P2, P3 - Input/Output Registers
There are 4 ports with in total of 32 input/output pins are
available for connection to peripheral environment.
So 4 Input/Output ports named P0, P1, P2 and P3 has got
four corresponding port registers P0, P1, P2 and P3. All 4
port registers are bit as well as byte addressable.
Data must be written into port registers first to send it out
to any other external device through ports.
Similarly any data received through ports must be read from
port registers for performing any operation.
MODULE - 2 55
8051 MEMORY ORGANIZATION
SFRs - P0, P1, P2, P3 - Input/Output Registers
MODULE - 2 56
8051 MEMORY ORGANIZATION
SFRs - P0, P1, P2, P3 - Input/Output Registers
MODULE - 2 57
8051 MEMORY ORGANIZATION
SFRs - P0, P1, P2, P3 - Input/Output Registers
Upon reset and power-on, all port bits are set (1), which
means that all appropriate pins will be configured as inputs.
MODULE - 2 58
8051 MEMORY ORGANIZATION
SFRs - DPTR REGISTER
It is a 16 bit register used to hold address of external or
internal RAM where data is stored or result is to be stored.
It can be divided into two 8-bit registers, DPH-data pointer
higher order and DPL-data pointer lower order.
Each register can be used as general purpose register to
store 8 bit data and can also be used to store memory
location.
It functions as Base register in base relative addressing mode
and indirect jump.
MODULE - 2 59
8051 MEMORY ORGANIZATION
SFRs - DPTR REGISTER
MODULE - 2 60
8051 MEMORY ORGANIZATION
SFRs - STACK POINTER
It is 8-bit register. It is byte addressable.
MODULE - 2 62
8051 MEMORY ORGANIZATION
PC - PROGRAM COUNTER (not a part of SFRs)
MODULE - 2 63
8051 MACHINE CYCLE
8051 MACHINE CYCLES
MACHINE CYCLES
The CPU takes a certain number of clock cycles to execute
an instruction.
MODULE - 2 64
8051 MACHINE CYCLES
MACHINE CYCLES
Pulse - One complete oscillation of the clock source; State -
Two pulses; Machine Cycle - six states.
MODULE - 2 65
8051 MACHINE CYCLES
MACHINE CYCLES
If an instruction takes one machine cycle to execute, it will
take 12 pulses of the crystal to execute.
The 8051 also has two really slow instructions that require a
full 4 cycles to execute-those instructions you’d find
performance to be about 230,395 instructions per second.
MODULE - 2 67
8051 MACHINE CYCLES
EXAMPLE - 1
Lets find the time period of the machine cycle in each case for the
following crystal frequency of different 8051 based systems: 11.0592
MHz, 16 MHz, 20 MHz.
Answer:
11.0592 MHz:
11.0592/12 = 921.6 KHz
Machine cycle = 1/921.6 KHz = 1.085us [us=microsecond]
16 MHz:
16MHz/12 = 1.333 MHz
Machine cycle = 1/1.333 MHz = 0.75us [us=microsecond]
20MHz:
20MHz/12 = 1.66 MHz
Machine Cycle = 1/1.66 MHz = 0.60us [us=microsecond]
MODULE - 2 68
8051 MACHINE CYCLES
EXAMPLE - 2
Lets find how long it takes to execute each of the following
instructions, for a crystal frequency of 11.0592 MHz. The machine
cycle of a system of 11.0592.z is 1.085 us
INSTRUCTION MACHINE CYCLE TIME TO EXECUTE
MOV R2,#55H 1 1x1.085 us = 1.085 us
DEC R2 1 1x1.085 us = 1.085 us
DJNZ R2,target 2 2x1.085 us = 2.17 us
LJMP 2 2x1.085 us = 2.17 us
SJMP 2 2x1.085 us = 2.17 us
NOP 1 1x1.085 us = 1.085 us
MUL AB 4 4x1.085 us = 4.34 us
MODULE - 2 69
ADDRESSING
MODES
48
ADDRESSING MODES
Addressing mode is a way to address an operand. Operand
means the data we are operating upon.
MODULE - 3 49
ADDRESSING MODES
IMMEDIATE ADDRESSING MODE
This addressing mode is named as “immediate” because it
transfers an 8-bit data immediately to the accumulator
(destination operand).
MODULE - 3 51
ADDRESSING MODES
IMMEDIATE ADDRESSING MODE
The opcode for MOV A, # data is 74H. The opcode is saved in
program memory at 0202 address. The data 6AH is saved in
program memory 0203.
When the opcode 74H is read, the next step taken would be to
transfer whatever data at the next program memory address
(here at 0203) to accumulator A (E0H is the address of
accumulator).
In the figure register 04H holds the data 1FH. So the data
1FH is moved to accumulator.
MODULE - 3 53
ADDRESSING MODES
DIRECT ADDRESSING MODE
MODULE - 3 54
ADDRESSING MODES
DIRECT ADDRESSING MODE
MODULE - 3 57
ADDRESSING MODES
REGISTER ADDRESSING MODE
MODULE - 3 58
ADDRESSING MODES
REGISTER INDIRECT ADDRESSING MODE
MODULE - 3 60
ADDRESSING MODES
REGISTER INDIRECT ADDRESSING MODE
The opcode for MOV A, @R0 is E6H. Assuming that register
bank #0 is selected. So the R0 of register bank #0 holds the
data 20H.
Program control moves to 20H where it locates the data 2FH and
it transfers 2FH to accumulator.
The source operand is @A+DPTR and we will get the source data
(to transfer) from this location.
MODULE - 3 63
ADDRESSING MODES
INDEXED ADDRESSING MODE
The opcode for the instruction is 93H. DPTR holds the value
01FE, where 01 is located in DPH (higher 8 bits) and FE is
located in DPL (lower 8 bits).
MODULE - 3 65