0% found this document useful (0 votes)
2 views

Microcontroller Notes UNIT - I

The document provides an overview of microcontrollers, specifically focusing on the architecture and functionality of the MCS-51 (µC-8051). It details the components of embedded systems, the differences between microcontrollers and microprocessors, and the specific features of the µC-8051, including its registers, memory, input/output lines, and internal buses. Additionally, it explains the role of the Arithmetic and Logic Unit (ALU) and the Program Status Word (PSW) in processing instructions and managing data operations.

Uploaded by

roshanbaitharu86
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Microcontroller Notes UNIT - I

The document provides an overview of microcontrollers, specifically focusing on the architecture and functionality of the MCS-51 (µC-8051). It details the components of embedded systems, the differences between microcontrollers and microprocessors, and the specific features of the µC-8051, including its registers, memory, input/output lines, and internal buses. Additionally, it explains the role of the Arithmetic and Logic Unit (ALU) and the Program Status Word (PSW) in processing instructions and managing data operations.

Uploaded by

roshanbaitharu86
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

UNIT – I: Microcontroller

Introduction:

A system is a connection or combination of different physical elements or


Components which act together as an entire system to perform the given task or function or
certain job or application.
Embedded system is a piece of hardware can be activated or configured by a
group of programs called as software thus hardware together software called as an
Embedded System.
Embedded System is a single VLSI (very large scale integration) chip consisting
of 1,000 to 10,000 gates or circuit elements enclosed on to a small piece of silicon
integrated circuit(I. C.) in order to control the peripheral devices connected to it.
Embedded System is a “Programmable Logic Device” (PLD) which accepts the
Information or Data from input device, process that data according to the set of Instructions
called as Program and generates Control or Command signal’s to control either internal
circuits of it or the peripheral devices connected to it. Logic device is an electronic circuit
or switch that passes the control signals from input to the output when a specified condition
at the input is met or satisfied.
Central Processing Unit (CPU) or Active Circuit of an Embedded System is either
Microcontroller or Microprocessor can generate timing or control signals for
controlling the input and output devices connected to it.
Embedded Systems are the Microcomputer Systems used in Auto machine to
control physical quantities or parameters such as speed, velocity and etc., for sophisticated
and precise control of objects, in Communication to control speed, mode of data transfer
and their protocols, used in Many fields like Medical, Computers and So on.
Embedded Systems can be Configured or Operated by a set of instructions called as
Programs for a desired requirements or applications. Program is a group of instructions or
the sequence of steps or algorithm that the Embedded System has to follow in order to
complete the given task or application or function.
Embedded System consisting Microcontroller (µC) as a CPU belongs to
“Harvard structure”. Harvard structure is a memory structure consisting of separate
memory to store the Program and separate memory to store the data.

Every system Called as Digital Logic Circuit or System accepts, processes and
understands binary data or logic works on a concept known as stored program concept,
introduced by “John von Neumann”. According to the stored program concept, the given
function or application or task realized in terms of program must be stored before it is being
executed.

Microcontroller (µC) is Application Specific Integrated Circuits (ASIC),


which are used for controlling Specific Applications such Home Appliances and Industrial
Applications.

Page 1 of 20
Differences between microcontroller and microprocessor:

S.No. Microprocessor Microcontroller


CPU or MPU (Micro Processing CPU along with the memory devices
1. Unit) on a single chip is known as such as RAM, ROM and I/O devices is
Microprocessor. called as Microcontroller.
Microprocessor is known as single
2. Microcontroller is known as single chip
board microcomputer
microcomputer system(MCS)
system(MCS)
It is a Special Purpose Computer or
3. It is a General Purpose Computer Controller System Meant for
System Sophisticated control such as Auto
machine
The Microprocessor is available in Microcontroller is also available in 40
4. 40 pin DIP (Dual in line package), pin DIP, most of the pins are
most of the pins are single purpose multipurpose or multifunction pins.
or function pins.
Most of the instructions are for the Most of the instructions of a
purpose rapid movement of data microcontroller will perform rapid
5. from one location to another movement of bits through the pins of a
location or from one device to microcontroller i.e. internal circuitry of a
another device. microcontroller to the external circuit.
Microprocessor will do only byte Microcontroller can do both byte and bit
6. processing or Manipulation processing or Manipulation Efficiently.
Efficiently.
7. Microprocessor belongs to Microcontroller belongs to Harvard
Von Neumann structure. structure.
Microprocessor belongs to CISC Microcontroller belongs to
8.
(complex instruction set computer) RISC (Reduced instruction set
Computers. computer) Computers.
Microprocessor can be perform Microcontroller can generate timing and
9. mathematical calculations such as control signals in order to control
addition, subtraction, comparison position of an object in auto machine.
and soon efficiently.
10. Microprocessor is not True Microcontroller is a True Computer
Computer
11. Most of the instructions are Byte Most of the instructions are Bit
Processing Instructions Processing Instruction

ARCHITECTURE OF MIRCOCONTROLLER MCS-51(μC -8051):

Architecture is a Method of internal organization of various Circuit elements or Internal


Blocks or Logic circuits or Sections of a Microcontroller in a Systemic and Proper specified
Manner in order to reduce the Size, Complexity, Space, Cost of the device and to increase
the Speed of Operation or Execution, so that accuracy of the system increased and their by
system is highly efficient and reliable.

Simply the Internal organization of various units is the knowing of features and
application of each Unit or Logic Circuit and the functional relationship among them is
Called as Architecture of a Microcontroller MCS 8051. Or the organization of various

Page 2 of 20
circuits that are required in order to complete the given task in an efficient manner and
knowing their functionality is known as architecture of a Microcontroller MCS 8051.

Architecture of a Microcontroller MCS 8051 consisting of following Specific


Features

 The µC consists of 8-bit CPU with Arithmetic and Logic Unit (ALU), two 8-bit
registers CPU Registers named as A and B, 8-bit Program Status Word. (PSW)

Arithmetic and logic unit:


Arithmetic and logic unit is a heart of a CPU of µC where Arithmetic and logic operations
are carried out on the given data and decision making is done in order to complete the given
task or function or application. The complexity of ALU depends upon the type of operations
that it can execute. The various circuits of ALU are

