You are on page 1of 117

Practical No.

Aim: Study of the embedded system Components

What is an Embedded Systems?

An embedded system is a special-purpose system in which the computer is completely


encapsulated by the device it controls. Unlike a general-purpose computer, such as a
personal computer, an embedded system performs pre-defined tasks, usually with very
specific requirements. Embedded systems evolved with general-purpose computer systems.
Although embedded systems have been around for some time, there is a renewed interest
now.

Why embedded Systems


Embedded systems are used in most house appliances, cars, electrical devices, and industrial
devices and tools. Mobile phone is a typical example of an embedded system.
This seems to be a long-lasting trend in front of us, of the same or larger impact and
disruption than the appearance of the World Wide Web. Being widespread poses some hard
requirements on embedded systems. They must be as reliable and robust as other house
appliances; as easy to use and as available; connected with other devices, requiring adherence
to standards of some kind; and low cost.

A Typical Embedded System

1
Microprocessors
A microprocessor incorporates the functions of a computer's central processing unit (CPU)
on a single integrated circuit, (IC) or at most a few integrated circuits. It is a multipurpose,
programmable device that accepts digital data as input, processes it according to instructions
stored in its memory, and provides results as output

Microcontrollers
A microcontroller can be considered a self-contained system with a processor, memory and
peripherals and can be used as an embedded system. The majority of microcontrollers in use
today are embedded in other machinery, such as automobiles, telephones, appliances, and
peripherals for computer systems.

These are called embedded systems.

1) 8051 Microcontroller

About 8051 Microcontroller

• The Intel 8051 microcontroller is one of the most popular general purpose
microcontrollers in use today. The success of the Intel 8051 spawned a number of clones
(also called derivatives) which are collectively referred to as the MCS-51 family of
microcontrollers, which includes chips from vendors such as Atmel, Philips, Infineon,
and Texas Instruments.

• 8051 chips are used in a wide variety of control systems, telecom applications, and
robotics as well as in the automotive industry. By an estimate, 8051 family chips make
up significant part of the embedded chip market.

2
8051 Variants
• The 8051 has the widest range of variants of any embedded controller in the market.

• The smallest device is the Atmel89c1051, a 20 pin flash variant with 2 timers, UART,
20mA.

• The fastest parts are from Dallas, with performance close to 10MIPS.

• The most powerful chip is the Siemens 80C517A, with 32-bit ALU, 2 UARTs, 2K RAM,
PLCC84 package, 8×16 bit PWMsand other features.

Among the major manufacturers are:

• AMD:- Enhanced 8051 parts ( no longer producing 80×51 parts)

• Atmel:- FLASH and semi-custom parts

• Dallas:- Battery backed, program download, and fastest variants

• Intel:- 8051 through 80c51gb/80c51sl

• ISSI:- IS80C51/31 runs up to 40MHz

• Matra:- 80c154, low voltage static variants

• OKI:- 80c154, mask parts

• Philips:- 87c748 through 89c588-more variants than anyone else

• Siemens:- 80c501 through 80c517a, and SIECO cores

• SMC:- COM20051 with ARCNET token bus network engine

• SSI:- 80×52, 2×HDLC variant for MODEM use

3
Intel 8051

ROM [on chip program space in bytes] 4K

RAM [bytes] 128

Timers 2

I/O pins 32

Serial port 1

Interrupt sources 6

Basic features of 8051:

The 8051 is the original member of the MCS-51 family, and is the core for all MCS-51 devices.

The features of the 8051 core are-

• 8-bit CPU optimized for control applications

• Sixteen bit program counter (PC) and data pointer (DPTR).

• Eight bit program status word (PSW).

• Eight bit stack pointer (SP).

• Extensive Boolean processing (single-bit logic)capabilities

4
• 64K program memory address space

• 64K data memory address space

• 4K bytes of on-chip program memory

• 128 bytes of on-chip data RAM

Four register banks, each containing eight registers.

Sixteen bytes, of bit addressable memory locations.

Eighty bytes of general-purpose data memory.

• 32 bidirectional and individually addressable I/O lines(4groups of eight)

• Two 16 bit timers/counters

• Full duplex 8-bit serial data transmitter/receiver (UART)

• Control registers: TCON, TMOD, SCON, PCON, IP and IE among SFRs

• Thirty two I/O pins arranged as four 8-bit ports P0, P1, P2 and P3 addressed as PX.0-
PX.7.

• On-chip clock oscillatorclock circuits

5
• 40-pin DIP implementation.

• 32 I/O pins.
• Extensive multiplexing.
• P0 - AD0-AD7.

• P1 - exclusive port.

• P2 - A8-A15.
• P3 - control.

6
2) Resistors
Resistors are used to oppose the flow of electricity whose resistance is measured in ohms

Types of Resistors:

There are many types of resistors for making circuits starting from a small surface mount chip to
large wire wound resistors.The main aim of the resistor inside a circuit is to set the flow
ofelectrons through them. However resistors can be classified broadly into four different
typesnamely

 Carbon Composition Resistor: These are the most common type of resistors and
areextremely inexpensive. These are made of either carbon dust or paste of graphite.
They are used in electronic circuits. The resistor’s lead is manufactured from tinned
copper. The key advantage of this carbon resistor is that they are easily available in
market at a reasonable cost and these resistors are durable as well. These resistors have
a tendency to create noise owing to the transferring of current from one carbon particle
to another. These resistors are given different colored rings on its cylindrical body.

7
 Metal Film Resistor: These are made ofconductive metal oxide paste.It consist
ofmetalfilm, carbon film and metal oxide film, they are mainly made by depositing
pure metalsAcontact capmade of metal is fixed at both sides of the resistor. These metal
caps have to bein touch with helical grooves or resistive film. The lead Wires are
soldered to these metallic contact caps.

 Wire Wound Resistor: This type of resistor is made by winding a wire made of alloy
into aninsulating ceramic former in the method of spiral helix. They are designed in such
a way that they can be physically mounted into heat sinks or metal plates. The wire
wound resistor is coated with a material like baked enamel, these materials are insulating
materials. Different ratings & sizes the resistor can be obtained by changing the length &
diameter of the wire.

8
 Variable Resistor:

Variable resistors are also known as potentiometer. A variable resistor has only two wires
thatconnect instead of three. It has a very difficult task to do. Thus the variable resistor
helps us inadjusting the resistance between two pins within a circuit. It is used at the
time when theamount of resistance value is unknown in a circuit.

Some of these variable resistors are intended to directly mount on the circuit board. The
ordinary spindle diameter of variable resistor is 6mm.

 SMD Resistor:

SMD resistors are made from a technology named SMT (surface mount technology); In
this technique parts are placed directly or mounted on the circuit board (PCBs). They are
the most extensively employed element as everyday millions of gadgets are made out of
this technique. Starting from cell phones, to television to MP3 players to all high
technology equipment all make use of this resistor. Their shape is rectangle and is made

