Sie sind auf Seite 1von 90




For the partial fulfillment of the degree of associated

Membership awarded by
SG-188152 W

Under the guidance of




This is certified that satish chander has carried out project
work presented in this thesis entitled bidirectional visitor
counter for the award of IETE, under my supervision.
The report embodies result of original work and studies
carried out by student himself and the contents of the thesis
do not form the basis for the awrd of any other degree or
diploma to the candidate or to anybody else.

Signature of the project guide


I am very much thankful from the core of my heart for the
precious contribution of my guide who provided his
possible help the succses ful completion of the project has
been possible due to sincere co operation guidance ,
inpiration, moral support and timely advice of my guide
who ddevoted his utmost co operation in this project work.
I also give special thanks to my colleagues for that endless
flow of ideas and all those who helped in this project in
some way or the other.

SG 188152 W



A counter that can change its state in either direction, under

control of an updown selector input, is known as an up
down counter. The circuit given here can count numbers
from 0 to 9999 in up and down modes depending upon the
state of the selector. It can be used to count the number of
persons entering a hall in the up mode at entrance gate. In
the down mode, it can count the number of persons leaving
the hall by decrementing the count at exit gate. It can also
be used at gates of parking areas and other public places.
This circuit divided in three parts: sensor, controller and
counter display. The sensor would observe an interruption
and provide an input to the controller which would run the
counter in up/down mode depending upon the selector
setting. The same count is displayed on a set of 7-segment
displays through the controller.



From the block diagram it is clear that the sensor pairs

are placed face to face so that an IR radiations from IR
LED are continuously received by phototransistor which
makes its emitter base junction forward and collector
current Ic equals to emitter current Ie (i.e, Ic=Ie)
assuming base current to be negligible. Hence the voltage
at collector node becomes zero (logic 0) which is feed to
microcontroller port pin P3.2 and P3.3, if any object is
placed in between the sensor pair blocks the IR radiation
which in turns put the phototransistor in cut-off mode
makes collector voltage to +5V (logic 1)


In this circuit, two infrared (IR) sensor modules are used

each for up and down counting, respectively. Whenever an
interruption is observed by the first IR sensor, it increments
the counter value. Similarly, when the second sensor
detects an obstacle, the count is decremented.
The count value is calculated depending upon the sensors
input and is displayed on a set of four seven segment
displays by using the concept of multiplexing (for concept
of multiplexing refer seven segment multiplexing). The

data pins of each 7-segment display are connected to port

P2 of the microcontroller AT89C51. The first four pins of
port P1 (P1^0-P1^3) are connected to control pins to enable a
particular 7-segment
. P1^5 & P1^6 are configured as input pins at which the
sensors are connected.
The sensor inputs are defined as up and down selector
modes for the counter in the code. Each time the first
sensor is blocked, it gives a high signal at P 1^5 and the
count value gets incremented. The value gets decremented
when P1^6, connected to second sensor, gives high input. At
each step, the value of the counter is sent to be displayed on
the segments.




5 V

5 V



R 2

R 2

470 E

D 2

D 1

Q 1A

D 1


D 2

470 E


Q 1A


R 3


T R A N S M IT T E R 1
P 0 .0

R 3

R E C E IV E R 1

R E C E IV E R 2

P 0 .2

P 0 .3

P 0 .4

P 0 .5



I R R e c e iv e r 1
I R R e c e iv e r 2

P 0 .6
P 0 .7

1 1 .0 5 9 2 M H z




10m f





.0 /A
.1 /A
.2 /A
.3 /A
.4 /A
.5 /A
.6 /A
.7 /A






P 2 .0 /A 8
P 2 .1 /A 9
P 2 .2 /A 1 0
P 2 .3 /A 1 1
P 2 .4 /A 1 2
P 2 .5 /A 1 3
P 2 .6 /A 1 4
P 2 .7 /A 1 5
P 3 .0 /R XD
P 3 .1 /TXD
P 3 .2 /IN T 0
P 3 .3 /IN T 1
P 3 .4 /T 0
P 3 .5 /T 1
P 3 .6 /W R
P 3 .7 /R D







P 0 .1






4.7 K



P 1 .1
P 1 .0
4.7 K 4 .7 K



g f
P 0 .0
P 0 .1
P 0 .2
P 0 .3
P 0 .4
P 0 .5

10 K
P 0 .6
P 0 .7




e d




a b


c h


// Program to make a bidirectional visitor counter

using IR sensor

#include <reg51.h>
#define msec 1
unsigned int num=0;
sbit dig_ctrl_4=P1^3; //declare the control pins of
seven segments
sbit dig_ctrl_3=P1^2;
sbit dig_ctrl_2=P1^1;
sbit dig_ctrl_1=P1^0;
unsigned int
unsigned int dig_1,dig_2,dig_3,dig_4,test=0;
unsigned char dig_disp=0;
sbit up=P3^5; //up pin to make counter count up
sbit down=P3^6; //down pin to make counter count

void init() // to initialize the output pins and Timer0

dig_ctrl_4 = 0;
dig_ctrl_3 = 0;
dig_ctrl_2 = 0;
dig_ctrl_1 = 0;

void delay() //To provide a small time delay



void display() interrupt 1 // Function to display the

digits on seven segment. For more details refer seven
segment multiplexing.
dig_ctrl_1 = dig_ctrl_3 = dig_ctrl_2 = dig_ctrl_4 = 0;

case 0:

P2= digi_val[dig_1];
dig_ctrl_1 = 1;

case 1:
P2= digi_val[dig_2];
dig_ctrl_2 = 1;

case 2:
P2= digi_val[dig_3];
dig_ctrl_3 = 1;

case 3:
P2= digi_val[dig_4];
dig_ctrl_4 = 1;

void main()
if(up==0&&down==1) //check if up pin is pressed

if(up==1&&down==0) //check if down pin is



It is often required to produce a signal whose frequency or

pulse rate is very stable and exactly known. This is
important in any application where anything to do with
time or exact measurement is crucial. It is relatively simple
to make an oscillator that produces some sort of a signal,
but another matter to produce one of relatively precise
frequency and stability. An ordinary quartz watch must
have an oscillator accurate to better than a few parts per
million. One part per million will result in an error of
slightly less than one half second a day, which would be
about 3 minutes a year. This might not sound like much,
parts per million would result in an error of about a half an
hour per year. A clock such as this would need resetting
about once a month, and more often if you are the punctual
Fig Crystal oscillator

A crystal oscillator is an electronic circuit that uses the

mechanical resonance of a vibrating crystal of piezoelectric
material to create an electrical signal with a very precise

frequency. This frequency is commonly used to keep track

of time (as in quartz wristwatches), to provide a stable
clock signal for digital integrated circuits, and to stabilize
frequencies for radio transmitters and receivers. The most
common type of piezoelectric resonator used is the quartz
crystal, so oscillator circuits designed around them were
called "crystal oscillators".
Quartz crystals are manufactured for frequencies from a
few tens of kilohertz to tens of megahertz. More than two
billion (2109) crystals are manufactured annually. Most
are small devices for consumer devices such as
wristwatches, clocks, radios, computers, and cellphones.
Quartz crystals are also found inside test and measurement
equipment, such as counters, signal generators, and

A crystal is a solid in which the constituent atoms,