8 – Bit 2’s Complement Adder and Sub tractor.


Basic Logic gate to perform basic function of Boolean algebra such as AND, OR and
NOT gate.
Increment and Decrement Circuit.
Shift register.
Magnitude Comparator and
EXOR gate for Parity checking.

A and B Registers:
A and B are the two 8-bit register which are parts of the CPU of a µC 8051 thus known as
CPU register used to store the data temporarily before the operation and to store the result
after the execution of operation.
A is CPU register, is a Heart of ALU also known as Accumulator holds the Sum of
addition operation and Difference of Subtraction operation, along with A and B are the two
registers holds the 2 - bytes of product i.e. the lower byte of the product is stored in A
register and higher bytes of products is stored in B register whenever multiplication
operation is executed, A holds Quotient and B holds remainder of the division operation. All
mathematical and logical operation carried by the ALU of µC in relation with A and B
registers.
All Operation carried by the CPU of µC in relation with the Accumulator thus it is
called Accumulator Based Processor or Controller.
 µC 8051 consisting of two special purpose 16-bit registers named as Program Counter
(PC) and Data Pointer (DPTR).

Program Counter:
Program Counter (PC) is a 16-bit special purpose register which holds the address of
memory location where the next instruction to be executed by the µC is stored. It is a
register that stores the address of a memory location to point the ROM memory where the
program is stored and address stored in PC is automatically incremented after execution of
each instruction to point next memory location. PC points the memory location of ROM or

Page 3 of 20
Program Memory one by one or one after the other in a specified manner, thus it is also
known as Program Sequencer or Memory Sequencer. In order make the machine to
complete the given task the starting address of a program is to be loaded into the program
counter.

The size of the PC is 16-BIT that is to say it can store 216 =65,536 different
combinations of addresses staring from 0000H to FFFFH, So the PC is capable of holding
the addresses in order to access 64KB of ROM memory.

Data Pointer:
Data pointer (DPTR) holds the address of a memory location where the data or
Operand is stored. DPTR is 16 – bit special purpose register made up of two 8 – bit register
named as DPH and DPL, are used to furnish memory address for internal and External
Code Access, External Data Access.

 µC 8051 consisting of 8 – Bit Stack Pointer

Stack Pointer:
Stack Pointer (SP) is an 8 – bit Register used to hold the internal RAM Address
called as “Top of the Stack Memory”. The address stored in the SP register is the location of
internal RAM where the last byte of data was stored by Stack Operation. Stack Pointer is
incremented and decremented to Store and Retrieve the data byte quickly from Stack
Memory. It holds 07H by default which is the ending address of the Register Bank – ‘0’.
 µC 8051 consisting of 4 Kbytes of Read Only Memory (ROM or EPROM) to store the
Program or Code that the µC has to execute in order to complete the given task or function.
The Sequence of steps nothing but a algorithm that the µC has to follow in order to
complete the given task dictated by the user to the Machine by storing group of instructions
nothing but a program in ROM memory space.
1 kilo = 1024.
4 KB = 4 X 1024 X 8 bits = 4096 X 8-bits=32,768 bits.
The ROM memory space consisting of 4096 memory location or registers and each
register is a group of 8 flip-flops capable of holding or storing 8-bits or 1 – Byte of binary
information thus a total of 32,768 bits of program can be stored in program memory. (i.e.
the program with 4096 bytes of instruction or Code)

 µC 8051 consisting of 128 bytes of internal Read/ Write Memory (RAM) to store the Data
or Operand on which the µC has to execute or perform Mathematical and Logical
operations. It is Consisting of 128 memory locations or registers and each register is a
group of 8 flip-flops capable of holding or storing 8-bits or 1 – Byte of binary information
thus in total 1024 bits of binary data can be stored onto the RAM Memory Space.

Out of available RAM memory space 32 bytes of RAM memory or 32 registers


or memory locations are grouped as 4 register banks named as Register Bank – ‘0’, ‘1’,
‘2’ and ‘3’ , each bank is consisting of 8-registers in it. Register Banks of RAM memory
are byte addressable Memory space.

Page 4 of 20
Out of available RAM space 16 bytes or registers or memory location of RAM
are Bit addressable memory space i.e. to say the individual bits of the registers of this
memory space can be accessed or modified or on the individual bits of this space the
arithmetic and logical operation can be executed .

The remaining 80 bytes of RAM memory space used as General Purpose


Memory space which is byte addressable also known as Scratch Pad Memory.

 µC 8051 consisting of 32 I/O (Input /Output) lines which are grouped as 4 Ports named
as Port - ‘0’, ‘1’, ‘2’ and ‘3’ to communicate the data information to the external I/O
devices in parallel manner, each is consisting of 8 lines with it and thus the size of the
port is of 8-bit . Out four ports, the Port – ‘1’ is a single function or single purpose port
meant solely for I/O operation and remaining three ports i.e. Port - ‘0’, ‘2’ and ‘3’ are
Multipurpose and Multifunction port along with the I/O operation.

 µC 8051 consisting of two 16 – bit timers named as TIMER - ‘0’ and TIMER - ‘1’ to
generate the timing and control signals or clock pulses in order to Count and Control the
sequence of events that are occurring internal and external to the µC. The Timer unit is
a section of µC used to generate control signals for synchronizing and controlling
external peripheral devices.

 µC 8051 is consisting of Full Duplex Serial Buffer (Transmitter and Receiver) Section or
Circuit (SBUF) in order to communicate the binary information or data to the peripheral
devices in serial manner that is bit by bit wise.

 µC 8051 consisting of three Internal interrupt and two External interrupt lines for
Dynamic Communication and Synchronous Data Transfer with the external Peri - Pheral
Devices.

 µC 8051 consists of Control Registers also known as Special Function Registers (SFR).
