Module 3.1
Module 3.1
Dr.N.Subhashini
Associate Professor,
SENSE, VIT Chennai
MICROPROCESSOR vs MICROCONTROLLER
MICROPROCESSOR vs MICROCONTROLLER
Microprocessor Micro controller
Contains only CPU in a single chip In a single chip has CPU, memory, IO Ports, Timers, Serial ports etc
Designed for high speed operations and has high cost Low speed operations and low cost
Hardware can be interfaced externally based on requirements Can handle less hardware externally
bidirectional
Parameters Von Neumann Harvard
Data and Program(Code) are stored in Data and Program(Code) are stored in
Memory the same memory different memory
Memory Type It has only RAM for data and Code It has RAM for Data and ROM for Code
Buses Common bus for address & data/code Separate bus for Address , data & code
code is executed serially and takes more code is executed in parallel with data so it
Program Execution cycles takes less cycles
Data/Code Transfer Data or code in one cycle Data and code in one cycle
Control Signals Less More
Space It needs less space It needs more space
Cost Less Costly
RISC and CISC
INTEL MCS 51 MICROCONTROLLER
But later versions, identified by a letter C in their name (e.g., 80C51) used
complementary metal–oxide–semiconductor (CMOS) technology and
consume less power
INTEL MCS 51 MICROCONTROLLER
FEATURES
- 8051 is a complete computer system built on one chip. It has CPU, RAM,
ROM,Serial Port, parallel port Interrupt, Timer on single chip.
- 8-bit CPU
- 12 MHZ clock frequency
- 8 bits of ALU.
- 8 bits of data lines
- 16 bits of address bus
- Harvard architecture ( code in ROM, data in RAM)
-4KB of internal ROM for program storage, 64K bytes of ROM can be
connected externally
-128 bytes on-chip data memory (RAM), 64K bytes of RAM can be connected
externally
-
INTEL MCS 51 MICROCONTROLLER
FEATURES
-32 I/O pins arranged as four 8-bit ports (P0 - P3). These ports are used for
interfacing of peripherals like keyboard, display, stepper motor, LEDs and
switches etc.
-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 ( used for delay generation and for counting)
-Two external and three internal vectored interrupts
-One full duplex serial I/O (UART)
8051 MICROCONTROLLER PIN DETAILS
8051 MICROCONTROLLER PIN DETAILS
They all have 40 pins that are dedicated to various functions such as I/O,
RD, WR, address, data, and interrupts.
0FFFH 7FH
Inst. Decoder
Registers
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.
It reads program written in ROM memory and executes them and do the
expected task of that application.
8051 MICROCONTROLLER ARCHITECTURE
INTERRUPT CONTROL
There are five interrupt sources in 8051 Microcontroller and interrupt
control section control all these interrupts.
Two external interrupts (INT0 & INT1), two timer (TF0 & TF1) interrupts
and one serial port (RI / TI) interrupt.
All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which
can be configured as input (1) or an output (0), depends on its logic state.
Since the 8051 has an 8-bit architecture, each 16-bit is accessed as two
separate registers of low byte and high byte.
8051 MICROCONTROLLER ARCHITECTURE
SERIAL PORT
Serial port: The 8051 contains one Serial port or UART (Universal
Asynchronous Receiver Transmitter)
Two port pins are used to provide the serial interface P3.0 is the receive
pin (RXD) P3.1 is the transmit pin (TXD)
The 8051 has two types of memory and these are Program Memory and
Data Memory.
The 8051 has 4K (4096 locations) of internal or on-chip ROM. And it can
be expanded up to 64K.
This is used for storing the system program. 212 = 4096, therefore the
internal ROM locations go from 000H to 0FFFH.
In the MCS-51 family, 8051 has 128 bytes of internal data memory and it
allows interfacing external data memory of maximum size up to 64K.
Special 128B
function
registers
128 B 7F
00
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.
There are 4 register banks designated bank #0,#1, #2 and #3. Each bank has 8
registers which are designated as R0,R1…R7.
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.
Bit addressable area is mainly used to store bit variables from application
program, like status of an output device like LED or Motor (ON/OFF) etc.
We need only a bit to store this status and using a complete byte
addressable area for storing this is really bad programming practice, since
it results in wastage of memory.
8051 MEMORY ORGANIZATION
DATA MEMORY – SCRATCH PAD RAM
The scratch pad RAM can be accessed using direct or indirect addressing
modes.
The SFR registers are located within the Internal Memory in the address
range 80h to FFh.
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.
8051 MEMORY ORGANIZATION
DATA MEMORY – SFRs
Although 128 bytes of the SFR address space is defined, only 21 SFR
registers are defined in the standard 8051.
Main function of SFR is to control timers, counters, serial I/O, port I/O,
and peripherals that are present in 8051 microcontroller.
DATA MEMORY – SFRs register
layout
8051 MEMORY ORGANIZATION
8051 MEMORY ORGANIZATION
SFRs
The 21 Special Function Registers of 8051 Microcontroller are categorized in to
seven groups.
The Accumulator holds the result of most of arithmetic and logic operations. It
is also used to store 8 bit data and to hold one of operand of ALU units during
arithmetical and logical operations.
More than half instructions used by the 8051 microcontroller use somehow the
accumulator.
ACC is usually accessed by direct addressing and its physical address is E0H.
8051 MEMORY ORGANIZATION
SFRs A- Register
Accumulator is an 8-bit register and it is both byte and bit addressable.
To access the individual bits of accumulator, use the format ACC.X in the
instruction where “X” denotes bit to be accessed.
8051 MEMORY ORGANIZATION
SFRs B- Register
It contains several status bits that reflects the status of the operation that
is being carried out in the processor.
It has 4 conditional flags or math flags (CY, AC, OV, P)which sets or resets
according to condition of result.
It has 3 control flags (F0, RS0, RS1) by setting or resetting bit required
operation or function can be achieved.
8051 MEMORY ORGANIZATION
SFRs - PSW REGISTER
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.
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.
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.
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.
8051 MEMORY ORGANIZATION
SFRs - P0, P1, P2, P3 - Input/Output Registers
8051 MEMORY ORGANIZATION
SFRs - P0, P1, P2, P3 - Input/Output Registers
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.
8051 MEMORY ORGANIZATION
SFRs - DPTR REGISTER
It is a 16 bit register used to hold address of external Memory
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.
8051 MEMORY ORGANIZATION
SFRs - DPTR REGISTER
8051 MEMORY ORGANIZATION
SFRs - STACK POINTER
It is 8-bit register. It is byte addressable. Stores the address of the stack
memory in the internal RAM.
It is used to hold the internal RAM memory location addresses which are
used as stack memory.
A value stored in the Stack Pointer points to the first free stack address
and permits stack availability.
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.
Stack of 8051
8051 MEMORY ORGANIZATION
PC - PROGRAM COUNTER (not a part of SFRs)
Since we know the crystal is pulsing 11,059,000 times per second and
that one machine cycle is 12 pulses. we can calculate how many
instruction cycles the 8051 can execute per second:
11,059,000 / 12 = 921,583 and 1/ 921,583=1.085µs
• Clk frequency ≈11.059Mhz=11059000 cycles /sec
• 11059000/12= 921583 machine cycles