molecules, or ions are packed in a regularly ordered,
repeating pattern extending in all three spatial dimensions.
Almost any object made of an elastic material could be
used like a crystal, with appropriate transducers, since all
objects have natural resonant frequencies of vibration. For
example, steel is very elastic and has a high speed of sound.
It was often used in mechanical filters before quartz. The
resonant frequency depends on size, shape, elasticity, and
the speed of sound in the material. High-frequency crystals
are typically cut in the shape of a simple, rectangular plate.
Low-frequency crystals, such as those used in digital

watches, are typically cut in the shape of a tuning fork. For

applications not needing very precise timing, a low-cost
ceramic resonator is often used in place of a quartz crystal.
When a crystal of quartz is properly cut and mounted, it can
be made to distort in an electric field by applying a voltage
to an electrode near or on the crystal. This property is
known as piezoelectricity. When the field is removed, the
quartz will generate an electric field as it returns to its
previous shape, and this can generate a voltage. The result
is that a quartz crystal behaves like a circuit composed of
an inductor, capacitor and resistor, with a precise resonant
frequency. (See RLC circuit.)
Quartz has the further advantage that its elastic constants
and its size change in such a way that the frequency
dependence on temperature can be very low. The specific
characteristics will depend on the mode of vibration and the
angle at which the quartz is cut (relative to its
crystallographic axes).[7] Therefore, the resonant frequency
of the plate, which depends on its size, will not change
much, either. This means that a quartz clock, filter or
oscillator will remain accurate. For critical applications the
quartz oscillator is mounted in a temperature-controlled
container, called a crystal oven, and can also be mounted
on shock absorbers to prevent perturbation by external
mechanical vibrations.

PCB is a platform where many of the embedded

systems to be made. PCB (Printed Circuit Board) is used
for the assembly of various components on a single plate.

The connections on the PCB should be identical to the

circuit diagram, but while the circuit diagram is arranged to
be readable, the PCB layout is arranged to be functional, so
there is rarely any visible correlation between the circuit
diagram and the layout.
PCB layout can be performed manually (using CAD)
or in combination with an Autorouter. The best results are
usually still achieved using atleast some manual routing
Sometimes abbreviated PCB, a thin plate on which
chips and other electronic components are placed.
Computers consist of one or more boards, often called
cards or adapters


A voltage regulator is an electrical regulator designed

to automatically maintain a constant voltage level. It may
use an electromechanical mechanism, or passive or active
electronic components. Depending on the design, it may be
used to regulate one or more AC or DC voltages.
With the exception of passive shunt regulators, all
modern electronic voltage regulators operate by comparing
the actual output voltage to some internal fixed reference
voltage. Any difference is amplified and used to control the
regulation element in such a way as to reduce the voltage
error. This forms a negative feedback control loop;
increasing the open-loop gain tends to increase regulation
accuracy but reduc``e stability (avoidance of oscillation, or
ringing during step changes). There will also be a trade-off

between stability and the speed of the response to changes.

If the output voltage is too low (perhaps due to input
voltage reducing or load current increasing), the regulation
element is commanded, up to a point, to produce a higher
output voltage - by dropping less of the input voltage (for
linear series regulators and buck switching regulators), or
to draw input current for longer periods (boost-type
switching regulators); if the output voltage is too high, the
regulation element will normally be commanded to produce
a lower voltage.

Fig Regulator ICs

The 78xx (also sometimes known as LM78xx) series

of devices is a family of self-contained fixed linear voltage
regulator integrated circuits. The 78xx family is a very
popular choice for many electronic circuits which require a
regulated power supply, due to their ease of use and relative
cheapness. When specifying individual ICs within this
family, the xx is replaced with a two-digit number, which
indicates the output voltage the particular device is
designed to provide (for example, the 7805 has a 5 volt
output, while the 7809 produces 9 volts). The 78xx line are
positive voltage regulators, meaning that they are designed
to produce a voltage that is positive relative to a common

ground. There is a related line of 79xx devices which are

complementary negative voltage regulators. 78xx and 79xx
ICs can be used in combination to provide both positive
and negative supply voltages in the same circuit, if

Fig Regulator IC 78XX


Output current in Excess of 1.0 A

No external component required
Internal thermal overload protection
Internal short circuit current limiting
Output transistor safe-area compensation
Output voltage offered in 2% and 4% tolerance

Available I n surface mount D2PAK and standard 3-lead

transistor packages
Previous commercial temperature range has been
extended to a junction temperature range of -40 degree C to
+125 degree C.

Fig 5.5 Resistors

A resistor is a two-terminal
electronic component that produces a voltage across its
terminals that is proportional to the electric current passing through
it in accordance with Ohm's law:
V = IR

Resistors are elements of electrical networks and electronic

circuits and are ubiquitous in most electronic equipment.
Practical resistors can be made of various compounds and

films, as well as resistance wire (wire made of a highresistivity alloy, such as nickel/chrome).
The primary characteristics of a resistor are the resistance,
the tolerance, maximum working voltage and the power
rating. Other characteristics include temperature
coefficient, noise, and inductance. Less well-known is
critical resistance, the value below which power dissipation
limits the maximum permitted current flow, and above
which the limit is applied voltage. Critical resistance
depends upon the materials constituting the resistor as well
as its physical dimensions; it's determined by design.
Resistors can be integrated into hybrid and printed circuits,
as well as integrated circuits. Size, and position of leads (or
terminals) are relevant to equipment designers; resistors
must be physically large enough not to overheat when
dissipating their power.

Fig 5.6 Symbol of Resistance


Resistor restrict the flow of electric current, for example a

resistor is placed in series with a light-emitting diode(LED)
to limit the current passing through the LED.
It includes two types of resistors as carbon film and metal
film .These two types are explained under
CARBON FILM RESISTORS: During manufacture,
at in film of carbon is deposited onto a small ceramic
rod. The resistive coating is spiraled away in an
automatic machine until the resistance between there
two ends of the rods is as close as possible to the
correct value. Metal leads and end caps are added, the
resistors is covered with an insulating coating and
finally painted with colored bands to indicate the
resistor value

Fig Carbon film resistors

Fig Carbon Film Resistors Another example for a

Carbon 22000 Ohms or 22 Kilo-Ohms also known as

22K at 5% tolerance: Band 1 = Red, 1st digit Band 2 =

Red, 2nd digit Band 3 = Orange, 3rd digit, multiply
with zeros, in this case 3 zero's Band 4 = Gold,
Tolerance, 5%

METAL FILM RESISTORS: Metal film and metal oxides

resistors are made in a similar way, but can be made more accurately
to within 2% or 1% of their nominal vale there are some difference
in performance between these resistor types, but none which affects
their use in simple circuit.

WIRE WOUND RESISTOR: A wire wound resistor is made of

metal resistance wire, and because of this, they can be manufactured
to precise values. Also, high wattage resistors can be made by using a
thick wire material. Wire wound resistors cannot be used for high
frequency circuits. Coils are used in high frequency circuit. Wire
wound resistors in a ceramic case, strengthened with special cement.
They have very high power rating, from 1 or 2 watts to dozens of
watts. These resistors can become extremely hot when used for high
power application, and this must be taken into account when
designing the circuit.

Fig 5.8 Capacitor

A capacitor or condenser is a passive electronic component

consisting of a pair of conductors separated by a dielectric
(insulator). When a potential difference (voltage) exists
across the conductors, an electric field is present in the