Operation that do not use the internal 128 – bytes of RAM Memory are done by a group
of SFR Registers of µC. Control registers are SCON (Serial control) to define modes of
serial communication, TMOD (Timer mode) and TCON (Timer control) are the registers
to define modes and control for the timer, PCON (Processor power control) for the µC,
IP (Interrupt priority) and IE (interrupt enable) are the registers to define Priority of
interrupt lines. These registers are addressed either by byte address using the addresses
80H t0 FFH. Some of these SFR’s are Bit addressable.

 The µC 8051 consisting of Oscillatory circuit with two pins named as XTAL – ‘1’ and XTAL
– ‘2’ across which a Quartz Crystal of 11.868 MHz is connected to generate Timing
and Clock Pulse in order to control the sequence of operations and events that are
carried by CPU of microcontroller internally and externally.

Internal Bus:
A Bus is a group of lines used to interconnect the various sections or circuits or block
of a µC to communicate the information among them. The data or Binary information is
communicated or transferred among the various block of µC and to the external devices
using group of lines called as Bus. The Bus is classified into

Address bus
Page 5 of 20
Data bus
Control bus
Address Bus is used send the address of the Memory Location of a Memory or
Peripheral device to identify them. Address bus is a group of 16 lines (i.e. size is 16 – bit
wide) used by µC to identify particular I/O device to which it is interested to
communicate and is a unidirectional bus allowing the addresses in one direction i.e. CPU
to the Peripheral devices

The address bus carries all zeros to all ones in it. Thus it is capable of carrying 65,536
different addresses (i.e. 0000H to FFFH) to address 64K input devices or Peripheral
devices or memory registers that are interfaced to µC 8051, thus Address bus describes
the maximum number of devices that can be connected to the µC.

Data bus is a group of 8 lines (i.e. size is 8 – bit wide) used by µC to Communicates or
carries 8- bits of binary information or data to the various block of µC. Data bus
describes the maximum no. of bits that it can transfer from one unit to another unit, that
can be Communicated by CPU to the peripheral devices in parallel manner and µC can
process or execute. Data bus is bi-directional bus allowing the binary information in
both directions i.e. between CPU and Peripheral devices.

The length or the size of the bus of µC of 16-bits divided as higher order bus denoted
as A15 to A8 and lower order address and data bus denoted ad AD7 to AD0, is called as
multiplexed bus carries both address and data.

Program Status Word (PSW):


The Conditions or Status arising due to Arithmetic and logical operations on a given
data are stored as a Individual flag bits in a separate register called as Program Status Word
(PSW). A PSW is an 8 - bit register, group of eight individual flip – flops are set or reset
according the result of the Arithmetic and logical operations or algorithm or process performed
on data in ALU.

“6” flags out of “8” flags are defined flag bits and used by microcontroller 8051 thus
called as Defined Flags, Remaining “2” are Undefined Flags and “1” flag bit out of “2”is
User flag bit denoted by “F0”, available for the user to store conditions of the user program for
later use called as User Definable Flag bit.

“4” flags out of “6” flags are Conditional or Mathematical flag bits used to
indicate conditions of mathematical operations and remaining “2” are unconditional flags
RS1 and RS0 (Register bank selection bits) used to select the register banks of RAM memory
space. The Conditional flags are

Carry flag (CY): Whenever the mathematical operation carried out on the unsigned
numbers and if the result of operation exceeds 8th bit then carry flag is “Set” otherwise it is
“Reset”. The result of arithmetic operations on data exceeds 8th bit, 9th bit stored is stored as
carry flag in PSW. Carry flag is used to indicate condition of unsigned number arithmetic. Carry
flag is treated as borrow flag while performing a Subtraction operation on unsigned numbers.

Overflow flag (OV): whenever the mathematical operation carried out on a signed numbers
and if the result is causing the high order bit then overflows flag is “Set” otherwise “Reset”.

Page 6 of 20
The Sign of the result is stored as Overflow flag also known as Sign flag. Overflow flag is
used to indicate the condition of signed arithmetic.

Auxiliary Carry flag (AC): whenever the mathematical operations are carried out on a BCD
(Binary coded decimal) numbers, carry generated at digit D3 forwarded to D4 the auxiliary
carry flag is “Set”, otherwise it is “Reset” i.e. generated from the lower nibble to higher
nibble. Auxiliary carry flag is used to indicate the conditions of BCD arithmetic.

D7 D6 D5 D4 D3 D2 D1 D0
Auxiliary Carry s 1 1 1
1 0 1 0 1 0 1 1
1 0 1 1 1 1 0 0
Carry 1 0 1 1 0 0 1 1 1

Parity flag (P): Parity flag is a bit to indicate and reflect the presence of number of one’s
(i.e.1’s) in the result of Arithmetic and Logical operations or in a given data. Microcontroller
MCS - 8051 follows the odd parity scheme i.e. if the result is consisting of odd number of
one’s (i.e.1’s) parity bit is “Set”, otherwise it is “Reset”. P=1 for Odd number of ones and P=0
for Even number of ones.

User flag named as F0 can be “Set”, otherwise it is “Reset” in order to store the
conditions of the program by user or programmer.

Memory Organization and Program Counter:


Memory is like a page of a notebook, as the page of notebook consists of fixed
number of lines, the memory consists of fixed number of registers or memory location
and each registers with a fixed number of flip- flops or Binary cells capable of storing fixed
no. of binary digits or binary data.

Memory organization is a method of knowing the storage capacity of internally


available memory, if the capacity of internally available memory is not sufficient then
how the memory capacity can be increased and what should be the maximum capacity
of memory that can be added to the available memory externally to the Microcontroller
MCS -8051. Organization is the knowing about the requirement of no. of address and data
lines for accessing the information from memory.

The microcontroller 8051 consisting of 4k bytes of ROM memory space also known
as Program memory or Code memory consisting of 4096 registers or memory locations and
each register is a group of 8 flip- flops stores 32,768 bits of binary code and each register or
memory location can be addressed by 12 – bit address to access the Code or Instruction.
128 bytes of RAM memory space also known as data memory consisting of 128 registers or
memory locations and each register is a group of 8 flip-flops stores 1024 bits of binary data.

Microcontroller 8051 consisting of 128 bytes internal data memory or Read/Write