9
of ceramic substrate which is deposited by a metal oxide. They are stable and have good
acceptance. They are available in various packages.

Pre-set Resistor:

This kind of resistor is used in the circuit when there is a necessity of altering the resistance. In
simpler terms preset resistors is a small PCB mounted edition of potentiometer. They can either
be turned up or down for either increasing or decreasing the resistance. The adjustment in this
can be done with the help of a screw driver.

10
11
3) Capacitors

Capacitors are components that are used to store an electrical charge and are used in timer
circuits.

A capacitor may be used with a resistor to produce a timer. Sometimes capacitors are used to
smooth a current in a circuit as they can prevent false triggering of other components such as
relays. When power is supplied to a circuit that includes a capacitor - the capacitor charges
up.When power is turned off the capacitor discharges its electrical charge slowly.

A capacitor is composed of two conductors separated by an insulating material called a


DIELECTRIC. The dielectric can be paper, plastic film, ceramic, air or a vacuum. The plates can
be aluminum discs, aluminum foil or a thin film of metal applied to opposite sides of a solid
dielectric. The CONDUCTOR - DIELECTRIC - CONDUCTOR sandwich can be rolled into
cylinder or left flat.

12
1)Electrolytic capacitors are „polarized‟ which means they have a positive and negative
lead and must Be Positioned in a circuit the right way round (the positive lead must go to
the positive side of the Circuit).They also have a much higher capacitance than non-
electrolytic capacitors.

2) Non-electrolytic capacitors usually have a lower capacitance.

They are not polarized (do not have a positive and negative lead) and can be placed
anyway round in normally used to smooth a current in a circuit.

CAPACITANCE - means the value of a capacitor.

13
4) DAC and ADC

Digital to Analog Converter

In modern life, electronic equipment is frequently used in different fields such as


communication, transportation, entertainment, etc. Analog to Digital Converter (ADC) and
Digital to Analog Converter (DAC) are very important components in electronic equipment.

Since most real world signals are Analog, these two converting interfaces are necessary to
allow digital electronic equipment‟s to process the analog signals. Take the audio signal
processing in Figure 1 as an example, ADC converts the analog signal collected by audio
input equipment, such as a microphone, into a digital signal that can be processed by
computer. The computer may add sound effect such as echo and adjust the tempo and pitch
of the music. DAC converts the processed digital signal back into the analog signal that is
used by audio output equipment such as a speaker.

Figure 1: Audio signal processing

A DAC can be constructed by using a Summing Amplifier and a set of resistors R, 2R,
4Rand 8R as its inputs, Figure 2. The resistors are scaled to represent weights for the
differentinput bits.

14
Figure 2: A Summing Amplifier functioning as a simple DAC

The resistor with the lowest value R corresponds to the highest weighted binary input Bit 3
(MSB) [23 = 8], and 2R, 4R, 8R correspond to the binary weights of Bit 2 (2 2 = 4), Bit 1 (21 = 2),
and Bit 0 (LSB) [20 = 1] respectively. The relationship between the digital inputs (Bit 0 to Bit 3)
and the analog output VOUT is as follow:

~!QA
whereVref is the Reference Voltage of the circuit. Assuming the value of V ref as 5 V, the
Analog Output Voltages corresponding to the Digital Input Codes is shown in Table 1.

Table 1: The Analog Output Voltages corresponding to the Digital Input Codes with Vref= 5 V

15
Analog To Digital Converter
In electronics, an Analog to Digital Converter (ADC) is a device for converting an analog signal
(current, voltage etc.) to a digital code, usually binary. In the real world, most of the signals
sensed and processed by humans are analog signals. Analog-to-Digital conversion is the primary
means by which analog signal are converted into digital data that can be processed by computers
for various purposes, Figure 3.

Figure 1: Audio Signal Processing

There are many types of ADC for different applications. The most inexpensive type of ADC is a
Successive-Approximation ADC.
Figure 4 shows the transfer curve of a 4-bit ADC. Inside a Successive-Approximation ADC, a
series of digital codes, each corresponds to a fix analog level, are generated successively by an
internal counter to compare with the analog signal under conversion. The generation is stopped
when the analog level becomes just larger than the analog signal. The digital code corresponds to
the analog level is the desired digital representation of the analog signal.

16
Figure 2: Ideal Transfer Curve of a 4-bit ADC

The performance of ADCs and DACs mainly depends on their Resolution and Speed.

The Resolution of a converter is expressed in the number of Bit. For an ADC, the
Resolutionstates the number of intervals or levels which can be divided from a certain analog
input range.An n-bit ADC has the resolution of 1 / 2n. For example, the Resolution of a 16-bit
ADC is 1 /65536, since 216 = 65536. If the measuring voltage range is 10 V, then this input
range can be resolved into 10 V / 65536 = 0.153 mV precision.

The Speed of a converter is expressed by the Sampling Frequency. It is the number of


timesthat the converter samples the analog signal, its unit is Hertz (Hz). In audio signal
processing,

Sampling Frequencies of 44 kHz, 22 kHz and 11 kHz are mostly used. Using 44 kHz
Sampling Frequency means the converter is sampling the analog audio signal and doing
analog to digital conversion at 44000 times per second. The higher the Sampling
Frequency,the lower the distortion and the better the sound quality.

17
ADCs are used virtually everywhere, whenever an analog signal has to be transported, it is
processed and stored in digital form. They are always used together with different transducers to
convert physical sense and measurement such as temperature, pressure, humidity, speed,
vibration, sound, picture etc. in digital signal for further processing by microprocessor.

18
5) Operational Amplifiers

Operational Amplifier Basics

Operational amplifiers are linear devices that have all the properties required for nearly ideal DC
amplification and are therefore used extensively in signal conditioning, filtering or to perform
mathematical operations such as add, subtract, integration and differentiation.

An Operational Amplifier is basically a three-terminal device which consists of two high


impedance inputs, one called the Inverting Input, marked with a negative or “minus” sign, ( - )
and the other one called the Non-inverting Input, marked with a positive or “plus” sign ( + ).

The third terminal represents the Operational Amplifiersoutput port which can both sink and
source either a voltage or a current. In a linear operational amplifier, the output signal is
theamplification factor, known as the amplifiers gain ( A ) multiplied by the value of the
inputsignal and depending on the nature of these input and output signals, there can be four
different classifications of operational amplifier gain.

Voltage – Voltage “in” and Voltage “out”

Current – Current “in” and Current “out”

Trans conductance– Voltage “in” and Current “out”

Trans resistance– Current “in” and Voltage “out”

Since most of the circuits dealing with operational amplifiers are voltage amplifiers, we will
limit the tutorials in this section to voltage amplifiers only, (Vin and Vout).