dielectric. This field stores energy and produces a

mechanical force between the conductors. The effect is
greatest when there is a narrow separation between large
areas of conductor, hence capacitor conductors are often
called plates.
An ideal capacitor is characterized by a single constant
value, capacitance, which is measured in farads. This is the
ratio of the electric charge on each conductor to the
potential difference between them. In practice, the
dielectric between the plates passes a small amount of
leakage current. The conductors and leads introduce an
equivalent series resistance and the dielectric has an electric
field strength limit resulting in a breakdown voltage.
Capacitors are widely used in electronic circuits to block
the flow of direct current while allowing alternating current
to pass, to filter out interference, to smooth the output of
power supplies, and for many other purposes. They are
used in resonant circuits in radio frequency equipment to
select particular frequencies from a signal with many


Like a battery, a capacitor has two terminals. Inside the

capacitor, the terminals connect to two metal plates
separated by a dielectric. The dielectric can be air, paper,
plastic or anything else that does not conduct electricity and
keeps the plates from touching each other. You can easily
make a capacitor from two pieces of aluminum foil and a

piece of paper. It won't be a particularly good capacitor in

terms of its storage capacity, but it will work. In an
electronic circuit, a capacitor is shown like this:

Fig 5.9 Symbol of Capacitor

When you connect a capacitor to a battery, heres what

The plate on the capacitor that attaches to the negative
terminal of the battery accepts electrons that the battery is
The plate on the capacitor that attaches to the positive
terminal of the battery loses electrons to the battery.

Fig 5.10 Capacitor & Battery




An electrolytic capacitor is a type of capacitor that uses an

ionic conducting liquid as one of its plates with a larger
capacitance per unit volume than other types. They are
often referred to in electronics usage simply as
"electrolytics". They are valuable in relatively high-current
and low-frequency electrical circuits. This is especially the
case in power-supply filters, where they store charge
needed to moderate output voltage and current fluctuations
in rectifier output. They are also widely used as coupling
capacitors in circuits where AC should be conducted but
DC should not.Electrolytic capacitors can have a very high
capacitance, allowing filters made with them to have very
low corner frequencies.

Mica capacitors are high precision high stability high

reliability capacitors. They are available in small values,
and are mostly used at high frequencies.

Common in antique radio equipment, paper dielectric and

aluminum foil layers rolled into a cylinder and sealed with
wax. Low values up to a few F, working voltage up to
several hundred volts, oil-impregnated bathtub types to 5
kV used for motor starting and high-voltage power

supplies, and up to 25 kV for large oil-impregnated energy

discharge types.

The main differences between ceramic dielectric types are

the temperature coefficient of capacitance, and the
dielectric loss. C0G and NP0 (negative-positive-zero, i.e.
0) dielectrics have the lowest losses, and are used in
filters, as timing elements, and for balancing crystal
oscillators. Ceramic capacitors tend to have low inductance
because of their small size. NP0 refers to the shape of the
capacitor's temperature coefficient graph (how much the
capacitance changes with temperature). NP0 means that the
graph is flat and the device is not affected by temperature

These capacitors have a rotating plate (which can be rotated

to change the capacitance) separated from a fixed plate by a
dielectric medium. Typically values range from 5 pF to 60


A nine-volt battery, sometimes referred to by its

original designation as a PP3 battery is used here, the
battery has both the positive and negative terminals on one

end. The negative terminal is fashioned into a snap fitting

which mechanically and electrically connects to a mating
terminal on the power connector. The power connector has
a similar snap fitting on its positive terminal which mates to
the battery. This makes battery polarization obvious since
mechanical connection is only possible in one
configuration. The clips on the 9-volt battery can be used to
connect several 9-volt batteries in series. Inside a PP3 there
are six cells, either cylindrical alkaline or flat carbon-zinc
type, connected in series. Some brands use welded tabs
internally to attach to the cells, others press foil strips
against the ends of the cells. Finally we will connect this
assembly with a 9 volts PP3 dry battery, we find it
experimentally that RTC will work with low voltage
supplies. As mentions in the circuit diagram we connect it
to the appropriate space.

Fig 5.11 Battery

Fig Battery Connector


This circuit is one of the most basic and popular sensor

modules. In electronics, this sensor is analogous to humans
visionary senses which can be used to detect an obstacle
which is one of its common applications. In robotics, a
group of such modules are used so that a robot can follow a
line pattern.
The transmitter part of the sensor is an Infrared (IR)
Led which transmits continuous IR rays to be received by
an IR receiver. The output of the receiver varies depending
upon its reception of IR rays. Since this variation cannot be

analyzed as such, therefore this output can be fed to a

comparator. Here operational amplifier (op-amp) of LM
339 is
When the IR receiver does not receive signal the potential
at the inverting input goes higher than that that at noninverting input of the comparator (LM 339). Thus the
output of the comparator goes low and the LED does not
glow .When the IR receiver receives signal the potential at
the inverting input goes low. Thus the output of the
comparator (LM 339) goes high and the LED starts
glowing. Resistor R1 (100 ), R2 (10k ) and R3 (330 ) are
used to ensure that minimum 10 mA current passes through
the IR LED, photodiode and normal LED, respectively.
Resistor VR2 (preset=5k ) is used to adjust the output.
Resistor VR1 (preset=10k ) is used to set the sensitivity of
the circuit.


A simple Diode is the simplest two-terminal unilateral

semiconductor device. It allows current to flow only in one
direction and blocks the current that flows in the opposite
direction. The two terminals of the diode are called as
anode and cathode. The symbol of diode symbol is as
shown in the figure below.

The characteristics of a diode closely match to that of a

switch. An ideal switch when open does not conduct
current in either directions and in closed state conducts in
both directions. The characteristic of a diode is as shown in

Ideally, in one direction that is indicated by the arrow head

diode must behave short circuited and in other one that
opposite to that of the direction of arrow head must be open

circuited. By ideal characteristics, the diodes is designed to

meet these features theoretically but are not achieved
practically. So the practical diode characteristics are only
close to that of the desired.

Working of Diode:

The diode operates when a voltage signal is applied across

its terminals. The application of a DC voltage to make the
diode operate in a circuit is called as Biasing. As already
mentioned above the diode resembles to that of a one way
switch so it can either be in a state of conduction or in a
state of non conduction. The ON state of a diode is
achieved by Forward biasing which means that positive or
higher potential is applied to the anode and negative or
lower potential is applied at the cathode of the diode. In
other words, the ON state of diode has the applied current
in the same direction of the arrow head. The OFF state of
a diode is achieved by Reverse biasing which means that
positive or higher potential is applied to the cathode and

negative or lower potential is applied at the anode of the

diode. In other words, the OFF state of diode has the
applied current in the opposite direction of the arrow head.
During ON state, the practical diode offers a resistance
called as the Forward resistance. The diode requires a
forward bias voltage to switch to the ON condition which
is called Cut-in-voltage. The diode starts conducting in
reverse biased mode when the reverse bias voltage exceeds
its limit which is called as the Breakdown voltage. The
diode remains in OFF state when no voltage is applied
across it.
A simple p-n junction diode is fabricated by doping p and n
type layers on a silicon or germanium wafer. The
germanium and silicon materials are preferred for diode
fabrication because:
They are available in high purity.
Slight doping like one atom per ten million atoms of
a desired impurity can change the conductivity to a
considerable level.
The properties of these materials change on
applying heat and light and hence it is important in
the development of heat and light sensitive devices.