memory or Random Access Memory is Organized or Sub – divided in to three distinct areas
as follows

 32 bytes of RAM memory space i.e. 32 memory locations or registers are


grouped as four Register Banks named as Register Bank – ‘0’, ‘1’, ‘2’ and ‘3’,
each bank is consisting of 8-registers in it designated as R0, R1, R2, R3, R4,
Page 7 of 20
R5, R6 and R7, all the registers are one byte or 8 – bit registers used by the μC – 51
to store the data temporarily while executing the Programs. Thus these registers of
all banks called as working registers, this area of RAM is Byte addressable
memory space.

 16 bytes of RAM memory space whose address is 20H to 2FH is a bit


addressable memory space i.e. to say the information can be accessed or processed
or manipulated or computed bit by bit from these locations by providing bit
address and also byte by byte by providing byte address thus these memory
locations are bit and byte addressable memory space, but mostly and efficiently
used by the μC – 51 as bit addressable RAM memory space.
 The remaining 80 bytes of RAM memory space whose address is 30H to
7FH used as General Purpose Memory space which is byte addressable also
known as Scratch Pad Memory.

If the Internal RAM or ROM Memory Space is not sufficient the capacity of this
memory’s can be enhanced or increased by interfacing memory externally to μC – 8051.
Maximum of 64 K bytes of memory can be accessed by the μC – 51 since its Program
counter and Data pointer size is 16 – bit, available internal ROM is 4 K bytes thus a
further of 60 K bytes memory can be connected or interfaced externally to the μC – 51.
The Information can be accessed from external memory by using Enable Access (EA) pin 0r
lead.

The Default registered bank used by the μC – 51 while executing programs is Register
Bank – ‘0’ for temporary storage of data, other register banks are selected with the help of
flag bits RS1 (Register Select – ‘1’)and RS0 (Register Select – ‘0’) of PSW.

Register Bank – ‘1’ whose address is 08H to 0FH of the RAM memory space
allocated as “Stack Memory” by default to store the PC Return address, contents of the
Registers and PSW while microcontroller deviates its execution from Main Program to Sub
Program. If this default “Stack Memory” space is not sufficient for storage then μC – 51
and Programmer can use any RAM memory space except bit addressable memory space i.e.
20H to 2FH.

Program Counter:
Program Counter (PC) is a 16-bit special purpose register which holds the address of
memory location where the next instruction to be executed by the µC is stored or existing or
available. It is a register that stores the address of a memory location to point the ROM
memory where the program is stored and address stored in PC is automatically incremented
after execution of each instruction to point next memory location. PC points the memory
location of ROM or Program Memory one by one or one after the other in a specified
sequential manner, thus it is also known as Program Sequencer or Memory
Sequencer. In order make the machine to complete the given task the starting address of a
program is to be loaded into the program counter.

Page 8 of 20
Data Types and Directives:
Data type is an element or Objective which describes the type of data, size of the data
on which the microcontroller has to process Arithmetic and Logical operations. Data type is
a method of describing about the type of data and its size to the assembler of a
microcontroller for the purpose of converting defined data into binary for the system.

The algorithm written by following a English letters known as commands or


instructions called as High Level Language (H.L.L.) Program, in order to make the
system to understand the algorithm or program in terms of HLL need to be converted into
zeros (0’s) and ones (1’s) called as Low or Machine level language(L.L.L.). The
machine level language is understood by the system and is comfortable but the user or a
programmer not comfortable with Low Level Language where as machine is not
comfortable with HLL. Thus, the user or a programmer should come down one step where
the algorithm is written in terms of Hex codes which are convenient for a machine and
programmer called as Assembly Level Language (A.L.L.). To the environment of
assembler the data types and directives are to be used along with the algorithm for the
purpose of assembling. Assembling is a process done by the assembler in order to convert
assembly level language program into machine level language. Assembler is the Tool or
program that translates the program of ALL in to Machine language.

The micro-controller work with only one data type which is commonly used by
the controller to process and to perform mathematical computation, most commonly used
data type is DB (Defined Byte) since every operation performed in C.P.U. of a micro-
controller on 8bits of a binary data or byte processing.

Defined Data (DB): DB is a data type which describes the type and the size of the data to
the assembler in order to convert the defined data into binary. The letter “D” after the number
is optional where as the letter such as “H” to indicate the Hexadecimal number, ”O” to indicate
the octal number, “B” to indicate the binary number are must. DB will also accept ASCII
characters and ASCII characters are placed in between the double quotes.

Ex:

DB 28 D - Decimal Number
DB 28 - Decimal Number, where D is optional
DB 11010101 B - Binary number
DB 367 O - Octal Number
DB 3ADH - Hexadecimal Number
DB “1234” - ASCII Number
DB “MYGOD” - ASCII characters

Along with the data types there are three directives or Pseudo instructions for
the assembler of a μC – 51. Pseudo instructions are commands will not perform any
mathematical or logical computation on the data except providing directions such as
starting and ending of the program to Assembler for conversion. They are

ORG (origin): Origin is a directive which specifies the starting address of a program
or algorithm to the assembler for the process of assembling. Origin is followed with either
decimal or hexadecimal address but it cannot be specified either in Octal or Binary.

Page 9 of 20
Ex:

ORG 200 - Decimal address


ORG 200H - Hexadecimal address

EQU (Equate): Equate is a directive which provides the values to the constants and labels
without requirements of memory location. The elements described with EQU directive
will takes the initial defined value where ever that constant or a label is existing such that in
order to change the value of constant, we need not change value at each label occurrence
in the program.

Ex: COUNT EQU 38H

--------------------

--------------------

MOV R3, # COUNT

END: End is a directive which specifies end address of algorithm or a program to the
assembler, so that the assembler stops or halts the process of assembling

The some of the assemblers of Microcontroller μC – 8051 will accepts the directives
as “.ORG”, “.EQU” & “.END”.

Problems: Define or describe the size and type for the data type given below.