The amplified output signal of an Operational Amplifier is the difference between the two
signals being applied to the two inputs. In other words the output signal is a differential signal
between the two inputs and the input stage of an Operational Amplifier is in fact a differential
amplifier as shown below.
Differential Amplifier

The circuit below shows a generalized form of a differential amplifier with two inputs
marked V1 andV2. The two identical transistors TR1 and TR2 are both biased at the same

19
operating point with their emitters connected together and returned to the common rail, -Vee by
way of resistor Re.

The circuit operates from a dual supply +Vcc and -Vee which ensures a constant
supply. The voltage that appears at the output, Vout of the amplifier is the difference
between the two input signals as the two base inputs are in anti-phase with each other.
So as the forward bias of transistor, TR1 is increased, the forward bias of transistor
TR2 is reduced and vice versa. Then if the two transistors are perfectly matched, the
current flowing through the common emitter resistor, Re will remain constant.
Equivalent Circuit of an Ideal Operational Amplifier

20
6) Transistors, Diode, Crystal Oscillator

Transistors

Transistors can be regarded as a type of switch, as can many electronic components. They are
used in a variety of circuits and you will find that it is rare that a circuit built in a school
Technology Department does not contain at least one transistor. They are central to electronics
and there are two main types;

NPN and PNP. Most circuits tend to use NPN. There are hundreds of transistors which work at
different
Voltages but all of them fall into these two categories.
Transistors are manufactured in different shapes but they have three leads (legs). The
BASE - which is the lead responsible for activating the transistor.

The COLLECTOR - which is the positive lead.


The EMITTER - which is the negative lead.

The diagram below shows the symbol of an NPN transistor. They are not always set out as
shown in the diagrams to the left and right, although the „tab‟ on the type shown to the left is
usually next to the „emitter‟.

21
SIMPLE USE OF A TRANSISTOR

DIAGRAM 'A' DIAGRAM 'B'


Diagram 'A' shows an NPN transistor which is often used as a type of switch. A small current or
voltage at ta larger voltage to flow through the other two leads (from the collector to the emitter).
The circuit shown in diagram B is based on an NPN transistor. When the switch is pressed a
current passes t resistor into the base of the transistor. The transistor then allows current to flow
from the +9 volts to the 0vs, comes on.

22
The transistor has to receive a voltage at its „base‟ and until this happens the lamp does not light.
The resistor is present to protect the transistor as they can be damaged easily by too high a
voltage / current. an essential component in many circuits and are sometimes used to amplify a
signal.

Diodes

Ideal Diodes

The key function of an ideal diode is to control thedirectionof current-flow.


Current passing through a diode can only go in one direction, called the forward
direction. Current trying to flow the reverse direction is blocked. They’re like the
one-way valve of electronics.

If the voltage across a diode is negative, no current can flow*, and the ideal diode
looks like an open circuit. In such a situation, the diode is said to be off or reverse
biased.

As long as the voltage across the diode isn‟t negative, it‟ll “turn on” and conduct current.
Ideally* a diode would act like a short circuit (0V across it) if it was conducting
current. When a diode is conducting current it‟sforward biased (electronics jargon
for “on”).

The current-voltage relationship of an ideal diode. Any negative voltage produces


zero current – an open circuit. As long as the voltage is non-negative the diode looks
like a short circuit.

23
Circuit Symbol

Every diode has two terminals – connections on each end of the component – and
those terminals are polarized, meaning the two terminals are distinctly different.
It‟s important not to mix the connections on a diode up. The positive end of a diode
is called the anode, and the negative end is called the cathode. Current can flow
from the anode end to the cathode, but not the other direction. If you forget which
way current flows through a diode, try to remember the mnemonic ACID: “anode
current in diode” (also anode cathode is diode).

The circuit symbol of a standard diode is a triangle butting up against a line.

The terminal entering the flat edge of the triangle represents the anode. Current
flows in the direction that the triangle/arrow is pointing, but it can‟t go the other
way.

24
Current-Voltage Relationship
The most important diode characteristic is its current-voltage (i-v) relationship.
This defines what the current running through a component is, given what voltage
is measured across it. Resistors, for example, have a simple, linear i-
vrelationship…Ohm‟s Law.The i-v curve of a diode, though, is entirely non-
linear. It looks something like this:

The current-voltage relationship of a diode. In order to exaggerate a few important


points on the plot, the scales in both the positive and negative halves are not equal.

Depending on the voltage applied across it, a diode will operate in one of three regions:
Forward bias: When the voltage across the diode ispositive the diode is “on” and current canrun
through. The voltage should be greater thanthe forward voltage (V F) in order for the current to be
anything significant.

1. Reverse bias: This is the “off” mode of the diode, where the voltage is less than
VFbutgreater than -VBR. In this mode current flow is (mostly) blocked, and the diode is
off.

A very small amount of current (on the order of nA) – called reverse saturation current –
is able to flow in reverse through the diode.

2. Breakdown: When the voltage applied across the diode is very large and negative,
lotsof current will be able to flow in the reverse direction, from cathode to anode.

25
Types of Diodes:-

1. Normal Diodes

2. Light-Emitting Diodes (LEDs)

3. Schottky Diodes

4. Zener Diodes

5. Photodiodes

The Crystal Oscillator

One of the most important features of any oscillator is its frequency stability, or in other words
its ability to provide a constant frequency output under varying load conditions. Some of the
factors that affect the frequency stability of an oscillator generally include: variations in
temperature, variations in the load as well as changes to its DC power supply voltage to name a
few.

26
Quartz Crystal Oscillator

To obtain a very high level of oscillator stability a Quartz Crystal is generally used as
thefrequency determining device to produce another types of oscillator circuit known
generally asa Quartz Crystal Oscillator, (XO).

When a voltage source is applied to a small thin piece of quartz crystal, it begins to change shape
producing a characteristic known as the Piezo-electric effect. This Piezo-electric Effect is the
property of a crystal by which an electrical charge produces a mechanical force by
changing the shape of the crystal and vice versa, a mechanical force applied to the crystal
produces an electrical charge.

Then, piezo-electric devices can be classed as Transducersas they convert energy of one kind
into energy of another (electrical to mechanical or mechanical to electrical).

The quartz crystal used in a Quartz Crystal Oscillator is a very small, thin piece or wafer of cut
quartz with the two parallel surfaces metallised to make the required electrical connections. The
physical size and thickness of a piece of quartz crystal is tightly controlled since it affects the
final or fundamental frequency of oscillations. The fundamental frequency is called the crystals
“characteristic frequency”.

The crystals characteristic or resonant frequency is inversely proportional to its physical


thickness between the two metallised surfaces. A mechanically vibrating crystal can
berepresented by an equivalent electrical circuit consisting of low resistance, large
inductance and small capacitance as shown below.

27
Quartz Crystal Equivalent Model