The other variant of diodes have different construction,

characteristics and applications. The different types of
diodes are:
Small signal or Small current diode - These
diodes assumes that the operating point is not
affected because the signal is small.
Large signal diodes - The operating point in these
diodes get affected as the signal is large.
Zener diodes - This diode runs in reverse bias
condition when the voltage reaches the breakdown
point. A stable voltage can be achieved by placing a
resistor across it to limit the current. This diode is
used to provide reference voltage in power supply
Light emitting diodes (LED) - This is the most
popular kind of diode. When it works in the forward
bias condition, the current flows through the
junction to produce the light.
Photodiodes - The electrons and holes are
generated as light strikes across the p-n junction
causing the current to flow. Theses diodes can work
as photodetector and are used to generate electricity.
Constant current diodes - This diode keeps the
current constant even when the voltage applied
keeps changing. It consists of JFET (junction field
effect transistor) with the source shorted to the gate
in order to function like a two - terminal current
limiter or current source.

Schottky diode - These diodes are used in RF

applications and clamping circuits. This diode has
lower forward voltage drop as against the silicon
PN junction diodes.
Shockley diode - This is a four layer diode which is
also known as PNPN diode. This didoe is similar to
thyristor where the gate is disconnected.
Step recovery diodes - This semiconductor diode
has the ability to generate short pulses and hence it
is used in microwave applications as a pulse
Tunnel diodes - This diode is heavily doped in the
forward bias condition that has a negative resistance
at extremely low voltage and a short circuit in the
negative bias direction. This diode is useful as a
microwave ampilifer and in oscillators.
Varactor diodes - This didoe works in reverse bias
condition and restricts the flow of current thorugh
the junction. Depending on the amount of biasing,
the width of the depletion region keeps varying.
This diode comprises of two plates of a capacitor
with the depletion region amidst them. The
variation in capacitance depends upon the depletion
region and this can varied by altering the reverse
bias on the diode.
PIN diodes - This diode has intrinsic
semiconductor sandwiched between P- type and Ntype region. Doping does not occur in this type of
diode and thereby the intrinsic semiconductor
increases the width of the depletion region. They

are used as ohtodiodes and radio frequency

LASER diode - This diode produces laser type of
light and are expensive as compared to LED. They
are widely used in CD and DVD drives.
Transient voltage supression diodes - This diode
is used to protect the electronics that are sensitive
against voltage spikes.
Gold doped diodes - These diodes use gold as the
dopant and can operate at signal frequencies even if
the forward voltage drop increases.
Super barrier diodes - These are also called as the
rectifier diodes. This diodes have the property of
low reverse leakage current as that of normal p-n
junction diode and low forward voltage drop as that
of Schottky diode with surge handling ability.
Point contact diodes - The construction of this
diode is simpler and are used in analog applications
and as a detector in radio receivers. This diode is
built of n type semiconductor and few conducting
metals placed to be in contact with the
semiconductor. Some metals move from towards
the semiconductor to form small region of p- tpye
semiconductor near the contact.
Peltier diodes - This diode is used as heat engine
and sensor for thermoelectric cooling.
Gunn diode - This diode is made of materials like
GaAs or InP that exhibit a negative differential
resistance region.

Crystal diode - These are a type of point contact

diodes which are also called as Cats whisker diode.
This didoe comprises of a thin sharpened metal wire
which is pressed against the semiconducting crystal.
The metal wire is the anode and the semconducting
crystal is the cathode. These diodes are obsolete.
Avalanche diode - This diode conducts in reverse
bias condition where the reverse bias volage applied
across the p-n junction creates a wave of ionization
leading to the flow of large current. These didoes
are designed to breakdown at specific reverse
voltage in order to avoid any damage.
Silicon controlled rectifier - As the name implies
this diode can be controlled or triggered to the ON
condition due to the application of small voltage.
They belong to the family of Tyristors and is used in
various fields of DC motor control, generator field
regulation, lighting system control and variable
frequency drive . This is three terminal device with
anode, cathode and third controled lead or gate.
Vaccum diodes - This diode is two electrode
vacuum tube which can tolerate high inverse

Generic diodes (Small signal and large signal):

A p-n junction diode is the simplest semiconductor device.

It is a two-terminal, bipolar, unilateral rectifying device that
conducts only in one direction. The generic diodes are used
in the following fields:

Rectification in power supply circuits

Extraction of modulation from radio signals in a

radio receiver and in protection circuits where large
transient currents may appear on low current transistors or
ICs in interfacing with relays or other high power devices.

Used in series with power inputs to electronic circuits

where only one of negative or positive polarity voltage is


A simple p-n diode is a junction where p-type and n-type

layers are doped on a silicon or germanium wafer. A p-type
semiconductor is formed by doping of trivalent or acceptor
impurity atoms on a pure silicon or germanium thereby
having an excess concentration of holes. An n-type
semiconductor is formed by doping of pentavalent or donor
impurity atoms on a pure silicon or germanium thereby
having an excess concentration of electrons. So, holes are
the majority charge carriers in a p-type region whereas
electrons in the n-type region. Electron-holes pairs are
thermally generated in both types which constitute the

minority charge carriers. It is remarkable that a p-type

material is not positively charged in spite of having
excessive holes while an n-type material is not negatively
charged in spite of excessive electrons. This is because in a
p-type material along with holes, the anions are generated
and the total number of protons and electrons still remain
the same. This is similarly observed for the n-type material.
The junction of a p-type and n-type doping on silicon or
germanium wafer produces a small region of the order of
micrometers which is depleted from the free charge
carriers. This region is formed due to diffusion of holes
from a p-type and electrons from an n-type material called
as the depletion region or space charge region or transition
region. The p-type region to the left of the depletion region
is having acceptor negative ion layer and to the right are
donor positive ion layer which induces an electric flux or
potential difference across the junction. The charge
concentration is positive on left of the junction and
negative on the right of the junction. This potential barrier
stops the holes to migrate into n-type region and electrons
to migrate into p-type region as the potential rises for holes
and electrons will allow migrating in to n-type and p-type
regions. The charge carrier regions around the depletion
regions are also called as the uncovered regions. This is
shown in graph below.

It is also important that the minority charge currents i.e.

electron current in p-type region and hole current in n-type
region decreases exponentially across the diode length.

The minority current is due to electron hole pairs generated

thermally and dependent upon temperature. These currents
are so small in magnitude in the order of microamperes.
However in conduction state, the current through the diode
crystal remains stable. The total current is a sum of
minority and majority charge currents due to bipolar nature
of the diode. The majority charge currents is hole current in
p-type and electron current in n-type are reduced as they
migrate near junction due recombination. The minority
currents is electron current in p-type and hole current in ntype are maximum near junction and reduces as they
migrate away from the junction as an exponential function.
The majority charge currents in their regions after crossing
the junction are the diffusion currents while before junction
are drift currents.
Concept of Ohmic contacts In addition to PN junction
diode, there is a two metal semiconductor junctions
originating from the leads in order to connect the device. It
is assumed that the resistance of these metal semiconductor
contacts remain constant despite of the magnitude and
direction of current. During the diode operation, the applied
voltage is solely effective for increasing or decreasing the
potential barrier height of the PN junction.

Principle and Operation:

The possible configurations for a diode are:

Open circuited
Short circuited
Forward biased
Reverse biased
Open circuited: In open circuited condition, the
current that flows through the diode is zero (I = 0). The
potential barrier at the PN junction remains the same as
created in the diode fabrication.

Short circuited: In short circuited condition, the sum
voltage in the loop must be zero. So it is assumed, that the
potential barrier at the PN junction is compensated by the
potential drops at the metal semiconductor junctions. The
holes supplied by the n-region must be driven to the p
region which is physically impossible. The similar
discussion applies to the electron current in the n-region.

Conclusion: The potential barrier height cannot be measured directly by a


Forward bias: In forward bias condition, higher or
positive potential is applied at the anode and negative or
lower potential is applied at the cathode of a diode. The
positive potential at anode repels the holes in p-region
towards n-region while negative potential at the cathode
repels electrons in n-region towards p-region. Thus, the
height of the potential barrier reduces. The depletion region
disappears when the applied voltage equals to the potential
barrier and a large current flows through the diode. The
voltage required to drive the diode into a state of
conduction is called as the Cut in/Offset/Threshold/Firing
voltage. The current is of considerable magnitude as it is
dominantly constituted by the majority charge currents that
is the hole current in the p-region and the electron current
in the n-region. The current that flows from anode to
cathode is limited by the crystal bulk resistance,
recombination of charges and the ohmic contact resistances

at the two metal semiconductor junctions. The current is

restricted to mille Amperes order.

Reverse Bias: In reverse bias condition, the higher
or positive potential is applied at the cathode and negative
or lower potential is applied at the anode. The negative
potential at anode attracts the holes in p-region that are
away from the n-region while positive potential at the
cathode attracts electrons in n-region that are away from
the p-region. The applied voltage increases the height of the
potential barrier. The current flows dominantly due to the
minority charge currents that is the electron current in pregion and the hole current in n-region. Thus a constant
current of negligible magnitude flows in the reverse
direction which is called as the Reverse saturation
current. Practically, the diode remains in a state of non
conduction. The reverse saturation current is of the order of
microamperes in a germanium diode or nanoamperes in a
silicon diode If the reverse voltage exceeds the limit of
breakdown/zener/Peak inverse/Peak reverse voltage, the
potential breakdown that occurs leads to a large reverse


The current that flows through a diode is given by the

where ID - diode current. (Positive for forward and
negative for reverse)
IS - constant reverse saturation current
V - applied voltage. (Positive for forward and
negative for reverse)
- factor dependent upon the nature of semiconductor. (1
germanium and 2 for silicon)
VT - volt equivalent of temperature which is given
by T/11600. (T is
Temperature in Kelvin)
When a forward voltage is applied at the terminals of a
diode, the diode begins to conduct. During conduction, the
cut in or threshold voltage exceeds the applied forward
voltage. The threshold voltage for a germanium diode is
0.3V and for silicon diode is 0.7V. The forward current
(miliampere range) initially increases linearly and then
increases exponentially for high currents.
When a a reverse voltage is applied, a reverse saturation
current flows through the diode. The diode continues to be
in the non conducting state until the reverse voltage drops
below the zener voltage. As the reverse voltage
approximates the peak inverse voltage a breakdown called

as the Avalanche breakdown occurs. During the

breakdown, the minority charge carriers ionize the stable
atoms which are followed by a chain ionization to generate
a large number of free charge carriers. Thus the diode
becomes short circuited and gets damaged.
Note: When diodes are connected in series their equivalent
peak inverse voltage is increased while in parallel
connection the current carrying capacity is increased.
As the temperature increases, the electron pairs generated
thermally also increases thereby increasing the conductivity
in both directions. The reverse saturation current also
increases with the increase in temperature. The change is
11% per C for a germanium diode and 8% per C for a
silicon diode. On the other hand the diode current is
doubled for every 10C rise. With increase in voltage, the
firing voltage in forward characteristics is reduced while
peak reverse voltage is increased.
Note: The peak inverse voltage can be reduced by
increasing the doping level. The same concept is used to
design zener diodes.
Diode resistances: The resistance associated with the
diode can be evaluated in three fashions and the three types
of resistances associate with a diode accordingly.

DC or Static resistance: It is the ratio of diode

voltage to the diode current at any point of its characteristic
curves. It is defined at a point on the characteristic curves.

AC or dynamic resistance: It is the ratio of change in
diode voltage to the change in diode current. It is defined at
a point on the characteristic curves over a tangent.

Average AC resistance: It is the ratio of change in

diode voltage to the change in diode current over a straight
line joining two limits of operation.

Diode capacitances: The diode exhibits two types of

capacitances transition capacitance and diffusion

Transition capacitance: The capacitance which appears
between positive ion layer in n-region and negative ion
layer in p-region.

Diffusion capacitance: This capacitance originates

due to diffusion of charge carriers in the opposite regions.
The transition capacitance is very small as compared to the
diffusion capacitance.
In reverse bias transition, the capacitance is the dominant
and is given by:
where CT - transition capacitance

A - diode cross sectional area

W - depletion region width
In forward bias, the diffusion capacitance is the dominant

CD -


dQ - change in charge stored in depletion region
V - change in applied voltage
- time interval for change in voltage
g - diode conductance
r - diode resistance
The diffusion capacitance at low frequencies is given by

The diffusion capacitance at high frequencies is inversely

proportional to the frequency and is given by the formula:


Diodes are used in various applications like rectification,

clipper, clamper, voltage multiplier, comparator, sampling
gates and filters.
Rectification The rectification means converting
AC voltage into DC voltage. The common rectification
circuits are half wave rectifier (HWR), full wave rectifier
(FWR) and bridge rectifier.

Half wave rectifier: This circuit rectifies

either positive or negative pulse of the input AC. The figure
is as shown below:

Full wave rectifier: This circuit converts the

entire AC signal into DC. The figure is as shown below:

Bridge rectifier: This circuit converts the entire

AC signal into DC. The figure is as shown below:

Clipper- Diode can be used to clip off some portion
of pulse without distorting the remaining part of the
waveform. The figure is as shown below:

Clamper A clamping circuit restricts the voltage
levels to exceed a limit by shifting the DC level. The peak
to peak is not affected by clamping. Diodes with resistors
and capacitors are used to make clamping circuits.
Sometimes independent DC sources can be used to provide
additional shift. The figure is as shown below:

Datasheet Analysis:

The datasheets of the diodes gives valuable stuff about their

various parameters such as:

Peak inverse voltage,

Reverse saturation currents at specified reverse


Maximum forward current,

Capacitance levels,
rse recovery time,

Storage and operating temperatures,

Peak repetitive forward current,

Peak forward surge current,

Average surge current and many more. .

The graphs to represent the voltage current characteristics

and temperature dependences are also supplied.

Rectifying Diodes in Market:

Diodes designated from IN4001 to IN4007 are

available with maximum forward voltage of 1.1 V and 1A
being the maximum rectifying current. The maximum
reverse current are 5 uA and PIV (Peak Inverse voltage)
varies from 50V to 1000V.

Another series of diodes is IN5400 to IN5408 with

maximum forward voltage of 1.2 V and 3A being the
maximum rectifying current. The maximum reverse current
are 5 uA and PIV (Peak Inverse voltage) varies from 50V to

Testing of a diode:

A diode can be open circuited or short circuited when

