Professional Documents
Culture Documents
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.
1) 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.
3
Intel 8051
Timers 2
I/O pins 32
Serial port 1
Interrupt sources 6
The 8051 is the original member of the MCS-51 family, and is the core for all MCS-51 devices.
4
• 64K program memory address space
• Thirty two I/O pins arranged as four 8-bit ports P0, P1, P2 and P3 addressed as PX.0-
PX.7.
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.
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.
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.
13
4) DAC and ADC
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.
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.
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.
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 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.
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.
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 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
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
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”).
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 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:
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
3. Schottky Diodes
4. Zener Diodes
5. Photodiodes
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”.
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.
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.
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 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.
34
9) Actuators
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
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
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
Algorithm:
39
Program:
#include<reg51.h>
void main()
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:
45
Practical No.3
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
Algorithm:
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
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
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
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
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 ;
sbit rs =P3^0 ;
sbit rw =P3^1 ;
sbit en =P3^2 ;
59
sfr lcd=0xa0 ; //address of port 2
void delay();
void delay1();
void main()
P2=0x00;
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();
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;
P2=val;
rs=0;
rw=0;
en=1;
delay();
en=0;
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()
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>
int detect_mouse(void)
in.x.ax = 0;
return out.x.ax;
int show_mouse(void)
in.x.ax = 1;
return 1;
70
{
in.x.ax = 3;
*click = out.x.bx;
*xpos = out.x.cx;
*ypos = out.x.dx;
int hide_mouse(void)
in.x.ax = 2;
return 1;
int status;
clrscr();
status = detect_mouse();
if (status == 0 ) {
return status;
71
}
getch();
clrscr();
show_mouse();
do {
if (xpos != xpos_old ||
ypos != ypos_old ||
click != click_old
xpos_old = xpos;
ypos_old = ypos;
click_old = click;
clrscr();
gotoxy(0, 0);
show_mouse();
} while (!kbhit());
hide_mouse();
getch();
return 0;
72
Output:
Conclusion:
73
Practical No.7
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.
#ifndef __ADC0808_H
#define __ADC0808_H
#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
#define Data_Bus P0
// Function Declarations
void InitADC(void);
#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.1 is RS
P1.0 is E
*/
//********************
// Defines Pins
sbit RS = P1^1;
sbit E = P1^0;
// Constants
// Function Declarations
void InitLCD(void);
void WriteCommandToLCD(int);
void WriteDataToLCD(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()
while(1)
78
Digit[2] = (unsigned char)( ADC_Value/100);
// Find out first digit
ClearLCDScreen();
// Clear LCD
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)
OE = 0; // Make output
80
unsigned char ReadADC(unsigned char Channel)
unsigned int i = 0;
// Select Channel
switch(Channel)
81
__delay_us(HalfCycleDelay); // 250kHz Frequency
for(i=0;i<2000;i++)
break;
for(i=0;i<2000;i++)
break;
OE = 1; // Enable Output
82
CLK = 1; // Make CLK High
OE = 0; // Disable Output
Program:
#include "Includes.h"
83
{
unsigned int i;
for(i=0;i<(d*20);i++)
__delay_us(50000);
limit = d/15;
for(i=0;i<limit;i++);
void ToggleEpinOfLCD(void)
__delay_us(E_Delay);
void WriteDataToLCD(char t)
RS = 1; // This is data
84
ToggleEpinOfLCD(); // Toggle E pin to send data
void WriteCommandToLCD(int z)
RS = 0; // This is command
void InitLCD(void)
__delay_us(15000);
__delay_us(4500);
85
P1 &= 0x0F; // Make P1.4 to P1.7 zero
__delay_us(300);
__delay_us(650);
__delay_us(650);
/////////////////////////////////////////////////////
while(*s)
void ClearLCDScreen(void) // Clear the Screen and return cursor to zero position
86
WriteCommandToLCD(0x01); // Clear the screen
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
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
Program:
#include <REG51.H>
#include <stdio.h>
int floor,tur,speed;
delay(c)
int i,j;
if(c==0)
for(i=0;i<500;i++)
for(j=0;j<speed;j++)
93
{
return;
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;
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:
102
Practical No.9
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
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:
108
Practical No.10
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
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:
117