The equivalent circuit for the quartz crystal shows an RLC series circuit, which represents the
mechanical vibrations of the crystal, in parallel with a capacitance, Cp which represents the
electrical connections to the crystal. Quartz crystal oscillators operate at “parallel resonance”,
and the equivalent impedance of the crystal has a series resonance where Cs resonates with
inductance, Land a parallel resonance where L resonates with the series combination of Cs and
Cp as shown.

28
7) Types of Relays
Relays
Relays are switches that open and close circuits electromechanically or electronically. Relays
control one electrical circuit by opening and closing contacts in another circuit. As relay
diagrams show, when a relay contact is normally open (NO), there is an open contact when the
relay is not energized. When a relay contact is Normally Closed (NC), there is a closed contact
when the relay is not energized. In either case, applying electrical current to the contacts will
change their state.

Relays are generally used to switch smaller currents in a control circuit and do not usually
control power consuming devices except for small motors and Solenoids that draw low amps.
Nonetheless, relays can "control" larger voltages and amperes by having an amplifying effect
because a small voltage applied to a relays coil can result in a large voltage being switched by
the contacts.

Protective relays can prevent equipment damage by detecting electrical abnormalities, including
overcurrent, undercurrent, overloads and reverse currents. In addition, relays are also widely
used to switch starting coils, heating elements, pilot lights and audible alarms.

Electromechanical Relays vs Solid State Relays.

Relays are either electromechanical relays or solid-state relays. In


electromechanicalrelays (EMR), contacts are opened or closed by a magnetic force. With
solid-state relays (SSR), there are no contacts and switching is totally electronic. The
decision to use electromechanical or solid state relays depends on an application's
electrical requirements, cost constraints and life expectancy. Although solid-state relays
have become very popular, electromechanical relays remain common. Many of the
functions performed by heavy-duty equipment need the switching capabilities of
electromechanical relays. Solid State relays switch the current using non-moving electronic
devices such as silicon controlled rectifiers.

29
Electromechanical Relays.
Basic parts and functions of electromechanical relays include:
1. Frame: Heavy-duty frame that contains and supports the parts of the relay.

2. Coil: Wire is wound around a metal core. The coil of wire causes an
electromagneticfield.

3. Armature: A relays moving part. The armature opens and closes the contacts.
Anattached spring returns the armature to its original position.

4. Contacts: The conducting part of the switch that makes (closes) or breaks (opens)
acircuit.

Relays involve two circuits: the energizing circuit and the contact circuit. The coil is on the
energizing side; and the relays contacts are on the contact side. When a relays coil is energized,
current flow through the coil creates a magnetic field. Whether in a DC unit where the polarity is
fixed, or in an AC unit where the polarity changes 120 times per second, the basic function
remains the same: the magnetic coil attracts a ferrous plate, which is part of the armature. One
end of the armature is attached to the metal frame, which is formed so that the armature can
pivot, while the other end opens and closes the contacts. Contacts come in a number of different
configurations, depending on the number of Breaks, poles and Throws that make up the relay.

30
For instance, relays might be described as Single-Pole, Single-Throw (SPST), or Double-Pole,
Single-Throw (DPST). These terms will give an instant indication of the design and function of
different types of relays.
1) Break -This is the number of separate places or contacts that a switch uses to open
orclose a single electrical circuit. All contacts are either single break or double break. A
single break (SB) contact breaks an electrical circuit in one place, while a double break
(DB) contact breaks it in two places. Single break contacts are normally used when
switching lower power devices such as indicating lights. Double break contacts are used
when switch in high-power devices such as solenoids.

2) Pole -This is the number of completely isolated circuits that relays can pass through
aswitch. A single-pole contact (SP) can carry current through only one circuit at a time.
A double-pole contact (DP) can carry current through two isolated circuits
simultaneously. The maximum number of poles is 12, depending upon a relays design.

3) Throw -This is the number of closed contact positions per pole that are available on
aswitch. A switch with a single throw contact can control only one circuit, while a
double-throw contact can control two.

Types of Relays: Electromechanical.


1. General Purpose Relays are electromechanical switches, usually operated by
amagnetic coil. General purpose relays operate with AC or DC current, at common
voltages such as 12V, 24V, 48V, 120V and 230V, and they can control currents ranging
from 2A-30A. These relays are economical, easy to replace and allow a wide range of
switch configuration.

2. Machine Control Relays are also operated by a magnetic coil. They are heavy-
dutyrelays used to control starters and other industrial components. Although they are
more expensive than general purpose relays, they are generally more durable. The biggest
advantage of machine control relays over general purpose relays is the expandable
functionality of Machine Control Relays by the adding of accessories. A wide selection
of accessories is available for machine control relays, including additional poles,
convertible contacts, transient suppression of electrical noise, latching control and timing
attachments.

3. Reed Relays are a small, compact, fast operating switch design with one contact, whichis
NO. Reed Relays are hermetically sealed in a glass envelope, which makes the contacts
unaffected by contaminants, fumes or humidity, allows reliable switching, and gives
contacts a higher life expectancy. The ends of the contact, which are often plated with
gold or another low resistance material to increase conductivity, are drawn together and
closed by a magnet. Reed relays are capable of switching industrial components such as
solenoids, contactors and starter motors. Reed relays consists of two reeds. When a
magnetic force is applied, such as an electromagnet or coil, it sets up a magnetic field in
which the end of the reeds assume opposite polarity. When the magnetic field is strong
enough, the attracting force of the opposite poles overcomes the stiffness of the reeds and

31
draws them together. When the magnetic force is removed, the reeds spring back to their
original, open position. These relays work very quickly because of the short distance
between the reeds.

Solid State Relays.

Solid state relays consist of an input circuit, a control circuit and an output circuit. The Input
Circuit is the portion of a relays frame to which the control component is connected. The input
circuit performs the same function as the coil of electromechanical relays. The circuit is activated
when a voltage higher than the relays specified Pickup Voltage is applied to the relays input. The
input circuit is deactivated when the voltage applied is less than the specified minimum Dropout
voltage of the relay. The voltage range of 3 VDC to 32 VDC, commonly used with most solid-
state relays, makes it useful for most electronic circuits. The Control Circuit is the part of the
relay that determines when the output component is energized or de-energized. The control
circuit functions as the coupling between the input and output circuits. In electromechanical
relays, the coil accomplishes this function. A relays Output Circuit is the portion of the relay that
switches on the load and performs the same function as the mechanical contacts of
electromechanical relays. Solid-state relays, however, normally have only one output contact.

32
Types of Relays: Solid State.
1. Zero-Switching Relays - relays turns ON the load when the control
(minimumoperating) voltage is applied and the voltage of the load is close to zero. Zero-
Switching relays turn OFF the load when the control voltage is removed and the current
in the load is close to zero. Zero-Switching relays are the most widely used.