damaged. It can be tested using a multimeter by following
the steps given below:

Insert the probes into the required sockets: The digital
multimeter will have several sockets for the test probes.
Insert these probes and check if they are already in the
correct sockets. Typically, these are labeled COM for
common and the others for current or voltage. This is
normally combined with the voltage measurement socket.
Turn on the multimeter and select the maximum
resistance range.
Check resistance in forward and reverse direction.
Place the red probe on diode anode and black probe on the
cathode to measure the forward resistance. Place the red
probe on diode cathode and black probe on anode to
measure the backward resistance. The forward resistance
must be very small in few ohms while backward resistance
must be very high in the range of mega ohms. If forward
resistance is very high the diode is open circuited and if
backward resistance is very small diode will be short
Another way is to select diode on the multimeter.
Place the red probe on diode anode and black probe on the
cathode and of the multimeter beeps then it indicates a
short circuit otherwise it is open. Place the red probe on
diode cathode and black probe on the anode and if the
multimeter does not beep then it indicates an open circuit
otherwise if it beeps the diode is short.
Turn off the multimeter: Once the resistance
measurement has been made, the multimeter can be turned
off to preserve the batteries. It is also wise to turn the
function switch to a high voltage range. In this way, if the
multimeter is used again for another type of reading then no

damage will be caused if it is inadvertently used without

selecting the correct range and function.


Circumstances that we find ourselves in today in the field

of microcontrollers had their beginnings in the
development of technology of integrated circuits. This
development has made it possible to store hundreds of
thousands of transistors into one chip. That was a
prerequisite for production of microprocessors, and the first
computers were made by adding external peripherals such
as memory, input-output lines, timers and other. Further
increasing of the volume of the package resulted in creation
of integrated circuits. These integrated circuits contained
both processor and peripherals. That is how the first chip
containing a microcomputer, or what would later be known
as a microcontroller came about.
Definition of a Microcontroller

Microcontroller, as the name suggests, are small

controllers. They are like single chip computers that are
often embedded into other systems to function as
processing/controlling unit. For example, the remote
control you are using probably has microcontrollers inside
that do decoding and other controlling functions. They are
also used in automobiles, washing machines, microwave
ovens, toys ... etc, where automation is needed.
The key features of microcontrollers include:
High Integration of Functionality
Microcontrollers sometimes are called single-chip
computers because they have on-chip memory and I/O
circuitry and other circuitries that enable them to

function as small standalone computers without other

supporting circuitry.
Field Programmability, Flexibility
Microcontrollers often use EEPROM or EPROM as
their storage device to allow field programmability so
they are flexible to use. Once the program is tested to
be correct then large quantities of microcontrollers can
be programmed to be used in embedded systems.
Easy to Use
Assembly language is often used in microcontrollers
and since they usually follow RISC architecture, the
instruction set is small. The development package of
microcontrollers often includes an assembler, a
simulator, a programmer to "burn" the chip and a
demonstration board. Some packages include a high
level language compiler such as a C compiler and
more sophisticated libraries.

Most microcontrollers will also combine other devices such

A Timer module to allow the microcontroller to
perform tasks for certain time periods.
A serial I/O port to allow data to flow between the
microcontroller and other devices such as a PC or
another microcontroller.
An ADC to allow the microcontroller to accept
analogue input data for processing.

Figure 2.1: Showing a typical microcontroller device and its different


The heart of the microcontroller is the CPU core. In the

past this has traditionally been based on an 8-bit
microprocessor unit.
Microcontrollers versus Microprocessors

Microcontroller differs from a microprocessor in many

ways. First and the most important is its functionality. In
order for a microprocessor to be used, other components
such as memory, or components for receiving and sending
data must be added to it. In short that means that
microprocessor is the very heart of the computer. On the
other hand, microcontroller is designed to be all of that in
one. No other external components are needed for its
application because all necessary peripherals are already

built into it. Thus, we save the time and space needed to
construct devices
Memory unit

Memory is part of the microcontroller whose function is to

The easiest way to explain it is to describe it as one big
closet with lots of drawers. If we suppose that we marked
the drawers in such a way that they can not be confused,
any of their contents will then be easily accessible. It is
enough to know the designation of the drawer and so its
contents will be known to us for sure.

Figure2.2: Simplified model of a memory unit

Memory components are exactly like that. For a certain

input we get the contents of a certain addressed memory
location and that's all. Two new concepts are brought to us:
addressing and memory location. Memory consists of all
memory locations, and addressing is nothing but selecting

one of them. This means that we need to select the desired

memory location on one hand, and on the other hand we
need to wait for the contents of that location. Besides
reading from a memory location, memory must also
provide for writing onto it. This is done by supplying an
additional line called control line. We will designate this
line as R/W (read/write). Control line is used in the
following way: if r/w=1, reading is done, and if opposite is
true then writing is done on the memory location. Memory
is the first element, and we need a few operation of our
The amount of memory contained within a microcontroller
varies between different microcontrollers. Some may not
even have any integrated memory (e.g. Hitachi 6503, now
discontinued). However, most modern microcontrollers
will have integrated memory. The memory will be divided
up into ROM and RAM, with typically more ROM than
Typically, the amount of ROM type memory will vary
between around 512 bytes and 4096 bytes, although some
16 bit microcontrollers such as the Hitachi H8/3048 can
have as much as 128 Kbytes of ROM type memory.
ROM type memory, as has already been mentioned, is used
to store the program code. ROM memory can be ROM (as
in One Time Programmable memory), EPROM, or
The amount of RAM memory is usually somewhat smaller,
typically ranging between 25 bytes to 4 Kbytes.

RAM is used for data storage and stack management tasks.

It is also used for register stacks (as in the microchip PIC
range of microcontrollers).
Central Processing Unit

Let add 3 more memory locations to a specific block that

will have a built in capability to multiply, divide, subtract,
and move its contents from one memory location onto
another. The part we just added in is called "central
processing unit" (CPU). Its memory locations are called

Figure: Simplified central processing unit with three

Registers are therefore memory locations whose role is to
help with performing various mathematical operations or
any other operations with data wherever data can be found.
Look at the current situation. We have two independent
entities (memory and CPU) which are interconnected, and
thus any exchange of data is hindered, as well as its
functionality. If, for example, we wish to add the contents
of two memory locations and return the result again back to

memory, we would need a connection between memory

and CPU. Simply stated, we must have some "way"
through data goes from one block to another.

That "way" is called "bus". Physically, it represents a group

There are two types of buses: address and data bus. The
first one consists of as many lines as the amount of memory
we wish to address and the other one is as wide as data, in
our case 8 bits or the connection line. First one serves to
transmit address from CPU memory, and the second to
connect all blocks inside the microcontroller.

Figure: Showing connection between memory and central

unit using buses
As far as functionality, the situation has improved, but a
new problem has also appeared: we have a unit that's
capable of working by itself, but which does not have any
contact with the outside world, or with us! In order to

remove this deficiency, let's add a block which contains

several memory locations whose one end is connected to
the data bus, and the other has connection with the output
lines on the microcontroller which can be seen as pins on
the electronic component.
Input-output unit

Those locations we've just added are called "ports". There

are several types of ports: input, output or bidirectional
ports. When working with ports, first of all it is necessary
to choose which port we need to work with, and then to
send data to, or take it from the port.

Figure: Simplified input-output unit communicating with