1. DB 10111100 B – The Data type is a binary and its size is 1 byte (8 bits)
2. DB BOAD H – The Data type is a Hexadecimal and its size is 2 bytes
(16 bits)
3. DB 376 O – The Data type is octal and its size is 9 bits
4. DB “OH GOD” – The Data type is ASCII Characters and the size of the
data type is 5 bytes (40 bits)
5. DB “1234” – The Data type is ASCII Numbers and the size is 4 bytes
(32 bits)

Sub Routine and Stack Memory:


The group of Instructions or Sequence of steps or Set of procedure that are
repeatedly occurring at various places of main program can be written as a separate
program called as sub routine or sub program. Sub program is one of the most powerful
method and programming technique of writing algorithm to minimize the size of the
program so that the requirement memory space, cost of realization and delay in the
processing can be minimized such that speed of processing by the microcontroller can be
increased in order to make the system highly efficiency, accurate and effective in
performance.

The sub programs can be called from main program using either conditional or
unconditional “CALL” instructions. Sub program is a programming technique used for
realizing special applications such as interrupt mode of data transfer, servicing an interrupt,
serial communication and so on.

Page 10 of 20
Microcontroller μC – 8051 while deviates its execution from main program to sub-
program it has to remember to which address it has to come back to continue the process or
execution in the Main program and to terminate or stop the process or program execution.
Since, the program termination or halting is available in the form of a instruction in main
program only, the address to which it has to come back from sub-program is called as PC
Return address.

Microcontroller has to store the contents of registers to avoid the loss of data of these
registers, since it has same and fixed numbers of registers for both Main and Sub Program
algorithm. Contents of program status word which indicate the status and conditions of
Mathematical computations are to be stored when the sequence of execution is changed
from main program to the sub program.

Microcontroller uses stack memory to store the above PC return address, register
contents and PSW while changing its sequence of execution from main program to sub-
program. The register bank “1” whose address is 08H to 0FH of internal RAM memory
space is used as a default stack memory, if the default memory space is not sufficient then
any memory space except bit addressable RAM memory space i.e. 20H to 2FH can be
used as a stack memory.

Stack pointer is 8 bit register used to point the stack memory, which holds the ending
address of the register bank “0” i.e., 07H as its default address. While the data is pushed on
to the stack memory the address of Stack pointer is incremented by “1”and retrieved from
the stack memory by decrementing the Stack pointer.

The microcontroller 8051 pushes the data onto the stack memory and retrieves the
data from the stack memory with the help of two instructions “PUSH” and “POP”. The
technique that is followed in order to store and retrieve the data from stack memory is
“LIFO” (Last in First Out). The information from the stack memory is stored and
retrieved in the following manner

Store Data Get Data


SP = 0AH Address 0AH SP = 0AH

Store Data Get Data


SP = 09H Address 09H SP = 09H

Store Data Address 08H


Get Data
SP = 08H SP = 08H

SP = 07H Address 07H SP = 07H

Storing Data on to the Stack Internal RAM Getting Data from Stack
(Increment then Store) (Get Data then Decrement)

Page 11 of 20
PIN Diagram of a Microcontroller 8051:
Pin is a terminal or lead or leg used to place the integrated circuit into the circuit or
on to the PCB (Printed Circuit Board). Pin is a terminal used to supply Power or Energy in
order to activate the internal circuitry of a Microcontroller. Pin is a lead used to transfer
the binary pulses or data or Information in to the μC for processing and out of the
microcontroller to control the Peri – Pheral devices.

Microcontroller MCS 8051 is a VLSI chip consisting of 1000 to 10,000 Logic


elements or gate circuits belong either MOS or CMOS family available as integrated circuit
consisting of 40 pins in the form of a DIP (Dual-in-Line Package). If the leads or terminals
available on the two sides, they are in line with each other such a package is called DIP
package.

P1.0 1 40 VCC

P1.1 2 39 P0.0 (AD0)

P1.2 3 38 P0.1(AD1)

P1.3 4 37 P0.2(AD2)

P1.4 5 36 P0.3(AD3)

P1.5 6 35 P0.4(AD4)

P1.6 7 34 P0.5(AD5)

P1.7 8 33 P0.6(AD6)

(RESET)RST 9 32 P0.7(AD7)

(RXD)P3.0 10 31 EA
Microcontroller
(TXD)P3.1 11 30 ALE(PROG)
MCS 8051
(INT - 0)P3.2 12 or 29 PSEN
IC 8051
(INT - 1)P3.3 13 28 P2.7(A15)
or
(T0)P3.4 14 μC - 51 27 P2.6(A14)

(T1)P3.5 15 26 P2.5(A13)

(WR)P3.6 16 25 P2.4(A12)

(RD)P3.7 17 24 P2.3(A11)

XTAL 1 18 23 P2.2(A10)

XTAL 2 19 22 P2.1(A9)

Vss 20 21 P2.0(A8)

Most of the pins of μC are multipurpose and multi function pins. 32 pins out of 40
pins are the I/O (Input /Output) pins, grouped as 4 Ports named as Port - ‘0’, ‘1’, ‘2’ and ‘3’

Port -“1” pins i.e., Pin no.’s 1 to 8 are single function pins will acts as input/output
pins to carry the data in parallel between μC and external Peri-Pheral devices.

Page 12 of 20
Port -“0” pins i.e., Pin no.’s 32 to 39 are Multi function pins will acts as input/output
pins as port – “1” to communicate with the external Peri – Pheral’s, along with the pins of
Port “2” will acts as address /data bus to access the external Memory interfaced to the μC -
8051. Port -“0” pins will be used as a bi –directional, multiplexed lower order address /data
bus.

Port -“2” pins i.e., i.e., Pin no.’s 21 to 28 are Multi function pins will acts as
input/output pins as port – “1” to transfer the data between μC and external Peri – Pheral’s,
along with the pins of Port “1” will acts as address bus to access the external Memory
interfaced to the μC - 8051. Port -“2” pins will be used as a uni –directional, higher order
address bus.

Port - “3” is multiple function port, Port - “3” pins i.e., Pin no.’s 10 to 17 will acts as
input/output pins, alternatively the pins are used for the purpose of System Timing,
System Interrupt or Interrupt I/O control , Memory Control and Serial
Communication control.