2. Instant ON Relays - turns ON the load immediately when the pickup voltage is
present.Instant ON Relays allow the load to be turned ON at any point in it's up and
down wave.

3. Peak Switching Relays - turns ON the load when the control voltage is present, and
thevoltage of the load is at its peak. Peak Switching relays turn OFF when the
controlvoltage is removed and the currentin the load is close to zero.

4. Analog Switching Relays - has an infinite number of possible output voltages within
therelays rated range. Analog switching relays have a built in synchronizing circuit that
controls the amount of output voltage as a function of the input voltage. This allows a
Ramp-Up function of time to be on the load. Analog Switching relays turn OFF when the
control voltage is removed and current in the load is near zero.

33
8) Sensors
A sensor is a device that detects events or changes in quantities and provides a corresponding
output, generally as an electrical or optical signal; for example, a thermocouple converts
temperature to an output voltage. But a mercury-in-glass thermometer is also a sensor; it
converts the measured temperature into expansion and contraction of a liquid which can be read
on a calibrated glass tube.

Sensors are used in everyday objects such as touch-sensitive elevator buttons (tactile sensor) and
lamps which dim or brighten by touching the base, besides innumerable applications of which
most people are never aware. With advances in micro machinery and easy-to use microcontroller
platforms, the uses of sensors have expanded beyond the more traditional fields of temperature,
pressure or flow measurement,[1]for example into MARG sensors. Moreover, analog sensors
such as potentiometers and force-sensing resistors are still widely used. Applications include
manufacturing and machinery, airplanes and aerospace, cars, medicine and robotics.

A sensor's sensitivity indicates how much the sensor's output changes when the input quantity
being measured changes. For instance, if the mercury in a thermometer moves 1 cm when the
temperature changes by 1 °C, the sensitivity is 1 cm/°C (it is basically the slope Dy/Dx assuming
a linear characteristic). Some sensors can also have an impact on what they measure; for
instance, a room temperature thermometer inserted into a hot cup of liquid cools the liquid while
the liquid heats the thermometer. Sensors need to be designed to have a small effect on what is
measured; making the sensor smaller often improves this and may introduce other advantages.

Technological progress allows more and more sensors to be manufactured on a


microscopicscale as micro sensors using MEMS technology. In most cases, a micro sensor
reaches a significantly higher speed and sensitivity compared with macroscopic approaches

34
9) Actuators

● Actuator is a form of transducer device (mechanical or electrical) which converts signals


to corresponding physical action. Actuator acts as an output device.
● It is operated by a source of energy, typically electric current, hydraulic fluid pressure, or
pneumatic pressure, and converts that energy into motion. An actuator is the mechanism
by which a control system acts upon an environment.
● The control system can be simple (a fixed mechanical or electronic system), software-
based (e.g. a printer driver, robot control system), a human, or any other input.

35
10)Types of Connectors

1. 8P8C connector

8P8C is short for "eight positions, eight conductors", and so an 8P8C modular connector
(plugor jack) is a modular connector with eight positions, all containing conductors. The
connector is probably most famous for its use in Ethernet and widely used on CAT5cables.

The 8P8C modular plugs and jacks look very similar to the plugs and jacks used for FCC's
registered jackRJ45 variants, although the specified RJ45 socket is not compatible with 8P8C
modular plug connectors. It neither uses all eight conductors (but only two of them forwires plus
two for connecting a programming resistor) nor does it fit into 8P8C because the true RJ45 is
"keyed".

2. D-subminiature connectors

36
A male DE-9 plug
The D-subminiature electrical connector is commonly used for the RS-232 serial porton modems
and IBM compatible computers. The D-subminiature connector is used in many different
applications, for computers, telecommunications, and test and measurement instruments. A few
examples are monitors (MGA, CGA, EGA), the Commodore 64, MSX, Apple II, Amiga, and
Atari joysticks and mice, and game consoles such as Atariand Sega. Another variants of D-
subminiature are the PositronicD-subminiature connector which have PosiBand closed entry
contact option, solid machined contacts, thermocouple contact options, crimp and PCB mount
and the Positronic Combo D-subminiature which have Large Surface Area (LSA) contact system
that is for low contact resistance and saves energy, and sequential mating options.

3. USB connectors

A male USB series A plug

The Universal Serial Bus is a serial bus standard to interface devices, founded in 1996. It is
currently widely used among PCs,Apple Macintosh and many other devices. There are several
types of USB connectors, and some have been added as the specification has progressed. The
most commonly used is the (male) series "A" plug on peripherals,when the cable is fixed to the
peripheral. If there is no cable fixed to the peripheral, the peripheral always needs to have a USB
"B" socket. In this case a USB "A" plug to a USB "B" plug cable would be needed. USB "A"
sockets are always used on the host PC and the USB "B" sockets on the peripherals. It is a 4-pin
connector, surrounded by a shield. There are several other connectors in use, the mini-A, mini- B
and mini-AB plug and socket (added in the On-The-Go Supplement to the USB 2.0
Specification).

37
Practical No.2

Aim: Write a program to blink an LED

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

38
Step 3: Go to File tab  Click on New  Save as .c extension

Step 4: Write a program  Save it.

Algorithm:

1) Declare header file for 51 family


2) Declare two user defined variable x, y for operating I/O pins logic
3) Declare variable i for delay
4) We select port P1 as O/P
5) Take infinite loop as while (1) for glowing LED
6) Declare x=0x01 hex value i.e 00000001 in binary
7) Take for-loop for operating LED one-by-one
8) Declare P1=x
9) take for-loop for delay the time
10) x=x<<1 for shifting value to left side for glowing other LED’s

39
Program:

#include<reg51.h>

void main()

unsigned char x,y;

unsigned int i;

P1=0x00;

while(1)

x=0x01;

for(y=0;y<8;y++)

P1=x;

for(i=0;i<60000;i++);

x=x<<1;

40
Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .c file  Click on ADD and Close it.

41
Step 6: Go to project tab  Click on Build.

Step 7: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

42
Step 8: Design the circuit diagram

43
Step 8: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

Output:

44
Conclusion:

Hence, we successfully blink an LED’s using Atmel 89C51 controller.

45
Practical No.3

Aim: Write a program to serial data interface.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

46
Step 3: Go to File tab  Click on New  Save as .c extension

Step 4: Write a program  Save it.

Algorithm:

1) Declare header file for 51 family


2) Declare SCON Register value as 0X50 for starting of a serial communication
3) Set the timer by TMOD=0X20
4) Set baud rate by TH1= -3
5) Start your timer by TR1= 1
6) Need to declare SBUF register for transferring character to the peripheral device
7) Wait until transmission is over by declaring while(TI == 0) i.e check the interrupt register
8) Set TI=0 for next character transmission

47
Program:

#include<reg51.h>

#include<stdio.h>

void main()