external world
When working with it the port acts like a memory location.
Something is simply being written into or read from it, and
it could be noticed on the pins of the microcontroller.
Serial communication

Beside stated above we've added to the already existing

unit the possibility of communication with an outside
world. However, this way of communicating has its
drawbacks. One of the basic drawbacks is the number of
lines which need to be used in order to transfer data. What
if it is being transferred to a distance of several kilometers?
The number of lines times number of kilometers doesn't
promise the economy of the project. It leaves us having to
reduce the number of lines in such a way that we don't
lessen its functionality. Suppose we are working with three
lines only, and that one line is used for sending data, other
for receiving, and the third one is used as a reference line
for both the input and the output side. In order for this to
work, we need to set the rules of exchange of data. These
rules are called protocol. Protocol is therefore defined in
advance so there wouldn't be any misunderstanding
between the sides that are communicating with each other.
For example, if one man is speaking in French, and the
other in English, it is highly unlikely that they will quickly
and effectively understand each other. Let's suppose we
have the following protocol. The logical unit "1" is set up
on the transmitting line until transfer begins. Once the
transfer starts, we lower the transmission line to logical "0"
for a period of time (which we will designate as T), so the
receiving side will know that it is receiving data, and so it
will activate its mechanism for reception. Let's go back
now to the transmission side and start putting logic zeros
and ones onto the transmitter line in the order from a bit of
the lowest value to a bit of the highest value. Let each bit
stay on line for a time period which is equal to T, and in the