Two lines of Port – “3” i.e. P3.0 and P3.1 with the Pin no.’s 10 and 11 named as TXD
(Transmitting the data) and RXD (Receiving the Data) are used during serial data
communication for transmitting and receiving the data serially.

Two lines of Port – “3” i.e. P3.2 and P3.3 with the Pin no.’s 12 and 13 named as INT
– “0” (External Interrupt – “o”) and INT – “1” (External Interrupt – “1”) are used to
communicate the interrupt requests from external I/O devices. Microcontroller is
interrupted by the Peri – Pheral devices interfaced to it through these lines.

Two lines of Port – “3” i.e. P3.4 and P3.5 with the Pin no.’s 14 and 15 named as T0
(Timer Interrupt – “0”) and T1 (Timer Interrupt – “1”) are used to control and configure the
operation of internal timers of μC 8051.

Two lines of Port – “3” i.e. P3.6 and P3.7 with the Pin no.’s 16 and 17 named as WR
(Write) and RD (Read) called as memory controlled signals, are used to specify the type of
accessing to the memory.

Two Pins with Pin no.’s 20 and 40 named as VSS and VCC are called as Power supply
pins across the pins a Single Positive 5V DC voltage is connected to activate internal circuit
of μC 8051.

Two Pins with Pin no.’s 18 and 19 named as XTAL - 1 and XTAL - 2 are called as Clock
pins across the pins a Quartz Crystal of 11.568 MHz is connected to generate Timing and
clock pulses to Control and synchronize the internal and external operation and events
performed by the μC 8051.

Pin no “9” named as RST [Reset] is an active high incoming signal used to reset and
terminate all the activities of μC. With the RST signal μC resets itself by clearing all internal
registers of it including PC, makes all buses to high impedance state and restart’s the
execution from beginning of the page – “0” of ROM memory space whenever it is struck
during the execution of application.

Page 13 of 20
Pin no “30” named as ALE [Address Latch Enable] is an active high outgoing signal
used by the microcontroller to enable or activate the lower ordered Multiplexed bus i.e.
(AD7 - AD0 lines) as address bus i.e. (A7 - A0 lines) and data bus i.e. (D7 - D0 lines). When
ALE =1 the line AD7 - AD0 will be latched as address lines to carry the address and the bus is
called as uni-directional bus. When ALE =0 the lines AD7-AD0 will be latched as data lines
to carry the data and the bus is called Bi-directional bus.

Pin no “31” named as EA [External access] is an active low outgoing signal used by
the μC 8051 to describe whether it is accessing internal or external memory. When EA is
logic - “1” then μC is accessing the code from internal ROM memory when EA is logic ‘0’
then μC is accessing the external memory.

Pin no “29” named as PSEN [Program Store Enable] is an active low outgoing
signal used by the μC 8031 along with the EA to access the External memory since it doesn’t
has on chip memory. PSEN is connected to OE (Output Enable) or CS (Chip Select) pin of
ROM Memory chip.

PORT Organization and I/O Programming of a Microcontroller 8051:


Port is a group of terminals or lines used to interface or connect the external I/O
devices to the micro-controller to establish parallel communication in order to exchange
information. In other words a port is a group of pins used to transfer binary information in
the form of electrical pulses in and out of the microcontroller for Processing. The MCS 8051
is consisting of 32 I/O lines grouped as four ports named as port-‘0’, ‘1’,’2’ and ‘3’. The
size of the each port is 8 - bit and all theses ports are bi-directional ports i.e. to say they
will allow the data transfer on either direction.

The method of configuring these ports to work as input and output ports are called
as port organization or Programming. The port ‘0’ and ‘2’ will also work as data bus and
address bus along with these the port will work as I/O port thus the method of describing
the port as address bus and data bus is known as port programming. The port can be
configured or organized for different functions with the help of Latching or controlling
circuit consisting of three functional elements. They are

D-flip-flop/latch
Input driver/ buffer
Output driver buffer.

The input and output driver circuit are also known as Tri-state logic gates or
buffer circuit which acts as a transparent gate or circuit, when control signal is active high to
allow the data from input to the output and acts as opaque when control signal is active low
not allowing any input to the output, this condition is also called as High impedance state.
The driver circuit is consisting of three terminals named as input, output and control signal.

Port – “1” Pin Configuration:

Port -“1” pins i.e., Pin no.’s 1 to 8 are single function pins will acts as input/output
pins to carry the data between μC and external Peri-Pheral devices in parallel. Logic circuit
connected to each pin of port-‘1’ and its pin configuration is as shown in the figure.

Page 14 of 20
Read Latch Pin

VCC

Internal Data D Q

RL

1k
Bus/Port Pin P 1.x

Write latch Pin Clk Q

Read data Pin

Fig: Pin configuration of Port – ‘1’

By placing “FFH” i.e. Binary data of “11111111” the D – Latch has “High” on its Q and
Q is “Low” (i.e. Q = 1 and Q = 0), a “Low” on Q switches the Transistor to OFF, data on the
pin connected to tri – state buffer TB1 and Port ‘1’ is configure to work as input port allowing
the data from external devices into microcontroller for processing.

By writing a “00H” i.e. Binary data of “00000000” D – Latch has “Low” on its Q and
Q is “High” (i.e. Q = 0 and Q = 1), a “Low” on Q switches the Transistor to ON and Port ‘1’ is
configured to work as output port allowing the data transfer from μC to the external devices
in order to store or display or print.

Port – “0” Pin Configuration:

Port -“0” pins i.e., Pin no.’s 32 to 39 are Multi function pins will acts as input/output
pins as port – “1”, will be used as a bi –directional, multiplexed lower order address /data
bus. Logic circuit connected to each pin of port-‘1’ and its pin configuration is as shown in
the figure.

Control Signal

Address Latch

Read Latch Pin


Open Drain Configuration

Internal Data D Q
Bus/Port Pin P.0.x
Control
Write Latch Pin Clk Q
Circuit

Read Data Pin

Fig: Pin configuration of Port – ‘0’