SCON=0x50;

TMOD=0x20;

TH1=-3;

TR1=1;

SBUF='a';

while(TI==0);

TI=0;

Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .c file  Click on ADD and Close it.

48
Step 6: Go to project tab  Click on Build.

49
Step 7: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

50
Step 8: Design the circuit diagram

Step 8: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

51
Output:

Conclusion:

Hence, we successfully perform serial communication using Atmel 89C51 controller and
peripheral device i.e. virtual monitor.

52
Practical No.4

Aim: Write a program to block transfer of data.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

53
Step 3: Go to File tab  Click on New  Save as .asm extension

Step 4: Write a program  Save it.

Program:

ORG 0000H

MOV R0,#20H

MOV R1,#30H

MOV R2,#05H

UP:MOV A,@R0

XCH A,@R1

MOV @R0,A

INC R0

INC R1

DJNZ R2,UP

RET

54
Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .asm file  Click on ADD and Close it.

55
Step 6: Go to project tab  Click on Build.

Step 7: To run project  Go to Debug tab  Start Debugging  Go to View tab  Open
memory window for entering bits on memory

Step 8: Run the program by “step into” for transfer bits one block to another

56
Output:

Conclusion:

Hence, we successfully perform block transfer of data using Atmel 89C51 controller.

57
Practical No.5

Aim: Write a program for the keypad and LCD interface.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

58
Step 3: Go to File tab  Click on New  Save as .c extension

Step 4: Write a program  Save it.

Program:

#include<reg51.h>

sbit r1 =P1^0 ;

sbit r2 =P1^1 ;

sbit r3 =P1^2 ;

sbit r4 =P1^3 ;

sbit c1 =P1^4 ;

sbit c2 =P1^5 ;

sbit c3 =P1^6 ;

//4X3 keypad connection

sbit rs =P3^0 ;

sbit rw =P3^1 ;

sbit en =P3^2 ;

59
sfr lcd=0xa0 ; //address of port 2

void lcdcmd(unsigned char);

void lcddat(unsigned char);

void delay();

void delay1();

void main()

P2=0x00;

lcdcmd(0x38);// 5*7 matrix

delay();

lcdcmd(0x01);//clear display

delay();

lcdcmd(0x06);//cursor blinking

delay();

lcdcmd(0x0c);//display on

delay();

lcdcmd(0x81);

delay();

r1=1;r2=1;r3=1;r4=1;

while(1)

r1=0;r4=1;

if(c1==0)

60
lcddat('1');

delay();

delay1();

if(c2==0)

lcddat('2');

delay();

delay1();

if(c3==0)

lcddat('3');

delay();

delay1();

r1=1;r2=0;

if(c1==0)

lcddat('4');

delay();

delay1();

if(c2==0)

61
lcddat('5');

delay();

delay1();

if(c3==0)

lcddat('6');

delay();

delay1();

r2=1;r3=0;

if(c1==0)

lcddat('7');

delay();

delay1();

if(c2==0)

lcddat('8');

delay();

delay1();

if(c3==0)

62
lcddat('9');

delay();

delay1();

//row3 scanning complete

r4=0;r3=1;

if(c1==0)

lcddat('*');

delay();

delay1();

if(c2==0)

lcddat('0');

delay();

delay1();

if(c3==0)

lcddat('#');

delay();

delay1();

63
r4=1;

void lcdcmd(unsigned char val)

P2=val;

rs=0;

rw=0;

en=1;

delay();

en=0;

void lcddat(unsigned char dat)

P2=dat;

rs=1;

rw=0;

en=1;

delay();

delay1();

en=0;

64
void delay()

unsigned int i;

for(i=0;i<10000;i++);

void delay1()

unsigned int j,k;

for(j=0;j<200;j++)

for(k=0;k<200;k++);

Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .c file  Click on ADD and Close it.

65
Step 6: Go to project tab  Click on Build.

66
Step 7: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

67
Step 8: Design the circuit diagram

Step 9: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

68
Output:

Conclusion:

Hence, we successfully perform keypad and LCD interface Atmel 89C51 controller.

69
Practical No.6

Aim: Write a program to implement mouse driver program using MSDOS interrupt.

Program:

#include<stdio.h>

#include<conio.h>

#include<dos.h>

union REGS in, out;

#define MOUSE_INTERRUPT 0x33

int detect_mouse(void)

in.x.ax = 0;

int86(MOUSE_INTERRUPT, &in, &out);

return out.x.ax;

int show_mouse(void)

in.x.ax = 1;

int86(MOUSE_INTERRUPT, &in, &out);

return 1;

void get_mouse_status(int *xpos, int *ypos, int *click)

