UNIT I
MICROCONTROLLER
EMBEDDED SYSTEM & ARCHITECTURE OF 8051
Embedded system
1. Embedded system
2. Characteristics of Embedded system
3. Structure of Embedded system
4. Processor in Embedded system
5. Microprocessor - Microcontroller
6. Microprocessor vs Microcontroller.
7. Compiler – cross compiler
8. Assembler – Simulator - Emulator
9. Criteria for choosing microcontroller for embedded application
10. 8051 family members comparison
EMBEDDED SYSTEM & ARCHITECTURE OF 8051
Architecture of 8051
1. Features of 8051 Microcontroller
2. Pin details of 8051
3. Block diagram of 8051 Microcontroller
4. Functions of each block
5. ALU
6. ROM
7. RAM
8. Special function registers
9. Program Counter
10.PSW register
11.Stack
EMBEDDED SYSTEM & ARCHITECTURE OF 8051
Architecture of 8051
12. I/O Ports
13. Timer
14. Interrupt
15. Serial Port
16. Memory Organization of 8051
17.Oscillator and Clock - Clock Cycle – State - Machine Cycle –Instruction cycle
18.Reset – Power on Reset
19.Overview of 8051 family
SYSTEM
A system is an arrangement in which all its unit assemble work
together according to a set of rules.
It can also be defined as a way of working, organizing or doing
one or many tasks according to a fixed plan.
Example:
A watch is a time displaying system. Its components follow a set
of rules to show time. If one of its parts fails, the watch will stop
working. So we can say, in a system, all its subcomponents
depend on each other.
EMBEDDED SYSTEM
An embedded system is a microcontroller or microprocessor
based system which is designed to perform a specific task.
Example:
A fire alarm is an embedded system; it will sense only smoke.
EMBEDDED SYSTEM
An embedded system has three components:
It has hardware.
It has application software.
It has Real Time Operating system (RTOS) that supervises the
application software and provide mechanism to let the processor
run a process as per scheduling by following a plan to control
the latencies. RTOS defines the way the system works. It sets
the rules during the execution of application program. A small
scale embedded system may not have RTOS.
An embedded system as a Microcontroller based, software
driven, reliable, real-time control system
CHARACTERISTICS OF EMBEDDED SYSTEM
Single-functioned
An embedded system usually performs a specialized operation
and does the same repeatedly.
Tightly constrained –
All computing systems have constraints on design metrics, but
those on an embedded system can be especially tight. Design
metrics is a measure of an implementation's features such as its
cost, size, power, and performance. It must be of a size to fit on
a single chip, must perform fast enough to process data in real
time and consume minimum power to extend battery life.
CHARACTERISTICS OF EMBEDDED SYSTEM
Reactive and Real time –
Many embedded systems must continually react to changes in
the system's environment and must compute certain results in
real time without any delay.
CHARACTERISTICS OF EMBEDDED SYSTEM
Microprocessors based – It must be microprocessor or
microcontroller based.
Memory – It must have a memory, as its software usually
embeds in ROM. It does not need any secondary memories in
the computer.
Connected – It must have connected peripherals to connect
input and output devices.
HW-SW systems – Software is used for more features and
flexibility. Hardware is used for performance and security.
ASIP – Application specific instruction set processor
ASIC – Application specific integrated circuit
CHARACTERISTICS OF EMBEDDED SYSTEM
Advantages
1. Easily Customizable
2. Low power consumption
3. Low cost
4. Enhanced performance
Disadvantages
1. High development effort
2. Larger time to market
STRUCTURE OF EMBEDDED SYSTEM
The figure shows the basic structure of an embedded system
STRUCTURE OF EMBEDDED SYSTEM
Sensor – It measures the physical quantity and converts it to an
electrical signal which can be read by an observer or by any
electronic instrument like an A/D converter. A sensor stores the
measured quantity to the memory.
A-D Converter – An analog-to-digital converter converts the
analog signal sent by the sensor into a digital signal.
Processor & ASICs – Processors process the data to measure
the output and store it to the memory.
D-A Converter – A digital-to-analog converter converts the
digital data fed by the processor to analog data.
Actuator – An actuator compares the output given by the D-A
Converter to the actual (expected) output stored in it and stores
the approved output.
PROCESSOR IN EMBEDDED SYSTEM
Processor is the heart of an embedded system. It is the basic unit
that takes inputs and produces an output after processing the
data.
A processor has two essential units:
1. Program Flow Control Unit (CU)
2. Execution Unit (EU)
PROCESSOR IN EMBEDDED SYSTEM
The CU includes a fetch unit for fetching instructions from the
memory. The EU has circuits that implement the instructions
pertaining to data transfer operation and data conversion from
one form to another.
The EU includes the Arithmetic and Logical Unit (ALU) and
also the circuits that execute instructions for a program control
task such as interrupt, or jump to another set of instructions.
A processor runs the cycles of fetch and executes the
instructions in the same sequence as they are fetched from
memory.
TYPES OF PROCESSOR
• Processors can be of the following categories:
General Purpose Processor (GPP)
1. Microprocessor
2. Microcontroller
3. Embedded Processor
4. Digital Signal Processor
5. Media Processor
Application Specific System Processor (ASSP)
Application Specific Instruction Processors (ASIPs)
GPP core(s) or ASIP core(s) on either an Application Specific
Integrated Circuit (ASIC) or a Very Large Scale Integration
(VLSI) circuit
MICROPROCESSOR
A microprocessor is a single VLSI chip having a CPU. In
addition, it may also have other units such as coaches, floating
point processing arithmetic unit, and pipelining units that help in
faster processing of instructions.
Earlier generation microprocessors’ fetch-and-execute cycle was
guided by a clock frequency of order of ~1 MHz. Processors
now operate at a clock frequency of 2GHz
MICROPROCESSOR
MICROCONTROLLER
A microcontroller is a single-chip VLSI unit (also called
microcomputer) which, although having limited computational
capabilities, possesses enhanced input/output capability and a
number of on-chip functional units.
Microcontrollers are particularly used in embedded systems for
real-time control applications with on-chip program memory
and devices.
MICROPROCESSOR VS MICROCONTROLLER
COMPILER
A compiler is a computer program (or a set of programs) that
transforms the source code written in a programming language
(the source language) into another computer language (normally
binary format).
The name "compiler" is primarily used for programs that
translate the source code from a high-level programming
language to a low-level language (e.g., assembly language or
machine code).
CROSS COMPILER
If the compiled program can run on a computer having different
CPU or operating system than the computer on which the
compiler compiled the program, then that compiler is known as
a cross-compiler.
ASSEMBLER
An assembler is a program that takes basic computer
instructions (called as assembly language) and converts them
into a pattern of bits that the computer's processor can use to
perform its basic operations.
An assembler creates object code by translating assembly
instruction mnemonics into opcodes, resolving symbolic names
to memory locations.
Assembly language uses a mnemonic to represent each low-
level machine operation (opcode).
SIMULATOR
Code is tested for the MCU / system by simulating it on the host
computer used for code development. Simulators try to model
the behavior of the complete microcontroller in software.
Functions of Simulators
A simulator performs the following functions –
Defines the processor or processing device family as well as its
various versions for the target system.
Monitors the detailed information of a source code part with labels
and symbolic arguments as the execution goes on for each single
step.
Provides the status of RAM and simulated ports of the target system
for each single step execution.
Monitors system response and determines throughput.
Provides trace of the output of contents of program counter versus
the processor registers.
SIMULATOR
Provides the detailed meaning of the present command.
Monitors the detailed information of the simulator commands as
these are entered from the keyboard or selected from the menu.
Supports the conditions (up to 8 or 16 or 32 conditions) and
unconditional breakpoints.
Provides breakpoints and the trace which are together the
important testing and debugging tool.
Facilitates synchronizing the internal peripherals and delays.
EMULATOR
An emulator is a hardware kit or a software program or can be
both which emulates the functions of one computer system (the
guest) in another computer system (the host), different from the
first one, so that the emulated behavior closely resembles the
behavior of the real system (the guest).
CRITERIA FOR CHOOSING
MICROCONTROLLER
While choosing a microcontroller, make sure it meets the task at
hand and that it is cost effective.
An 8-bit, 16-bit or 32-bit microcontroller can best handle the
computing needs of a task.
The following points should be kept while choosing a
microcontroller –
Speed – speed of the microcontroller.
Packaging – Is it 40-pin DIP (Dual-inline-package) or QFP
(Quad flat package). It is important in terms of space,
assembling, and prototyping the end-product.
CRITERIA FOR CHOOSING
MICROCONTROLLER
Power Consumption – This is an important criteria for battery-
powered products.
Amount of RAM and ROM on the chip.
Count of I/O pins and Timers on the chip.
Cost per Unit – This is important in terms of final cost of the
product in which the microcontroller is to be used.
COMPARISON BETWEEN 8051 FAMILY
MEMBERS
The following table compares the features available in 8051, 8052,
and 8031.
BIT
Bit is the abbreviation for binary digit. The BIT is the smallest
binary (bivalent) information unit, which can accept a signal
status of “1“ or “0“.
1
BYTE
For a unit of 8 binary characters, the term BYTE is used. A byte
has the size of 8 bits.
WORD
A word is a sequence of binary characters, which is regarded as
a unit in a specific connection. The word length corresponds to
the number from 16 binary characters.
FEATURES OF 8051 MICROCONTROLLER
8051 microcontroller with the following features:
64K bytes on-chip program memory (ROM)
128 bytes on-chip data memory (RAM)
Four register banks
128 user defined software flags
8-bit bidirectional data bus
16-bit unidirectional address bus
32 general purpose registers each of 8-bit
16 bit Timers (usually 2, but may have more or less)
Three internal and two external Interrupts
Four 8-bit ports,(short model have two 8-bit ports)
16-bit program counter and data pointer
8051 may also have a number of special features such as UARTs,
ADC
PIN DETAILS OF 8051
PIN DETAILS OF 8051
The 8051 has 40 pin DIP (Dual Inline Package)
Pin- 1to 8: Port 1 (P1.0 – P1.7): Port 1 act as an 8 bit
bidirectional bit /byte addressable port. It has been allotted an
address in the SFR address range.
Pin-9 : RESET pin is used to set the 8051 microcontroller to its
initial values, while the microcontroller is working or at the
initial start of application. To reset the microcontroller ,the reset
pin must be set high for 2 machine cycles.
Pin- 10 to 17: Port 3 (P3.0 – P3.7): Port 3 is an 8 – bit
bidirectional bit / byte addressable I/O port. It has been allotted
an address in the SFR address range. The port 3 pins also serve
the alternate function
PIN DETAILS OF 8051
Port Pins Alternate Function
P3.0 RXD (Serial Input Port)
P3.1 TXD (Serial Output port)
P3.2 INTO (External Interrupt 0)
P3.3 INT1 (External Interrupt 1)
P3.4 T0 (Timer/Counter 0 external input)
P3.5 T1 (Timer/Counter 1 external input)
P3.6 WR (External data memory write strobe)
P3.7 RD (External data memory read strobe)
PIN DETAILS OF 8051
Pins 18 and 19: XTAL1 and XTAL2 : There is an in built
oscillator used for connecting an crystal externally to provide
system clock.
Pin-20 : Vss - Ground
Pins 21 to 28: Port 2 (Port 2.0 to 2.7) : Port 2 pins are used as input
/ output pins similar in operation to port 1.
The alternate use of port 2 is to supply a high order address byte
(A8 – A15) when the microcontroller is connected to external
memory.
Pin- 29: PSEN or Program Store Enable is used to read data from
external program memory.
PIN DETAILS OF 8051
Pin – 30: ALE – Address Latch Enable is an output pin and is
active high.
When connecting an 8051 to external memory port 0 provides both
address and data.. If ALE =0 port 0 provides data (D0 – D7). If
ALE =1 it had address (A0 – A7)
Pin – 31: EA - External Aceess. This pin is connected to either V cc
or Ground (Vss). The 8051has ON - CHIP ROM to store programs.
EA pin is connected to Vcc is in 8051.
In 8031 there is no ON – CHIP ROM code is stored on an external
ROM and is fetched by 8031. EA pin is connected to Vss (Ground)
to indicate that the code is stored externally.
PIN DETAILS OF 8051
Pins 32 to 39: Port 0 (Port 0.7 to 0.0) : Port 0 is used for both
address and data bus (AD0 – AD7). When the microcontroller
chip is connected to an external memory. Port 0 provides both
address and data. ALE pin indicates if port 0 has address or data.
Pin-40 : This pin is named as Vcc Usually +5V DC is given to this
pin.
BLOCK DIAGRAM OF 8051
MICROCONTROLLER
CENTRAL PROCESSING UNIT
The CPU is the brain of the microcontroller reading user’s
programs and executing the expected task as per the instructions
stored.
Its primary element are
1. Accumulator
2. B register
3. Stack Pointer (SP)
4. Program Counter (PC)
5. Program Status Word (PSW)
6. Data Pointer (DP)
ACCUMULATOR
The Accumulator performs arithmetic and logic function on 8
bit input variables.
Arithmetic operation include basic addition, subtraction,
multiplication and division. Logical operations are AND, OR,
XOR as well as rotate, clear, complement etc.
Accumulator is responsible for conditional branching decisions
and provides a temporary place in a data transfer operations with
in the device.
B REGISTER
B register is used in multiply and divide operation. During
execution B register either keeps one of the two inputs and then
retains a portion of the result.
It is used as general purpose register
STACK POINTER
Stack Pointer (SP) is an 8 bit register.
This pointer keeps track of memory space where the important
register information are stored when the program flow gets into
executing a subroutine.
The stack portion may be placed in anywhere in the onchip
RAM..
Normally SP is initialized to 07H after a device reset and grows
up from the location 08H.
The SP is automatically incremented or decremented for all
PUSH or POP instruction and for all subroutines call and
returns.
PROGRAM COUNTER
The Program Counter (PC) is the 16 bit register giving address
of next instruction to be executed during program execution and
it always point to the program memory space.
PROGRAM STATUS WORD (PSW)
It is also one of the special function register.This register
contains program status information.
It is a bit and byte addressable register.
It is also used to select any one of the required register bank.
DATA POINTER
The Data pointer register (DPTR) is the 16 bit addressing
register that can be used to fetch any 8 bit data from the data
memory space.
When it is not being used for this purpose it can be used as two
eight bit register DPH and DPL.
INPUT / OUTPUT PORTS
8051 has 32 I/O pins configured as 4 eight bit parallel ports (P0,
P1, P2, P3)
Each pin can be used as an output under the software control..
These I/O pins can be accessed directly by memory instruction
during program execution.
Port 0 used as a multiplexed address / data bus. At the beginning
of an external memory cycle, low order 8 bits of the address bus
are output on P0. The same pins transfer data byte at the later
stage of the instruction execution.
Any instruction that access external program memory will
output the higher order byte (A8 –A15)on port2 during read
cycle.
Port1 and port 3 are available for standard I/O functions.
INPUT / OUTPUT PORTS
Port 3 has additional functions
TIMERS / COUNTERS
8051 has two 16 bit Timers / Counters, T0 and T1 capable of
working in different modes. Each consist of a HIGH byte and a
LOW byte which can be accessed under software
There is a mode control register (TMOD) and a control register
(TCON) to configure these timers/counters in number of ways.
These timers are used to measure time intervals determine pulse
widths or initiate events with one microsecond upto a maximum
65ms.
Use software to get longer delays.
SERIAL PORT
TXD and RXD are used for serial port. These pins are available
in Port 3. To transmit data serially TXD pin is used. To receive
data serially RXD pin is used .Each pin have separate buffer
registers named SBUF.
INTERRUPT CONTROL
The 8051 has 5 interrupts.
One from the serial port (R1 / T1) when a transmission and
receiving operation is executed.
2 from the timers (TF0 / TF1)
When overflow occurs and two come from the 2 input pins
(INT0 / INT1)
Each interrupt may be independently enabled or disabled and
may be classified as high or low priority.
These operation are selected by Interrupt Enable (IE) and
Interrupt priority (IP) register.
OSCILAATOR
This circuit generates the basic timing clock signal for the
operation of the circuit using crystal oscillator.
ON CHIP ROM
The 8051 has 4 kilobyte of inbuilt ROM. It is otherwise called
program memory. Usually program-code is stored in ROM. To
store program into ROM , programmer is needed. If more area is
required in ROM, an external ROM may be connected.
Maximum of 64kb ROM memory can be used.
ON CHIP RAM
• The 8051 has 128 byte of RAM as inbuilt . Some versions have
256 byte also. It is used as data memory. If the system needs
more memory, external RAM may be connected up to 64kb.In
128 byte RAM chip, 00h to 71Fh are the address range .In this
range ,00H to 1FH are the general purpose registers . 20H to 2F
are the bit Addressable area and rest of this are byte
addressable .This is used as general purpose scratch pad. In 256
byte RAM chip, another 128 byte are used for Special Function
Registers.
BUS CONTROL
In 8051 ,Data Bus has a width of 8 bits and Address Bus has a
width of 16 bits. Lower byte address bus are used for both
Address and data. The bus usage is controlled by BUS control.
There are 3 control signals, EA, PSEN and ALE. These signals
known as External Access (EA), Program Store Enable (PSEN),
and Address Latch Enable (ALE) are used for external memory
interfacing.
ARCHITECTURE OF 8051
ARITHMETIC LOGIC UNIT (ALU)
ALU- Arithmetic and Logic Unit.
Arithmetic and logical operations are carried out. The arithmetic
operations are Addition, Subtraction, multiplication and
Division etc.
The logical operations are AND,OR,XOR etc.
The operations, one operand must be in A register another may
be general purpose register. In multiplication and division ,the
other operand must be in B register.
The result of the arithmetic and logical operations are available
in A register. In multiplication, the low byte answer is in A
register and high byte answer is in B register. In division,
quotient is in A register and remainder is in B register.
Clear, Complement and Rotate are also done in ALU.
SPECIAL FUNCTION REGISTER
Locations 80H to FFH contain the special function registers.
Special Function Registers (SFRs) are registers used for special
functions and the operation of the microcontroller. Each one has
its own name and address.
Only 21 SFR’s in 8051 are available to user. Among the 21
registers, 11 registers are bit and byte addressable. The
remaining 10 are bit addressable . Each one are 8 bit registers .
TMOD,TCON,TH1,TL0,TH1and TH0 are used for Timer
operation .
SCON and SBUF are the SFR’s used for serial communication.
SPECIAL FUNCTION REGISTER
P0,P1,P2 andP3 are used for I/O port.
PCON is used for power control.
IE and IP are used as SFR used for interrupt control.
DPH and DPL are the 8bit SFR,s in DPTR .
A and B registers are also the SFR’s used in instruction .
SPECIAL FUNCTION REGISTER
PROGRAM COUNTER (PC)
The Program Counter (PC) is a 2-byte OR 16 bit register.
It is memory pointer. It holds the address of instruction.
The address in the program counter may be in the range of
0000h to FFFFh.
It is incremented each time an instruction is executed. It is
important to note that PC is not always incremented by one.
Since some instructions require 2 or 3 bytes the PC will be
incremented by 2 or 3 in these cases.
The Program Counter is special .There is no way to directly
modify its value.
PROGRAM STATUS WORD REGISTER
The PSW contains program status information.
It is an 8-bit, byte/bit addressable register.
PROGRAM STATUS WORD REGISTER
CARRY FLAG (CY):
In an arithmetic operation when a carry is generated, the CY
flag is set otherwise it is reset.
The carry flag also serves as a borrow flag for subtraction.
AUXILLIARY CARRY FLAG (AC):
In an arithmetic operation either when a carry is generated from
digit D3 and passed on to digit D4 or a borrow is generated from
bit D4 to bit D3, the Ac flag is set, otherwise it is reset.
PROGRAM STATUS WORD REGISTER
OVER FLOW FLAG (OV):
In an arithmetic operation either when a carry is generated from
digit D7 or a borrow is generated from bit D7 the OV flag is set,
otherwise it is reset.
PARITY FLAG (P):
If the result of an operation has an odd number of 1’s the parity
flag is set, otherwise it is reset.
PROGRAM STATUS WORD REGISTER
REGISTER BANK SELECT BITS:
Bits 3 and 4 of the PSW are used for selecting the register bank.
Since there are four register banks, two bits are required for
selecting a bank.
INPUT / OUTPUT PORTS
8051 has 32 I/O pins configured as 4 eight bit parallel ports (P0,
P1, P2, P3)
Each pin can be used as an output under the software control..
These I/O pins can be accessed directly by memory instruction
during program execution.
Port 0 used as a multiplexed address / data bus. At the beginning
of an external memory cycle, low order 8 bits of the address bus
are output on P0. The same pins transfer data byte at the later
stage of the instruction execution.
Any instruction that access external program memory will
output the higher order byte (A8 –A15)on port2 during read
cycle.
Port1 and port 3 are available for standard I/O functions.
INPUT / OUTPUT PORTS
Port 3 has additional functions
STACK
Stack is a random access memory. The stack may reside
anywhere in the on-chip RAM.
The stack memory is pointed by a 8-bit register called Stack
Pointer. SP is an only byte addressable SFR register.
The stack memory is used by either programmer or
microcontroller.
During the execution of CALL instructions, the microcontroller
automatically stores the content of program counter in the stack
memory. Similarly, by using the PUSH instructions, the
programmer can store the content of any direct addressable
location in the stack memory.
STACK
During the execution of return instruction, the content of stack
memory moves in to the program counter.
Similarly by using the POP instruction, the programmer can
retrieve the content of stack memory to any direct addressable
location.
The content of stack pointer is incremented before data is stored
during the execution of PUSH and CALL instructions.
The stack pointer is initialized to 07H after a reset. This causes
the stack to begin at location 08H.
STACK
STACK
Suppose the instruction PUSH direct, is executed by the
microcontroller, first the stack pointer. is incremented by 1"
(Now the stack pointer contains 08H ).
Then the content of the indicated direct byte location is copied
into the stack memory location 08H.
Suppose, the content of direct byte location is 25, after the
execution of PUSH instruction, the data 25H is moved into the
location 08H.
SERIAL PORT
In serial communication the data is rate is known as the baud
rate. The baud rate simply means the number of bits transmitted
per second.
The 8051 serial port is full duplex. In other words, it can
transmit and receive data at the same time. Shown in the Fig
Diagram of Serial port.
SERIAL PORT
The block diagram above shows SBUF is in fact two distinct
registers - the write-only register and the read-only register.
Transmitted data is sent out from the write-only register while
received data is stored in the read-only register.
There are two separate data lines, one for transmission (TXD)
and one for reception (RXD). Therefore, the serial port can be
transmitting data down the TXD line while it is at the same time
receiving data on the RXD line.
SERIAL PORT
The TXD line is pin 11 of the microcontroller (P3.1) while the
RXD line is on pin 10 (P3.0).
Therefore, external access to the serial port is achieved by
connecting to these pins.
For example, if you wanted to connect a keyboard to the serial
port you would connect the transmit line of the keyboard to pin
10 of the 8051.
If you wanted to connect a display to the serial port you would
connect the receive line of the display to pin 11 of the 8051.
SERIAL PORT
INTERRUPTS
When an interrupt occurs, the microcontroller stops the
execution of main program and its control is immediately
transferred to its corresponding service subroutine.
The microcontroller 8051 provides 5 interrupt sources. They are
INTERRUPTS
All these interrupts are vectored interrupts. when an interrupt
occurs, the control microcontroller is automatically transferred
to its service subroutine.
INTERRUPTS
The external interrupt pins INTO and INT1 can each be either
level activated or transition activated, depending bits ITO and
IT1 in register TCON. The flags that actually generate these
interrupts are bits IE0 and IE1 in TCON.
When an external interrupt is generated, the flag that generated
is cleared by the hardware when the service routine is vectored
to only, If the interrupt was transition activated.
If the interrupt was level activated, then the external requesting
source will control the request flag, rather than on-chip
hardware.
INTERRUPTS
Timer 0 and Timer 1 interrupts are generated by TFO and TF1
in TCON register, which are set by a rollover in their respective
timer counter register.
When a timer interrupt is generated, the flag that generated is
cleared by the on-chip hardware when its control is transferred
to its corresponding service subroutine.
The serial port interrupt is generated by the logical OR of RI and
TI (in SCON register). Neither of these flags are cleared by
hardware when the service routine is vectored to.
The service routine will normally have to determine whether it
was RI or TI that generated the interrupt, and the bit will have to
be cleared only in software.
TIMER/COUNTER
Microcontroller 8051 has two 16-bit timer/ counter registers.
They are timer 0 and timer 1. Both can be configured to operate
either as timers or event counters.
• In the timer function, the register is incremented every machine
cycle. That means, in timer operation it counts the machine
cycles. Since a machine cycle consists of 12 oscillator periods,
the count rate is 1/12 of the oscillator frequency.
• In the counter function, the register is incremented in response
to "1 to 0" transition at its input pin T0 corresponding external
or T1. When the samples show a high in one machine cycle.
And a low in the next machine cycle, the count is incremented.
Since it takes atleast 2 machine cycles (24 oscillator periods) to
recognize a "1 to 0" transition. The maximum count rate is 1/24
of the oscillator frequency.
TIMER/COUNTER
The TMOD, TCON, THO, TLO, TH1 and TL1 special function
registers are used in Timer/Counter functions.
MEMORY ORGANIZATION OF 8051
The microcontroller 8051 has three basic memory address
spaces. They are
i) 64 Kbyte program memory
ii) 64 Kbyte external data memory
iii)256 byte internal data memory
In general ROM type memories are used for program memory
and RAM type memory is used for data memory.
The 64 Kbyte program memory space consists of an internal and
external memory portions.
The data memory address space also consists of an internal and
an external memory spaces.
ROM (PROGRAM MEMORY)
• Program memory can only be read, not written to. There can be
upto 64 Kbytes of program memory.
• In the ROM and EPROM versions, the lowest 4 Kbytes are
provided on-chip. In the ROM less versions all program
memory is external (off-chip).
• The 64 Kbyte program memory space consists of an internal and
external memory portions.
• The memory map structure of program memory is shown in
ROM (PROGRAM MEMORY)
In microcontroller 8051, the lower 4 Kbytes of program memory
can be placed either in the on-chip ROM or in an external ROM.
This selection is made by strapping the EA pin to either Vcc (1)
or Vss (0). lf the EA pin is held high, the program fetches to
addresses 0000H through 0FFFH are directed to the internal
ROM.
Program fetches to addresses 1000H through FFFFH are
directed to the external ROM.
If the EA pin is held low, the microcontroller 8051 fetches all
instructions from external program memory.
PSEN is used for all program fetches. PSEN is not activated for
internal program fetches.
RAM (DATA MEMORY)
The data memory address space consists of an internal and
external memory spaces.
External data memory is accessed, when a MOVX instruction is
executed.
The structure of data memory is shown in the figure.
RAM (DATA MEMORY)
Internal data memory is divided into two physically separate and
distinct blocks. They are,
i) The lower 128 bytes of RAM (internal RAM) area.
ii) The upper 128 bytes of special function register (RAM) area.
RAM (DATA MEMORY)
The structure of internal data memory space is shown in the
figure.
Four 8-bit register banks occupy Lotations 0 through 31 in
lower RAM area. Only one of these banks may be enabled at a
time, through a two bit (RS1 and RSO) field in PSW.
The next 16-bytes, locations 32 through 47 contain 128 bit
addressable locations.
Again the next 80 bytes, locations 48 through 127 contain only
byte addressable locations.
The SFR area also has byte and bit addressable locations.
Internal data memory addresses are always one byte wide.
RAM (DATA MEMORY)
All the bytes in the lower 128 can be accessed by either direct
or indirect addressing.
The SFRs are accessed only direct addressing.
The CPU generates RD and WR signals as needed during
external RAM accessses
There can be up to 64 Kbytes of external data memory. Memory
addresses can be either 1 or 2 bytes wide. Only indirect
addressing can be used for accessing external data memory. In
one byte addresses.
The location is indirectly specified either in register R0 or R1,
which is specified as @Ri.
In two byte addresses, the location indirectly specified in
register DPTR, specified as @ DPTR
INTERNAL RAM MEMEORY MAP
• The internal data memory of 8051 microcontroller is divided
into two physically separate and distinct blocks.
• They are 128 bytes of internal RAM area and the 128 bytes
special function register (SFR) area.
• The memory map of interna RAM is shown in the figure
INTERNAL RAM MEMEORY MAP
INTERNAL RAM MEMEORY MAP
The 128 bytes internal RAM is again subdivided into three
distinct areas. They are
1. Register bank area
2. Bit and Byte addressable location
3. Only byte addressable location
INTERNAL RAM MEMEORY MAP
Register Bank area: Microcontroller 8051 has four number of
register banks, each contains 8 registers.
They occupy the locations 0 through 31 in the lower RAM area
Their addresses are ranging from 00H to 1FH.
The four register banks are numbered 0 to 3, and the eight
registers are named R0 to R7. Each register can be addressed by
its name.
Bits RS0 and RS1 in PSW SFR DETERMINE which of bank
register is currently used.
INTERNAL RAM MEMEORY MAP
Bit and Byte addressable locations: The next 16 bytes,
locations 32 through 47 are bit and byte addressable locations.
They form total of 128 bit addressable locations.
These 16 byte locations may be specified by its bit address of
00H to 7FH, or byte address from 20H to 2FH.
INTERNAL RAM MEMEORY MAP
Only byte addressable locations: The next 80 bytes, locations
48 through 127 contain only byte addressable locations.
Their byte addresses are ranging from 30H to 7FH. It is called
general purpose RAM area.
OSCILLATOR AND CLOCK
The oscillator circuit used for generating clock pulses. The clock
pulses are used to synchronize all operations performed by the
microcontroller.
8051 have on chip crystal oscillator is connected to XTAL1 and
XTAL2 of microcontroller and capacitors to ground as shown
in figure.
The oscillator drives the internal clocking signals to the chip.
CLOCK CYCLE
In 8051, the crystal oscillator generates clock cycles. Depending
upon the frequency of crystal the clock cycle time varies. The
diagram shows 12 clock cycles.
Combination of one on- time and one off- time pulse is referred
as cycle.
STATE
T state-It is defined as the one subdivision of
operation performed in one clock period.
The state is defined as combination of two pulses .
MACHINE CYCLE
The length of the machine cycle depends on the frequency of the
crystal oscillator connected to the 8051 system.
Machine cycle consists of twelve (12) clock cycles.
Machine cycle is the unit of time elapsed during the execution.
It is the unit used to describe the operation of 8051operation.
The CPU takes a certain number of clock cycles to execute an
instruction.
INSTRUCTION CYCLE
Instruction cycle is the time required to complete the execution
of an instruction.
The Instruction may take different machine cycles to complete
execution.
So the instruction cycle may be of one or more machine cycles.
RESET
If reset is active high 8051 microcontroller will reset and turn
off all its functions. It will erase all values of registers and it will
make all program counter values to zero. It will not affect
memory content.
POWER ON RESET
To reset the microcontroller, the reset pin must be high (+5v) for
two machine cycle time.
To ensure that , the power-on reset circuit (shown below) using
capacitor and resistor is used.
When power on, the 8051 must be reset. During power-on , the
capacitor is charging. This maintains a high voltage across
Resistor R and then gradually the RC circuit discharges to bring
the reset pin to 0. This time period is necessary for getting reset.
To reset the microcontroller, the switch s is pressed. Shown in
Figure 1.11
OVERVIEW OF 8051 FAMILY
The MCS 51 family of 8- bit was built-in HMOS I technology.
The HMOS II version, which is the device current in production
is called the 8051AH.
The MCS 51 family members.
OVERVIEW OF 8051 FAMILY
The newest MCS 51 members, the 8032 and 8052 have more
on-chip memory and additional 16 bit timer/counter.
The new timer can be used as a timer, a counter and to generate
baud rates for the serial port. As a timer/counter, it operates in
either a 16-bit auto reload mode or 16 bit capture mode.
The 8051 is the most popular microcontroller. The 8051 is
available in different memory types such as UV-EPROM, flash
and NV-RAM, all of which have different part numbers.