Page 15 of 20
By placing “FFH” i.e. Binary data of “11111111” the D – Latch has “High” on its Q and
Q is “Low” (i.e. Q = 1 and Q = 0), Q applied to the control circuit and it switches both the
Transistor’s to OFF, data on the pin connected to tri – state buffer TB1 and Port ‘1’ is
configure to work as input port allowing the data from external devices into microcontroller
for processing.

By writing a “00H” i.e. Binary data of “00000000” D – Latch has “Low” on its Q and
Q is “High” (i.e. Q = 0 and Q = 1), “Low” Q applied to the control circuit and it switches the
upper Transistor M1to OFF and M2 to ON, Port ‘1’ is configured to work as output port
allowing the data transfer from μC to the external devices in order to store or display or
print.

The major difference between the P0 and other ports is that P0 has no internal pull –
up resistors, is in open drain configuration i.e. Drain terminal is under open condition since
it is used as Address/ Data bus along with the I/O. Thus, when ever P0 is used for simple
data I/O the pull up resistors must be connected to the port ‘0’ pins to drive the external
circuitry or devices.

Placing an address on the internal bus, sending a control signal ALE as logic ‘1’ to the
control circuit, makes the P0 to work as address bus and when ALE is logic ‘0’ the P0 is
configured to work as data bus to allow the data to transferred in and out of the port.

Port – “2” Pin Configuration:

Port -“2” pins i.e., Pin no.’s 21 to 28 are dual function pins will acts as input/output
pins as port – “1”, will be used as a Uni –directional, higher order address bus. Logic circuit
connected to each pin of port-‘1’ and its pin configuration is as shown in the figure.

Control Signal

Address Latch

Read Latch Pin


Vcc

Internal Data
RL

D Q
1k

Bus/Port Pin
P.2.x
Control
Clk Q
Write Latch Pin Circuit

Read Data Pin

Fig: Pin configuration of Port – ‘2’

Port – “2” may be used as an I/O port similar in operation to Port – “1”. The
alternative function of P2 is to supply higher byte address in connection with the P0. P2 will
work as a higher order address bus along with the P0 by placing the address on internal bus
and activating the control signal ALE as logic-‘1’
Page 16 of 20
Port – “3” Pin Configuration:

Port -“3” pins i.e., Pin no.’s 10 to 17 are Multi function pins will acts as input/output
pins as port – “1”, will be used for the purpose of System Timing, System Interrupt or
Interrupt I/O control , Memory Control and Serial Communication control.
Logic circuit connected to each pin of port-‘1’ and its pin configuration is as shown in the
figure.

Control Signal

Read Latch Pin


Vcc

Internal Data

RL
D Q

1k
Bus/Port Pin
P.3.x
Control
Clk Q
Write Latch Pin Circuit

Read Data Pin

Fig: Pin configuration of Port – ‘3’

Port – “3” may be used as an I/O port similar in operation to Port – “1”. The
alternative function of P3 is under the control of Special Function registers (SFR) with the
help of Bit Manipulation or Programming instruction.

INTERRUPTS of a Microcontroller 8051:


Interrupt is a method opted by the peripheral devices in order to get the attention of
microcontroller or in other words interrupt is a method to intimate the problems that are faced
by the peripheral devices to the microcontroller, to get it solved by the μC. Interrupt is a
technique intended for dynamic or synchronous data transfer among the μC and I/O devices.

Microcontroller is an Embedded System will serve several devices interfaced to it.


There are two techniques to serve the devices, they are Polling and Interrupt. Polling is a
technique in which the μC continuously monitors the status of device in a Round – Robin
fashion (i.e. one after the other), when status or condition met it provides the service to that
device and continues the monitoring of other devices. Interrupt is a technique in which the
device being serviced upon request or when the device needs service.

Interrupt is better, effective and efficient method than polling since polling method
wastes much of the Microcontroller’s time in checking whether any peripheral device is asking
the request or not during which the μC can do important and useful task. Where as in an
interrupt method, the burden of checking is relieved from the μC and whenever the interrupt
line is activated or sends an interrupt signal then only μC responds. In Interrupt method each
device will get the service depending on the Priority, where as it is not possible with polling.
More importantly of μC can ignore a devise request for service but it is not possible with the
polling.

Page 17 of 20
Whenever a particular interrupt line is active high or interrupts the microcontroller
then it provides a service by executing a program known as Interrupt service subroutine
(ISS or ISR) called as Interrupt handler. The interrupt service subroutine is a group of
instructions that are executed by microcontroller to solve the problems of devices or to give the
service to the device.

The MCS 8051 consisting of Five interrupt lines named as INT0 and INT1 are the
two external interrupts generated by external devices or circuits connected to pins of
microcontroller i.e. p 3.2 and p3.3. Three are the internal interrupts named as Timer - 0 and
Timer - 1 interrupts for the timers and one is serial communication interrupt named as RI &
TI available for the user but many data sheets state that there are six interrupts including
RESET. Three internal interrupts are generated automatically by internal operations.

When more than one peripheral devices requesting the attention of a μC then it
provides service to any one device by resolving the priority among them and acknowledging the
highest priority interrupt. INT – ‘0’ has highest priority and RI&TI has lowest priority by
default. Priority among the Interrupt lines according to the manufactures of 8051 is as given in
the below table.

All the Interrupts except RESET are allocated with the 8 memory locations or 8–
bytes of ROM memory space to store ISR of the corresponding interrupt thus they are called as
Vectored Interrupts. If the Specified memory space is not sufficient to store ISR then μC is
redirected to any another memory space from vector memory space by specifying JUMP
instruction along with address of memory space. Interrupt vector table is existing on ROM
memory is as give below.

ROM Location
S.No. INTERRUPT Priority
Vector Address in Hex
1 RESET 0000H
External Hardware Interrupt 0
2 0003H 1
(INT 0)
3 Timer 0 Interrupt (TF0) 000BH 2
External Hardware Interrupt 1
4 0013H 3
(INT 1)
5 Timer 1 Interrupt (TF1) 001BH 4
Serial Communication Interrupt
6 0023H 5
(RI and TI)

Priority among the interrupt lines can be altered or changed according to the
requirement of user or programmer depending on application, with the help of a Special
Function Register (SFR) known as Interrupt Priority (IP) register.