70
{

in.x.ax = 3;

int86(MOUSE_INTERRUPT, &in, &out);

*click = out.x.bx;

*xpos = out.x.cx;

*ypos = out.x.dx;

int hide_mouse(void)

in.x.ax = 2;

int86(MOUSE_INTERRUPT, &in, &out);

return 1;

int main(int argc, char *argv[])

int status;

int xpos, ypos, click;

int xpos_old, ypos_old, click_old;

clrscr();

printf("\n\DOS Text Mode Mouse demo using INT 0x33");

status = detect_mouse();

if (status == 0 ) {

printf("Mouse support not available.\n");

return status;

71
}

printf("Mouse support available. Press any key to continue.\n");

getch();

clrscr();

show_mouse();

do {

get_mouse_status(&xpos, &ypos, &click);

if (xpos != xpos_old ||

ypos != ypos_old ||

click != click_old

xpos_old = xpos;

ypos_old = ypos;

click_old = click;

clrscr();

gotoxy(0, 0);

printf("Mouse position: X=%d, Y=%d, Z=%d", xpos, ypos, click);

show_mouse();

} while (!kbhit());

hide_mouse();

getch();

return 0;

72
Output:

Conclusion:

Hence, we successfully implement mouse driver program using MSDOS interrupt.

73
Practical No.7

Aim: Write a program to implement ADC0808 with 8051 microcontroller.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

74
Step 3: Go to File tab  Click on New  Save as Includes.h extension.  Write a program 
Save it.

Go to File tab  Click on New  Save as ADC0808.h extension.  Write a program 


Save it.

#ifndef __ADC0808_H

#define __ADC0808_H

// Define ADC Channels

#define AN0 0

#define AN1 1

#define AN2 2

75
#define AN3 3

#define AN4 4

#define AN5 5

#define AN6 6

#define AN7 7

// Define Pins

sbit Add_A = P2^0; // Address Pin A

sbit Add_B = P2^1; // Address Pin B

sbit Add_C = P2^2; // Address Pin C

sbit ALE = P2^3; // Address Latch Enable

sbit EOC = P2^4; // End Of Conversion

sbit OE = P2^5; // Output Enable

sbit START = P2^6; // Start Conversion

sbit CLK = P2^7; // Clock for AD0808

// Define Data Bus

#define Data_Bus P0

#define HalfCycleDelay 10 // usecs

// Function Declarations

void InitADC(void);

unsigned char ReadADC(unsigned char);

#endif

76
Go to File tab  Click on New  Save as LCD.h extension.  Write a program  Save it.

#ifndef __LCD_H

#define __LCD_H

//Pin description

/*

P1.4 to P1.7 is data bus

P1.1 is RS

P1.0 is E

*/

//********************

// Defines Pins

sbit RS = P1^1;

sbit E = P1^0;

// Constants

#define E_Delay 250

// Function Declarations

void delay_sec(unsigned int);

void __delay_us(unsigned int);

void InitLCD(void);

void WriteCommandToLCD(int);

void WriteDataToLCD(char);

void WriteStringToLCD(const char*);

void ClearLCDScreen(void);

#endif

77
Step 4: Go to File tab  Click on New  Save as Main.c extension.

Program:

#include "Includes.h"

// Main function

void main()

unsigned char ADC_Value = 0; // To capture ADC value

unsigned char Digit[3] = { 0,0,0 }; // To make digits to display on LCD

InitADC(); // Initialize ADC

InitLCD(); // Initialize LCD display

WriteStringToLCD("Starting..."); // Show Welcome Message

delay_sec(1); // 1 Sec delay

ClearLCDScreen(); // Clear LCD

while(1)

ADC_Value = ReadADC(AN1); // Read ADC value from Channel 1

78
Digit[2] = (unsigned char)( ADC_Value/100);
// Find out first digit

Digit[1] = (unsigned char)( ADC_Value/10) - Digit[2]*10; // Find out second


digit

Digit[0] = ADC_Value - Digit[2]*100 - Digit[1]*10; // Find


out third digit

ClearLCDScreen();
// Clear LCD

WriteStringToLCD("ADC value = ");


// Display string

WriteDataToLCD(Digit[2]+0x30);
// Display first digit

WriteDataToLCD(Digit[1]+0x30);
// Display second digit

WriteDataToLCD(Digit[0]+0x30);
// Display third digit

delay_sec(1);
// Delay of one second

79
Step 5: Go to File tab  Click on New  Save as ADC0808.c extension.

Program:

#include "Includes.h"

void InitADC(void)

Add_A = 0; // Make output

Add_B = 0; // Make output

Add_C = 0; // Make output

ALE = 0; // Make output

EOC = 1; // Make input

OE = 0; // Make output

START = 0; // Make output

CLK = 0; // Make output

Data_Bus = 0xFF; // Make Inputs

80
unsigned char ReadADC(unsigned char Channel)

unsigned int i = 0;

unsigned int ADC_value = 0;

// Select Channel

switch(Channel)

case AN0: Add_C = 0; Add_B = 0; Add_A = 0; break;

case AN1: Add_C = 0; Add_B = 0; Add_A = 1; break;

case AN2: Add_C = 0; Add_B = 1; Add_A = 0; break;

case AN3: Add_C = 0; Add_B = 1; Add_A = 1; break;

case AN4: Add_C = 1; Add_B = 0; Add_A = 0; break;

case AN5: Add_C = 1; Add_B = 0; Add_A = 1; break;

case AN6: Add_C = 1; Add_B = 1; Add_A = 0; break;

case AN7: Add_C = 1; Add_B = 1; Add_A = 1; break;

__delay_us(HalfCycleDelay); // 250kHz Frequency

ALE = 1; // Enable Address Latch

CLK = 1; // Make CLK High

__delay_us(HalfCycleDelay); // 250kHz Frequency

CLK = 0; // Make CLK Low

START = 1; // Start ADC Conversion

__delay_us(HalfCycleDelay); // 250kHz Frequency

CLK = 1; // Make CLK High

ALE = 0; // Disable Address Latch

81
__delay_us(HalfCycleDelay); // 250kHz Frequency

CLK = 0; // Make CLK Low

START = 0; // Complete the start pulse

for(i=0;i<2000;i++)

CLK = !CLK; // Toggle Clock

__delay_us(HalfCycleDelay);// 250kHz Frequency

if(!EOC) // Wait for EOC to be low

break;

for(i=0;i<2000;i++)

CLK = !CLK; // Toggle Clock

__delay_us(HalfCycleDelay);// 250kHz Frequency

if(EOC) // Wait for EOC to be High

break;

CLK = 0; // Make CLK Low

OE = 1; // Enable Output

__delay_us(HalfCycleDelay); // 250kHz Frequency

CLK = 1; // Make CLK High

__delay_us(HalfCycleDelay); // 250kHz Frequency

CLK = 0; // Make CLK Low

__delay_us(HalfCycleDelay); // 250kHz Frequency

82
CLK = 1; // Make CLK High

ADC_value = Data_Bus; // Read value

__delay_us(HalfCycleDelay); // 250kHz Frequency

OE = 0; // Disable Output

CLK = 0; // Make CLK Low

__delay_us(HalfCycleDelay); // 250kHz Frequency

return ADC_value; // Return ADC value

Step 6: Go to File tab  Click on New  Save as LCD.c extension.

Program:

#include "Includes.h"

// Function Purpose: Produce approximate delay in Secs.

void delay_sec(unsigned int d)

83
{

unsigned int i;

for(i=0;i<(d*20);i++)

__delay_us(50000);

// Function Purpose: Produce approximate delay in given uSecs.

void __delay_us(unsigned int d)

unsigned int i, limit;

limit = d/15;

for(i=0;i<limit;i++);

void ToggleEpinOfLCD(void)

E = 1; // Give a pulse on E pin

__delay_us(E_Delay); // so that LCD can latch the

E = 0; // data from data bus

__delay_us(E_Delay);

void WriteDataToLCD(char t)

RS = 1; // This is data

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= (t&0xF0); // Write Upper nibble of data

84
ToggleEpinOfLCD(); // Toggle E pin to send data

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= ((t<<4)&0xF0);// Write Lower nibble of data

ToggleEpinOfLCD(); // Toggle E pin to send data

void WriteCommandToLCD(int z)

RS = 0; // This is command

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= (z&0xF0); // Write Upper nibble of data

ToggleEpinOfLCD(); // Toggle E pin to send data

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= ((z<<4)&0xF0);// Write Lower nibble of data

ToggleEpinOfLCD(); // Toggle E pin to send data

void InitLCD(void)

RS = 0; // Make pin zero

E = 0; // Make Pin zero

///////////// Reset process from datasheet /////////

__delay_us(15000);

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= 0x30; // Write 0x3

ToggleEpinOfLCD(); // Toggle E pin to send data

__delay_us(4500);

85
P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= 0x30; // Write 0x3

ToggleEpinOfLCD(); // Toggle E pin to send data

__delay_us(300);

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= 0x30; // Write 0x3

ToggleEpinOfLCD(); // Toggle E pin to send data

__delay_us(650);

P1 &= 0x0F; // Make P1.4 to P1.7 zero

P1 |= 0x20; // Write 0x2

ToggleEpinOfLCD(); // Toggle E pin to send data

__delay_us(650);

/////////////////////////////////////////////////////

WriteCommandToLCD(0x28); //function set

WriteCommandToLCD(0x0c); //display on,cursor off,blink off

WriteCommandToLCD(0x01); //clear display

WriteCommandToLCD(0x06); //entry mode, set increment

void WriteStringToLCD(const char *s)

while(*s)

WriteDataToLCD(*s++); // print first character on LCD

void ClearLCDScreen(void) // Clear the Screen and return cursor to zero position

86
WriteCommandToLCD(0x01); // Clear the screen

__delay_us(2000); // Delay for cursor to return at zero position

Step 7: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your all .c file  Click on ADD and Close it.

87
Step 8: Go to project tab  Click on Build.

Step 9: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

88
Step 10: Design the circuit diagram

Step 11: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

89
Output:

90
Conclusion:

Hence, we successfully perform analog to digital conversion using ADC0808 with 8051
microcontroller.

91
Practical No.8

Aim: Write a program to simulate elevator functions.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

92
Step 3: Go to File tab  Click on New  Save as .c extension

Step 4: Write a program  Save it.

Program:

#include <REG51.H>

#include <stdio.h>

int floor,tur,speed;

tur=10; //number of rotations of motor for each floor

speed=10; //motor rotation speed 0 max 32000 min

delay(c)

int i,j;

if(c==0)

for(i=0;i<500;i++)

for(j=0;j<speed;j++)

93
{

return;

// the elevator goes up

up(b)

int i,j;

for (i=1;i<=b;i++)

for (j=0;j<=10;j++)

P3=1;

delay(0);

P3=2;

delay(0);

P3=4;

delay(0);

P3=8;

delay(0);

P2=floor+i;

94
}

floor=floor+b;

return;

// the elevator goes down

down(b)

int i,j;

for (i=1;i<=b;i++)

for (j=0;j<=tur;j++)

P3=8;

delay(0);

P3=4;

delay(0);

P3=2;

delay(0);

P3=1;

delay(0);

P2=floor-i;

floor=floor-b;

return;

95
}

control(a)

int diff;

if(a>floor)

diff=a-floor;

up(diff);

if(a<floor)

diff=floor-a;

down(diff);

return;

main()

int floor1;

floor=0;

P2=floor;

while(1)

if(P0==1)

96
floor1=1;

control(1);

if(P0==2)

floor1=2;

control(2);

if(P0==4)

floor1=3;

control(3);

if(P0==8)

floor1=4;

control(4);

if(P0==16)

floor1=5;

control(5);

97
Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .c file  Click on ADD and Close it.

98
Step 6: Go to project tab  Click on Build.

Step 7: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

99
Step 8: Design the circuit diagram

Step 9: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

100
Output:

101
Conclusion:

Hence, we successfully perform simulating elevator functions using 8051 microconyroller.

102
Practical No.9

Aim: Write a program to interface stepper motor controller.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

103
Step 3: Go to File tab  Click on New  Save as .c extension

Step 4: Write a program  Save it.

Program:

#include<reg51.h>

sbit l1 =P1^0 ;

sbit l2 =P1^1 ;

sbit l3 =P1^2 ;

sbit l4 =P1^3 ;

void main()

unsigned int i;

l1=l2=l3=l4=0;

while(1)

l1=1;

l2=l3=l4=0;

104
for(i=0;i<60000;i++);

l2=1;

l1=l3=l4=0;

for(i=0;i<60000;i++);

l3=1;

l2=l1=l4=0;

for(i=0;i<60000;i++);

l4=1;

l2=l3=l1=0;

for(i=0;i<60000;i++);

Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .c file  Click on ADD and Close it.

105
Step 6: Go to project tab  Click on Build.

Step 7: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

106
Step 8: Design the circuit diagram

107
Step 9: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

Output:

Conclusion:

Hence, we successfully perform interface stepper motor with 8051 controller.

108
Practical No.10

Aim: Write a program to simulate traffic signals.

Step 1: Open Keil Software  Click on Project  New Project  Give the name and save it.

Step 2: Select Controller for your project. (For this project we select from Atmel)

109
Step 3: Go to File tab  Click on New  Save as .c extension

Step 4: Write a program  Save it.

Program:

#include<reg51.h>

char arr[10]={0xbf,0x86,0xdb,0xcf,0xe6,0xed,0xfd,0x87,0xff,0xef};

void delay()

int i;

for(i=0;i<500;i++);

void delay2()

int i;

for(i=0;i<30000;i++);

void main()

110
{

int a,b,c;

task1:

P1=0xe1;

delay2();

if(a==2&&b==9)

goto task2;

for(a=2;a>=0;a--)

for(b=9;b>=0;b--)

for(c=0;c<50;c++)

P2=0xfd;

P3=arr[b];

delay();

P2=0xfe;

P3=arr[a];

delay();

}}}