end, or after the 8th bit, let us bring the logical unit "1"
back on the line which will mark the end of the
transmission of one data. The protocol we've just described
is called in professional literature NRZ (Non-Return to

Figure: Serial unit sending data through three lines only

As we have separate lines for receiving and sending, it is
possible to receive and send data (info.) at the same time.
So called full-duplex mode block which enables this way of
communication is called a serial communication block.
Unlike the parallel transmission, data moves here bit by bit,
or in a series of bits what defines the term serial
communication comes from. After the reception of data we
need to read it from the receiving location and store it in
memory as opposed to sending where the process is
reversed. Data goes from memory through the bus to the
sending location, and then to the receiving unit according to
the protocol.
Timer unit

Since we have the serial communication explained, we can

receive, send and process data.

Figure: Timer unit generating signals in regular time

However, in order to utilize it in industry we need a few
additionally blocks. One of those is the timer block which
is significant to us because it can give us information about
time, duration, protocol etc. The basic unit of the timer is a
free-run counter which is in fact a register whose numeric
value increments by one in even intervals, so that by taking
its value during periods T1 and T2 and on the basis of their
difference we can determine how much time has elapsed.
This is a very important part of the microcontroller whose
understanding requires most of our time.

One more thing is requiring our attention is a flawless

during its run-time. Suppose that as a result of some
interference (which often does occur in industry) our
microcontroller stops executing the program, or worse, it
starts working incorrectly.

Figure2.8: Watchdog
Of course, when this happens with a computer, we simply
reset it and it will keep working. However, there is no reset
button we can push on the microcontroller and thus solve
our problem. To overcome this obstacle, we need to
introduce one more block called watchdog. This block is in
fact another free-run counter where our program needs to
write a zero in every time it executes correctly. In case that
program gets "stuck", zero will not be written in, and
counter alone will reset the microcontroller upon achieving
its maximum value. This will result in executing the
program again, and correctly this time around. That is an
important element of every program to be reliable without
man's supervision.
Analog to Digital Converter

As the peripheral signals usually are substantially different

from the ones that microcontroller can understand (zero and
one), they have to be converted into a pattern which can be
comprehended by a microcontroller. This task is performed
by a block for analog to digital conversion or by an ADC.
This block is responsible for converting an information
about some analog value to a binary number and for follow
it through to a CPU block so that CPU block can further
process it.

Figure: Block for converting an analog input to digital

Finally, the microcontroller is now completed, and all we
need to do now is to assemble it into an electronic
component where it will access inner blocks through the
outside pins. The picture below shows what a
microcontroller looks like inside.

Figure: Physical configuration of the interior of a

Thin lines which lead from the center towards the sides of
the microcontroller represent wires connecting inner blocks
with the pins on the housing of the microcontroller so
called bonding lines. Chart on the following page
represents the center section of a microcontroller.

Figure: Microcontroller outline with basic elements and

internal connections
For a real application, a microcontroller alone is not
enough. Beside a microcontroller, we need a program that
would be executed, and a few more elements which make
up interface logic towards the elements of regulation
(which will be discussed in later chapters).


Figure2.12 Pin configuration of

VCC (Pin 40) Provides voltage to the chip . +5V
GND (Pin 20) Ground

XTAL1 (Pin 19) and XTAL2 (Pin 18) Crystal Oscillator

connected to pins 18, 19.
RST (Pin 9) RESET pin
External Access: EA 31
Connected to VCC for on chip ROM
Connected to Ground for external ROM containing the
code Input Pin

Program Store Enable: PSEN 29

Output Pin
Address Latch Enable: ALE 30
\Output Pin . Active high .
I/O Port Pins and their Functions:
Four ports P0,P1,P2,P3 with 8 pins each, making a total of
32 input/output pins.

Pins 32-39

Can be used as both Input or Output

External pull up resistors of 10K need to be connected

Dual role: 8051 multiplexes address and data through

port 0 to save pins .AD0-AD7

ALE is used to de multiplex data and address bus


Pins 1 through 8

Both input or output

No dual function

Internal pull up registers

On RESET configured as output


Pins 21 through 28

No external pull up resistor required

Both input or output

Dual Function: Along with Port 0 used to provide the

16-Bit address for external memory. It provides
higher address A8-A16


Pins 10 through 17
No external pull up resistors required

We have 4 ports in 8051 micro controller. They are port0,

port1, port2, port3 which can
be accessed as i/o ports. The pins of the micro controller
are explained below.
Reset: It resets total 8051 micro controller.
RXD: It receives data in serial communication.
TXD: It transmits data in serial communication.
INT0: External interrupt for timer 0.
INT1: External interrupt for timer1
T0: Timer0.
T1: Timer1.
RD: To read into external memory.
WR: To write into external memory.
XTAL1 & XTAL2: To connect the crystal oscillator.

ALE: Address latch enable which is used to access the

address locations
from external memory.
PSEN: Program store enable which is used for storing
code into the external memory.
EA: External Access: 64 KB of ROM is the limit for
external memory.


Fig 2.13 RAM Architecture

The 8051 has a bank of 128 bytes of Internal RAM. This
Internal RAM is found on-chip on the 8051 so it is the
fastest RAM available, and it is also the most flexible in
terms of reading, writing, and modifying its contents.
Internal RAM is volatile, so when the 8051 is reset this
memory is cleared. The 128 bytes of internal ram is
subdivided as shown on the memory map. The first 8 bytes
(00h - 07h) are "register bank 0". These alternative register
banks are located in internal RAM in addresses 08h
through 1Fh.Bit memory actually resides in internal RAM,
from addresses 20h through 2Fh. The 80 bytes remaining of
Internal RAM, from addresses 30h through 7Fh, may be

used by user variables that need to be accessed frequently

or at high-speed. This area is also utilized by the
microcontroller as a storage area for the operating stack.
Register Banks

The 8051 uses 8 "R" registers which are used in many of its
instructions. These "R" registers are numbered from 0
through 7 (R0, R1, R2, R3, R4, R5, R6, and R7).These
registersare generally used to assist in manipulating values
and moving data from one memory location to another. The
concept of register banks adds a great level of flexibility to
the 8051.

Bit Memory

The 8051, being a communication oriented microcontroller,

gives the user the ability to access a number of bit
variables. These variables may be either 1 or 0. There are
128 bit variables available to the user, numbered 00h
through 7Fh. The user may make use of these variables
with commands such as SETB and CLR. It is important to
note that Bit Memory is really a part of Internal RAM. In
fact, the 128 bit variables occupy the 16 bytes of Internal
RAM from 20h through 2Fh.

Special Function Register (SFR) Memory

Special Function Registers (SFRs) are areas of memory that

control specific functionality of the 8051 processor. For
example, four SFRs permit access to the 8051s 32
input/output lines. Another SFR allows a program to read
or write to the 8051s serial port .SFR is a part of Internal
Memory. This is not the case. When using this method of
memory access (its called direct address), any instruction
that has an address of 00h through 7Fh refers to an Internal
RAM memory address; any instruction with an address of
80h through FFh refers to an SFR control register.
The Accumulator

The Accumulator, as its name suggests, is used as a general

register to accumulate the results of a large number of
instructions. It can hold an 8-bit (1-byte) value and is the
most versatile register
The "R" registers

The "R" registers are a set of eight registers that are named
R0, R1, etc. up to and including R7. These registers are
used as auxiliary registers in many operations.

The "B" Register

The "B" register is very similar to the Accumulator in the

sense that it may hold an 8-bit (1-byte) value. The "B"
register is only used by two 8051 instructions: MUL AB
and DIV AB.
The Data Pointer (DPTR)

The Data Pointer (DPTR) is the 8051s only user-accessible

16-bit (2-byte) register. The Accumulator, "R" registers,
and "B" register are all 1-byte values. DPTR, as the name
suggests, is used to point to data. It is used by a number of
commands which allow the 8051 to access external
The Program Counter (PC)

The Program Counter (PC) is a 2-byte address which tells

the 8051 where the next instruction to execute is found in
memory. When the 8051 is initialized PC always starts at
0000h and is incremented each time an instruction is
The Stack Pointer (SP)

The Stack Pointer, like all registers except DPTR and PC,
may hold an 8-bit (1-byte) value. The Stack Pointer is used
to indicate where the next value to be removed from the

Addressing Modes

An "addressing mode" refers to how you are addressing a

given memory location. The addressing modes are as
With an example of each:
Immediate Addressing MOV A, #20h
Direct Addressing MOV A, #30h
Indirect Addressing MOV A, @R0
External Direct MOVX A, @DPTR
Code Indirect MOVC A, @A+DPTR
Each of these addressing modes provides important

An interrupt is a special feature which allows the 8051 to

provide the illusion of "multitasking," although in reality
the 8051 is only doing one thing at a time.

Timers are one of the categories of hardware time delays.

Time delays are used to keep a system into halting System
or sleepy mode. We have two timers-timer0,
timer1.Hardware time delays are used to generate exact
time delays.

L14G2 is an NPN phototransistor. It acts as a photodetector
in the sense that it can convert the incident light into
electric response. They are commonly used as sensors
usually paired with a light source like LED.
These are the bipolar transistors having a transparent case.
This transparent case exposes the base collector region of
transistor to external light. When light incidents on this
junction, electrons are generated by the photons. These
electrons are injected in the base of phototransistor. The
current gain of the transistor amplifies the resulting
photocurrent at the base collector junction. Thus a
phototransistor conducts in the presence of light and
remains in off mode in absence of light. The maximum
dark current is 100nA; while in light its current is 500A.
A phototransistor is different from a simple transistor in the
way that in the latter, voltage applied to the base is replaced
by light striking it. Simply put, a phototransistor amplifies
variations in the light striking it.
*Phototransistors may or may not have a base terminal. If a
base terminal is available, it is used to bias its light
Photodiodes can also be used for similar function as
phototransistors, but they have much lower gain and thus
lower photocurrent. Phototransistors cannot detect low
intensities of light but are more responsive to the exposed

light. Also, the transistor response lasts for a longer period

as compared to a photodiode.
The required light source is a gallium arsenide LED with
peak wavelength is 940 nm. The emitter lead is indicated
by a protruding edge in the transistor case. The base is
nearest to the emitter. The collector is at the other extreme
Pin Diagram:

BC547 is an NPN bi-polar junction transistor. A
transistor, stands for transfer of resistance, is
commonly used to amplify current. A small current at
its base controls a larger current at collector & emitter
BC547 is mainly used for amplification and switching
purposes. It has a maximum current gain of 800. Its
equivalent transistors are BC548 and BC549.
The transistor terminals require a fixed DC voltage to
operate in the desired region of its characteristic
curves. This is known as the biasing. For amplification
applications, the transistor is biased such that it is
partly on for all input conditions. The input signal at
base is amplified and taken at the emitter. BC547 is
used in common emitter configuration for amplifiers.
The voltage divider is the commonly used biasing
mode. For switching applications, transistor is biased
so that it remains fully on if there is a signal at its

base. In the absence of base signal, it gets

Pin Diagram:

An IR LED, also known as IR transmitter, is a special
purpose LED that transmits infrared rays in the range
of 760 nm wavelength. Such LEDs are usually made
of gallium arsenide or aluminium gallium arsenide.
They, along with IR receivers, are commonly used as
The appearance is same as a common LED. Since
the human eye cannot see the infrared radiations, it is
not possible for a person to identify whether the IR
LED is working or not, unlike a common LED. To
overcome this problem, the camera on a cellphone
can be used. The camera can show us the IR rays
being emanated from the IR LED in a circuit.

Pin Diagram:


A seven segment display is the most basic electronic

display device that can display digits from 0-9. They find
wide application in devices that display numeric
information like digital clocks, radio, microwave ovens,
electronic meters etc. The most common configuration has
an array of eight LEDs arranged in a special pattern to
display these digits. They are laid out as a squared-off
figure 8. Every LED is assigned a name from 'a' to 'h' and
is identified by its name. Seven LEDs 'a' to 'g' are used to

display the numerals while eighth LED 'h' is used to display

the dot/decimal.
A seven segment is generally available in ten pin package.
While eight pins correspond to the eight LEDs, the
remaining two pins (at middle) are common and internally
shorted. These segments come in two configurations,
namely, Common cathode (CC) and Common anode (CA).
In CC configuration, the negative terminals of all LEDs are
connected to the common pins. The common is connected
to ground and a particular LED glows when its
corresponding pin is given high. In CA arrangement, the
common pin is given a high logic and the LED pins are
given low to display a number.
Pin Diagram:

This version is a common anode version. That means that

the positive leg of each LED is connected to a common
point which is pin 3 in this case. Each LED has a negative
leg that is connected to one of the pins of the device. To
make it work you need to connect pin 3 to 5 volts. Then
to make each segment light up, connect the ground pin for
that led to ground. A resistor is required to limit the
current. Rather than using a resistor from each LED to
ground, you can just use one resistor from Vcc to pin 3 to
limit the current.
The following table shows how to form the numbers 0 to
9 and the letters A, b, C, d, E, and F.
'0' means that pin is connected to ground. '1' means that
pin is connected to Vcc.