The interrupt priority register is an 8 - bit register in which the bits D7 and D6 are not
defined reserved for the later use, remaining bits i.e. D5 to D0 are allocated for each interrupt
line in order to determine the priority by the user. If the bit is logic ‘1’ then corresponding
interrupt has highest priority and if the bit is logic ‘0’ then interrupt has lowest priority.
D7 D6 D5 D4 D3 D2 D1 D0
IP 7 IP6 IP5 IP4 IP3 IP2 IP1 IP0

-- -- -- PS PT1 PX1 PT0 PX0

Page 18 of 20
Priority bit is ‘1’ assigns highest priority
Priority bit is ‘0’ assigns lowest priority.

Fig: Interrupt Priority Register

Method of activating or deactivating, enabling or disabling, a particular interrupt line


is called as Masking. The enabling or disabling, acknowledgement of a particular interrupt line
can be described by using a special function register known as Interrupt Enable Register
(IE).

The interrupt enable register is an 8 - bit register in which the bits D6 and D5are not
defined, reserved for the future use, remaining bits i.e. D7, D5 to D0 describes the enable and
disables conditions of each interrupt line.

Bit D7 i.e. EA is Enable Access will disables or enables all the interrupts sources. If
EA is ‘0’ then all the interrupts are disabled and no interrupt is acknowledged, not given any
service to it by the μC. If EA is ‘1’ then the interrupt line provided service depending on
conditions of the individual interrupts. Each interrupt line is enabled or disabled by setting or
clearing the corresponding enable bits of IE.

D7 D6 D5 D4 D3 D2 D1 D0
IE 7 IE6 IE5 IE4 IE3 IE2 IE1 IE0

EA -- -- ES ET1 EX1 ET0 EX0

Bit is set to ‘1’ to Enables interrupt


Bit is set to ‘0’ to Disables interrupt

Fig: IE (Interrupt Enable) Register

TIMER/ COUNTER Module of a Microcontroller 8051:


In many Microcontroller applications the sequence of events occurring externally
and internally to the microcontroller are to be counted, to generate the control signals in order
to control the devices interfaced to it and the necessary time delay need to created between the
events during the execution of the task or system actions.

The counting of events, generation of time delays and timing control signals can be
accomplished using software technique i.e. Programs with loops and nested loops, but software
loops for counting or timing keeps the microcontroller busy and is burden to the μC. During this
time, some other important job or more valuable task can be done by 8051 so an extra hardware
circuit is provided to the μC 8051 called timer unit will do all the above mentioned tasks.

μC 8051 has two 16 - bit timers named as timer – ‘0’ and timer – ‘1’ can be
accessed as two separate 8 bit timer register TL0 and TH0 (Timer – ‘0’ lower byte and
timer higher byte), TH1 and TL1 (Timer – ‘1’ lower byte and timer higher byte) since
μC is an 8 – bit architecture. They can be used either as timers to generate necessary time
delay between the events or as counters to count the events.

Modes and internal operations of timers are controlled by two 8 – bit Registers
TCON (timer control register) and TMOD (timer mode control register). TMOD is a special
Page 19 of 20
function register which controls timer operation modes of two timers and 4 – bits of TMOD are
allocated to control the action of each timer.

D7 D6 D5 D4 D3 D2 D1 D0

GATE C/T M1 M0 GATE C/T M1 M0


Timer - 1 Timer - 0

Fig: TMOD (Timer Mode Control) Register


Gate: Gating control bit, describes start and start of timer either by software or by hardware
since the timers of a μC can be controlled by both. If Gate = ‘0’ then timer will be controlled by
software instructions by setting and clearing TRX (Timer Run control) bit and if Gate = ‘1’ then
timer will be controlled by hardware i.e.by an external source. When Gate bit is set then Timer/
Counter is enabled only while INTX is high and TRX is set and When Gate bit is cleared timer
is enabled whenever TRX is set.

C/T (Counter/Timer): C/T is a bit in the TMOD register used to decide whether timer is used
as a counter to count events occurring internal and external to the μC called as event counter
or as a timer to generate necessary time delay between the events or computer actions called as
delay generator. C/T is cleared (i.e. C/T = ‘0’) for Timer operation and is set (i.e. C/T = ‘1’)
for counter operation in order.

M1 and Mo: M1 and M0 are mode selection bits for timer of μC. Timer may be operated in any
one of four modes described by mode selection bits, the four different mode of timer are as
described below.

D7 D6 D5 D4 D3 D2 D1 D0
TCON.7 TCON.6 TCON.5 TCON.4 TCON.3 TCON.2 TCON.1 TCON.0

TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0

Fig: TCON (Timer Control) Register

TF1 and TF0: TF1 and TF0 are called as timer over flow flags. These bits are set to logic ‘1’
whenever the timer/counter overflows (i.e. rolls from all one’s to zero’s) and cleared to logic ‘0’
by hardware to indicate the processor vectors (i.e. deviates) to execute interrupt service
subroutine(ISS) at a vector address 001BH for Timer – ‘0’and 000BH for Timer – ‘1’.

TR1 and TR0: TR1 and TR0 are the timer run control bits used to describe ON/OFF
conditions of timer/counter, set to logic ‘1’ by the program to activate or enable the
timer/counter to start counting and cleared to logic ‘0’ by the program to stop (i.e. Halt)the
timer.

IE1 and IE0: IE1 and IE0 are external interrupt edge flag bits. These bits are set to logic ‘1’ by
CPU when external interrupt edge (High to Low transition) is detected on Pin 3.3 (INT 1) and
Pin 3.2 (INT0) and cleared to logic ‘0’ by CPU when Interrupt is processed.

IT1 and IT0: IT1 and IT0 are the type control bits. These bits are set to logic ‘1’ by program to
enable external interrupt – 1 (INT1) and interrupt – 0 (INT0) to be triggered by falling edge
signal and cleared to logic ‘0’ to enable a low level signal on external interrupt – 1 (INT1) and
interrupt – 0 (INT0) to generate Interrupt.
Page 20 of 20

You might also like