task2:

P1=0xd2;

111
delay2();

if(a==2&&b==9)

goto task3;

for(a=2;a>=0;a--)

for(b=9;b>=0;b--)

for(c=0;c<50;c++)

P2=0xfd;

P3=arr[b];

delay();

P2=0xfe;

P3=arr[a];

delay();

}}}

task3:

P1=0xb4;

delay2();

if(a==2&&b==9)

goto task4;

for(a=2;a>=0;a--)

112
for(b=9;b>=0;b--)

for(c=0;c<50;c++)

P2=0xfd;

P3=arr[b];

delay();

P2=0xfe;

P3=arr[a];

delay();

}}}

task4:

P1=0x78;

delay2();

if(a==2&&b==9)

goto task1;

for(a=2;a>=0;a--)

for(b=9;b>=0;b--)

for(c=0;c<50;c++)

P2=0xfd;

P3=arr[b];

113
delay();

P2=0xfe;

P3=arr[a];

delay();

}}}

Step 5: For compilation, expand Target 1  Right Click on Source Group 1  Click on Add
Files to Group “Source Group 1”  Select your .c file  Click on ADD and Close it.

114
Step 6: Go to project tab  Click on Build.

Step 7: For H/W simulation we need to create hex file. For that Click on Target 1 Option for
Target 1  Give Crystal Oscillator frequency 11.0592 and click on checkbox  Go to output
tab  Click on Create HEX File  Click on ok.  Again Build the project.

115
Step 8: Design the circuit diagram

Step 9: Upload the program i.e hex file into the controller  Click on ok  Click on Play
Button at the bottom

116
Output:

Conclusion:

Hence, we successfully perform simulating traffic signals with 8051 microcontroller.

117

You might also like