You are on page 1of 53

1

ACKNOWLEDGEMENT

I am bringing this report on " EMBEDDED SYSTEM ". While carrying out this
project we received literary, guidance and inspiration from the professionals engaged
in education. I am grateful to Senior Er. Ankush Gawri & Er. Bhupinder Singh
at SLR CHANDIGARH for their encouraging guidance & support throughout the
course period.
I am thankful to all those people who stood by me throughout the training &
supported us in my project.





















2


CONTENTS
1. Numbering & Coding System....................3
1.1Converting from decimal to binary3
1.2 Converting from binary to hex..5
1.3 Converting from decimal to hex5
1.4 BCD number system.5
1.5 ASCII Code...6
1.6 Some Important Terminology...7
2. Internal Organization of Computers...7
2.1 Memories...8
2.2 Buses..9
2.3 Inside CPUs10
EMBEDDED SYSTEM
3. Microcontroller Versus Microprocessors.12
3.1 Microcontroller for Embedded system13
3.2 8051 Family.13
3.3 Versions of 8051 from Atmel..15
3.4 Pin description.16
4. Soldering Tips & Precautions...20
5. Regulated Power Supply..21
5.1 Transformer.21
5.2 Bridge Rectifier...23
5.3 Smoothing23
5.4 Regulator.24
5.5 Working of Power Supply..25
6. LED Interfacing26



3
6.1 Connecting & Soldering..27
6.2 Advantages of LEDs27
6.3 LED on I/O Port..30
7. Interfacing of LED with 8051 Microcontroller31
8. Keypad Interfacing...32
9.Seven Segment Display Interfacing..36
9.1 Types of Seven Segment.38
9.2 Interfacing Seven Segment Display to 8051...39
9.3 Applications.40
10. Liquid Crystal Display(LCD).40
10.1 Interfacing of Microcontroller with LCD display....42
11. Power Transistor(BC 369)..47
12. RELAY Interfacing47
12.1 Advantages of Relays...50
12.2 Disadvantages of Relays51
12.3 Relay Driver..51
12.4 Interfacing with Microcontroller...51










4
1.NUMBERING AND CODING SYSTEM
Various Number Systems are:
Decimal number system (base 10)
Binary system (base 2)
Octal system (base 8)
Hexadecimal system (base 16)
Human beings use decimal & computer use the binary system. The convenient
representation of binary numbers in base 16 is called hexadecimal number system.
The base of the decimal number system is 10 because it has 10 building blocks (i.e. 10
distinct symbols) which are 0, 1, 2, 3, .., 9. The base of the binary number system
is 2 because there are only two building blocks, 0 and 1, with which to generate
numbers. These two binary digits, 0 and 1, are referred to as bits. The binary system is
used in computers because 1 and 0 represent the two voltage levels (Low level/
Ground level & High level/ +VCC).The hexadecimal number system has 16 digits. In
this system, the first 10 digits, 0 to 9, are the same as in decimal, and for the
remaining six digits, the letters A, B, C, D, E, F are used.

1.1 Converting from decimal to binary:
Knowing the weight associated with each binary bit position allows one to convert a
decimal number to binary. This is shown in example:
Convert 39
10
to binary.
Weight 32 16 8 4 2 1
1 0 0 1 1 1
32+ 0+ 0+ 4+ 2+ 1 = 39
Therefore, 39
10
= 100111
2

Given Table shows the equivalent binary, decimal and hexadecimal representations
for 0 to 15.
Decimal Binary Hex
0 0000 0
1 0001 1
2 0010 2



5














1.2 Converting from binary to Hex:
To represent a binary number as its equivalent hexadecimal number, start from the
right and group 4 bits at a time, replacing each 4-bit binary number with its hex
equivalent shown in above table. Example: convert 100111110101 in hex.
First the number is grouped into sets of 4 bits: 1001 1111 0101
Then each group of 4 bits is replaced with its hex equivalent:
8 4 2 1 8 4 2 1 8 4 2 1
1 0 0 1 1 1 1 1 0 1 0 1
8+1 8+4+2+1 4+1
9 F 5
Therefore, 100111110101B = 9F5H

1.3Converting From decimal to hex
Converting from decimal to hex could be approached in two ways:
1. Convert to binary first and then convert to hex.
2. Convert directly from decimal to hex by repeated division, keeping track
remainders.
1.4 BCD (binary coded decimal) number system:
BCD stands for binary coded decimal. Binary representation of 0 to 9 is called BCD
as shown.
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F



6
Digit BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

Two terms for BCD numbers are used:
1. Unpacked BCD numbers
2. Packed BCD numbers
Unpacked BCD numbers: In unpacked BCD, the lower 4 bits of the number
represent the BCD number, and the rest of the bits are 0. For example: 00001001
is unpacked BCD for 9 and 00000011 is unpacked BCD for 3. Unpacked BCD
requires 1 byte memory or 8-bit register to store it.
Packed BCD number: In packed BCD, a single byte has two BCD numbers in it, one
in the lower 4 bits & one in the upper 4 bits. For example: 00111001 is packed
BCD for 39H. Packed BCD also requires 1 byte memory or 8-bit register to store it.

1.5 ASCII Code:
In 1960s a standard representation called ASCII (American Standard Code for
Information Interchange) was established. The ASCII (pronounced ask-E) code
assigns binary patterns for numbers 0 to 9, all the letters of English alphabet, both
uppercase and lowercase, and many control codes and punctuation marks. The ASCII
system uses a total of 7 bits to represent each code. The great advantage of this system
is that it is used by most computers and peripherals, so that the information can be
shared among them. ASCII code for letter A is 65 (1000001) and a is 97 (110
0001). Often, a zero is placed in the most significant bit (MSB) position to make it an
8-bit code. The use of ASCII is standard for keyboards, Printers and display devices



7
like monitors. The digits 0 through 9 are represented by ASCII codes 30H through
39H.
1.6 Some important terminology:
Bit ------------------------- 0 or 1
Nibble ------------------------- 4 bits
One Byte ------------------------- 8 bits
One word ------------------------- 16 bits (2 bytes)
One kilo ------------------------- 2
10
One Mega ------------------------- 2
20

One Giga ------------------------- 2
30

One Tera ------------------------- 2
40

2.Internal organization of Computers:
The internal working of every computer can be broken down into four parts:
CPU (central processing unit)
Memory
Buses
I/O (input output) devices






8
The function of the CPU is to execute (process) information stored in memory
(ROM). Peripheral means any device which is working around the center. Here, all
the I/O devices are peripherals because they are working around the CPU. The
function of I/O devices such as the keyboard and video monitor is to provide means of
communicating with the CPU. The CPU is connected to memory and I/O through
strips of wire called a bus. A bus carries information from place to place inside a
computer.
2.1 Memories:
Memory is the part of the computer system which stores the data. Two types of
memory commonly used in microcomputers are RAM (random access memory) and
ROM (read only memory). Let us see the difference between them.

S.
No.
RAM ROM
1. RAM is random access memory i.e.
any location of the RAM can be
accessed randomly as shown:

ROM is sequential memory i.e. ROM
locations can be accessed in a sequence
not in random fashion as shown:

2. RAM is read/write memory i.e.
when our application is working
then any of the operation can be
performed.
ROM is read only memory. When any
application is running at that time it can
not be written & only read operation can
be performed. To write the ROM a
special device known as ROM
PROGRAMMER/ ROM BURNER is
required.



9
3. RAM is volatile memory because
the data stored in it is lost when the
computer is turned off. That is why
RAM is also called temporary
memory because it is used to store
data/program temporarily.
ROM is non-volatile memory because it
retains the data stored in it even if power
is turned off. That is why ROM is called
ROM is permanent memory because it
can store the data permanently and
information stored can not be changed by
user.
4. RAM is used by the computer
when any application/ program is
running i.e. the application is
processed in this memory.
The Program/ code (Firmware) is stored
in this memory which is working behind
the application. And CPU read this code
from ROM & process (executes) it.

2.2 Buses:
A bus is a group of wires. A wire can carry a single bit (0 or 1). The size of any bus
represents the number of wires present in it. If any bus is 8-bit wide then it means it
has 8 wires and it can transfer 8 bits at a time from one location to another.
In every computer there are there types of buses:
Address bus
Data bus
Control bus
Data Bus:
Since data lines are used to carry information in and out of a CPU. More data lines
available the better the CPU lf one thinks of data lines as highway lines it is clear that
more lanes provide a batter between the CPU and its external device (such as printers
RAM, ROM etc.) by the same token that increase in the number of lines increases the
cost of construction more data buses mean a more expensive CPU and computer the
grouping of data lines is called data bus the average size of data buses in CPUs varies
between 8 and 64 Early computers such as apple 2 used an 8-bit data bus while
supercomputers such as Cray use a 64- bet data bus data buses are bidirectional since
the CPU must use them either to receive ort send data the processing power of a
computer is related to the size of its buses since an 8-bit bus can sand out 1 byte time
bus a16-bit bus can sand out 2bytes at time which is twice as fast.




10
Address Bus:
For a device (memory or I/O) to be recognized by the CPU it must be assigned an
address the address assigned to a given device must be unique no two device allowed
to have the same address. The CPU puts the address (in binary of course) on the
address bus and the decoding circuitry finds the device then the CPU uses the data bus
either to get data from that device or to send data to it.
The control buses are used to provide read or write signals to the device to indicate it
the CPU is asking for information or sending it information. Out of the three buses the
address bus and data bus determine the capability of a given CPU.
Since the address bus is used to identify the device and memory connected to the
CPU. The more address lines available the Larger the number of device that can be
addressed. In other words the number of address lines for a CPU determines the
number of locations with which it can communicate the number of locations is always
equal to 2
x
.where x is the number of address lines regardless of the size the of data
bus for example a CPU with 16 address lines can provide a total of 65,536 (2
16
) or
64k bytes of addressable memory. Each location can have maximum of l byte of data.
An another example the IBM PC uses a CPU with 24 address lines and 16 data lines
In this case the total accessible memory is 16 megabytes (2
24
X 2bytes=16megabytes).
The address bus is a unidirectional bus which means that the CPU uses the address
bus only to send out address. To summarize the total of memory locations addressable
by a given CPU is always equal to 2
x
where x the number of address bits regardless
the size the data bus.

2.3 Inside CPUs
A program stored in memory provides instructions to the CPU to perform an action.
The action can simply be adding data such as payroll data or controlling a machine
such as a robot. It is the function of the CPU to fetch these instructions from memory
and execute them to perform the action. All CPUs are equipped with resources such
as the following:
1. Among these resources, all CPUs contain a number of registers. The CPU uses
registers to store information temporarily. It could be two values to be
processed. Registers inside the CPU can be 8 bit, 16 bit, 32 bit or even 64-bit
registers depending on the CPU. In general the more and bigger the registers



11
the better the CPU. The disadvantage of more and bigger registers is the
increased cost of such a CPU.
2. The CPU also has what is called the ALU (arithmetic and logical unit). The
ALU section of the CPU is responsible for performing arithmetic functions
such as add, subtract, multiply and logic functions such as AND, OR and
NOT.
3. Every CPU also contains what is called a program counter. The function of
program counter is to contain the address of the next instruction to be
executed. As each instruction is executed the program counter is incremented
to point to the address of the next instruction to be executed. The contents of
the program counter are placed on the address bus to find and fetch the desired
instruction. In the IBM PC the program counter is a register called IP or the
instruction pointer.
4. The function of the instruction decoder is to decode the code of the instruction
fetched. One can think of the instruction decoder as kind of dictionary storing
the meaning of each instruction and what steps the CPU should take upon
receiving given instruction. Just as a dictionary requires more pages the more
words it defines, a CPU capable of understanding more instructions requires
more transistors to design.

Internal Block Diagram of a CPU

ALU

PROGRAM
COUNTER
INSTRUCTION
DECODER
FLAGS
REGISTER A
REGISTER B
REGISTER C
Address Bus
Data Bus



12
EMBEDDED SYSTEM

An embedded system is a special-purpose computer system designed to perform one
or a few dedicated functions, often with real-time computing constraints. It is usually
embedded as part of a complete device including hardware and mechanical parts. In
contrast, a general-purpose computer, such as a personal computer, can do many
different tasks depending on programming. Embedded systems control many of the
common devices in use today.
Since the embedded system is dedicated to specific tasks, design engineers can
optimize it, reducing the size and cost of the product, or increasing the reliability and
performance. Some embedded systems are mass-produced, benefiting from
economies of scale.
Embedded systems range from portable devices such as digital watches and MP4
players, to large stationary installations like traffic lights, factory controllers, or the
systems controlling nuclear power plants. Complexity varies from low, with a single
microcontroller chip, to very high with multiple units, peripherals and networks
mounted inside a large chassis or enclosure.

3.Microcontroller versus Microprocessors:
What is the difference between a microprocessor and microcontroller? The
microprocessors (such as 8086, 80286, 68000 etc.) contain no RAM, no ROM and no
I/O ports on the chip itself. For this reason they are referred as general- purpose
microprocessors. A system designer using general- purpose microprocessor must add
external RAM, ROM, I/O ports and timers to make them functional. Although the
addition of external RAM, ROM, and I/O ports make the system bulkier and much
more expensive, they have the advantage of versatility such that the designer can
decide on the amount of RAM, ROM and I/o ports needed to fit the task at hand. This
is the not the case with microcontrollers. A microcontroller has a CPU (a
microprocessor) in addition to the fixed amount of RAM, ROM, I/O ports, and timers
are all embedded together on the chip: therefore, the designer cannot add any external
memory, I/O, or timer to it. The fixed amount of on chip RAM, ROM, and number of
I/O ports in microcontrollers make them ideal for many applications in which cost and
space are critical. In many applications, for example a TV remote control, there is no



13
need for the computing power of a 486 or even a 8086 microprocessor. In many
applications, the space it takes, the power it consumes, and the price per unit are much
more critical considerations than the computing power. These applications most often
require some I/O operations to read signals and turn on and off certain bits. It is
interesting to know that some microcontrollers manufactures have gone as far as
integrating an ADC and other peripherals into the microcontrollers.
3.1 Microcontrollers for Embedded Systems:
In the literature discussing microprocessors, we often see a term embedded system.
Microprocessors and microcontrollers are widely used in embedded system products.
An embedded product uses a microprocessor (or microcontroller) to do one task and
one task only. A printer is an example of embedded system since the processor inside
it performs one task only: namely, get data and print it. Contrasting this with a IBM
PC which can be used for a number of applications such as word processor, print
server, network server, video game player, or internet terminal. Software for a variety
of applications can be loaded and run. Of course the reason a PC can perform myriad
tasks is that it has RAM memory and an operating system that loads the application
software into RAM and lets the CPU run it. In an embedded system, there is only one
application software that is burned into ROM. A PC contains or is connected to
various embedded products such as the keyboard, printer, modem, disk controller,
sound card, CD-ROM drive, mouse and so on. Each one of these peripherals has a
microcontroller inside it that performs only one task. For example, inside every mouse
there is a microcontroller to perform the task of finding the mouse position and
sending it to the PC.
Although microcontrollers are the preferred choice for many embedded systems, there
are times that a microcontroller is inadequate for the task. For this reason, in many
years the manufacturers for general-purpose microprocessors have targeted their
microprocessor for the high end of the embedded market.
3.2 A brief history of 8051 Family
In 1981, Intel Corporation introduced an 8-bit microcontroller called the 8051. This
microcontroller had 128 bytes of RAM, 4K bytes of on-chip ROM, two timers, one
serial port, and four ports (8-bit) all on a single chip. The 8051 is an 8-bit processor,
meaning the CPU can work on only 8- bit pieces to be processed by the CPU. The



14
8051 has a total of four I/O ports, each 8- bit wide. Although 8051 can have a
maximum of 64K bytes of on-chip ROM, many manufacturers put only 4K bytes on
the chip.
The 8051 became widely popular after Intel allowed other manufacturers to make any
flavor of the 8051 they please with the condition that they remain code compatible
with the 8051. This has led to many versions of the 8051 with different speeds and
amount of on-chip ROM marketed by more than half a dozen manufacturers. It is
important to know that although there are different flavors of the 8051, they are all
compatible with the original 8051 as far as the instructions are concerned. This means
that if you write your program for one, it will run on any one of them regardless of the
manufacturer. The major 8051 manufacturers are Intel, Atmel, Dallas
Semiconductors, Philips Corporation, Infineon.
8051 microcontroller
The 8051 is the original member of the 8051 family. Intel refers to it as MCS-51.

Other members of the 8051 family
There are two other members in the 8051 family of microcontrollers. They are the
8052 and the 8031.

Comparison of 8051 Family Members
Feature 8051 8052 8031
ROM (On Chip) 4K 8K 0K
RAM (Bytes) 128 256 128
Timers 2 3 2
I/O Pins 32 32 32
Serial Port 1 1 1
Interrupt Sources 6 8 6




15
3.3 Versions of 8051 from Atmel
Part Number ROM RAM I/O Pins Timers Interrupts V
cc

AT89C51 4K 128 32 2 6 5V
AT89LV51 4K 128 32 2 6 3V
AT89C1051 1K 64 15 1 3 3V
AT89C2051 2K 128 15 2 6 3V
AT89C52 8K 128 32 3 8 5V
AT89LV52 8K 128 32 3 8 3V

AT89C51 from ATMEL Corporation:
This popular 8051 chip has on-chip ROM in the form of flash memory. This is ideal
for fast development since flash memory can be erased in seconds compared to
twenty minutes or more needed for the earlier versions of the 8051. To use the
AT89C51 to develop a microcontroller-based system requires a ROM burner that
supports flash memory: However, a ROM eraser is not needed. Notice that in flash
memory you must erase the entire contents of ROM in order to program it again. The
PROM burner does this erasing of flash itself and this is why a separate burner is not
needed. To eliminate the need for a PROM burner Atmel is working on a version of
the AT89C51 that can be programmed by the serial COM port of the PC.

Atmel Microcontroller AT89C51
Features of AT89C51
40 pin Dual-in-line package



16
4 Kbytes of Flash
128 Bytes of RAM
32 I/O lines
Two16-Bit Timer/Counters
Two-Level Interrupt Architecture
Full Duplex Serial Port
On Chip Oscillator and Clock Circuitry
3.4 Pin description
The 89C51 have a total of 40 pins that are dedicated for various functions such as
I/O, RD, WR, address and interrupts. Out of 40 pins, a total of 32 pins are set
aside for the four ports P0, P1, P2, and P3, where each port takes 8 pins. The rest
of the pins are designated as V
cc
, GND, XTAL1, XTAL, RST, EA, and PSEN. All
these pins except PSEN and ALE are used by all members of the 8051 and 8031
families. In other words, they must be connected in order for the system to work,
regardless of whether the microcontroller is of the 8051 or the 8031 family. The
other two pins, PSEN and ALE are used mainly in 8031 based systems.




17
V
cc

Pin 40 provides supply voltage to the chip. The voltage source is +5V.
GND
Pin 20 is the ground.
Oscillator Characteristics
XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier which can be configured for use as an on-chip oscillator, as shown in
Figure. Either a quartz crystal or ceramic resonator may be used. To drive the
device from an external clock source, XTAL2 should be left unconnected while
XTAL1 is driven as shown in Figure.

Oscillator Connections
It must be noted that there are various speeds of the 8051 family. Speed refers to
the maximum oscillator frequency connected to the XTAL. For example, a 12
MHz chip must be connected to a crystal with 12 MHz frequency or less.
Likewise, a 20 MHz microcontroller requires a crystal frequency of no more than
20 MHZ. When the 8051 is connected to a crystal oscillator and is powered up,
we can observe the frequency on the XTAL2 pin using oscilloscope.
RST
Pin 9 is the reset pin. It is an input and is active high (normally low). Upon
applying a high pulse to this pin, the microcontroller will reset and terminate all
activities. This is often referred to as a power on reset. Activating a power-on
reset will cause all values in the registers to be lost. Notice that the value of
Program Counter is 0000 upon reset, forcing the CPU to fetch the first code from



18
ROM memory location 0000. This means that we must place the first line of
source code in ROM location 0000 that is where the CPU wakes up and expects to
find the first instruction. In order to RESET input to be effective, it must have a
minimum duration of 2 machine cycles. In other words, the high pulse must be
high for a minimum of 2 machine cycles before it is allowed to go low.
EA
All the 8051 family members come with on-chip ROM to store programs. In such
cases, the EA pin is connected to the V
cc
. For family members such as 8031 and
8032 in which there is no on-chip ROM, code is stored on an external ROM and is
fetched by the 8031/32. Therefore for the 8031 the EA pin must be connected to
ground to indicate that the code is stored externally. EA, which stands for
external access, is pin number 31 in the DIP packages. It is input pin and must
be connected to either V
cc
or GND. In other words, it cannot be left unconnected.
PSEN
This is an output pin. PSEN stands for program store enable. It is the read strobe
to external program memory. When the microcontroller is executing from external
memory, PSEN is activated twice each machine cycle.
ALE
ALE (Address latch enable) is an output pin and is active high. When connecting
a microcontroller to external memory, port 0 provides both address and data. In
other words the microcontroller multiplexes address and data through port 0 to
save pins. The ALE pin is used for de-multiplexing the address and data by
connecting to the G pin of the 74LS373 chip.
I/O port pins and their functions
The four ports P0, P1, P2, and P3 each use 8 pins, making them 8-bit ports. All the
ports upon RESET are configured as output, ready to be used as output ports. To
use any of these as input port, it must be programmed.
Port 0
Port 0 occupies a total of 8 pins (pins 32 to 39). It can be used for input or output.
To use the pins of port 0 as both input and output ports, each pin must be
connected externally to a 10K-ohm pull-up resistor. This is due to fact that port 0



19
is an open drain, unlike P1, P2 and P3. With external pull-up resistors connected
upon reset, port 0 is configured as output port. In order to make port 0 an input
port, the port must be programmed by writing 1 to all the bits of it. Port 0 is also
designated as AD0-AD7, allowing it to be used for both data and address. When
connecting a microcontroller to an external memory, port 0 provides both address
and data. The microcontroller multiplexes address and data through port 0 to save
pins. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-
D7, but when ALE=1 it has address A0-A7. Therefore, ALE is used for de-
multiplexing address and data with the help of latch 74LS373.
Port 1
Port 1 occupies a total of 8 pins (pins 1 to 8). It can be used as input or output. In
contrast to port 0, this port does not require pull-up resistors since it has already
pull-up resistors internally. Upon reset, port 1 is configures as an output port.
Similar to port 0, port 1 can be used as an input port by writing 1 to all its bits.
Port 2
Port 2 occupies a total of 8 pins (pins 21 to 28). It can be used as input or output.
Just like P1, port 2 does not need any pull-up resistors since it has pull-up resistors
internally. Upon reset port 2 is configured as output port. To make port 2 as input
port, it must be programmed as such by writing 1s to it.
Port 3
Port 3 occupies a total of 8 pins (pins 10 to 17). It can be used as input or output.
P3 does not need any pull-up resistors, the same as P1 and P2 did not. Although
port 3 is configured as output port upon reset, this is not the way it is most
commonly used. Port 3 has an additional function of providing some extremely
important signals such as interrupts. Some of the alternate functions of P3 are
listed below:
P3.0 RXD (Serial input)
P3.1 TXD (Serial output)
P3.2 INT0 (External interrupt 0)
P3.3 INT1 (External interrupt 1)



20
P3.4 T0 (Timer 0 external input)
P3.5 T1 (Timer 1 external input)
P3.6 WR (External memory write strobe)
P3.7 RD (External memory read strobe)
4.SOLDERING TIPS & PRECAUTIONS
Bend the component leads at right angles with both bends at the same distance
apart as the PCB pad holes.
Ensure that both component leads and the copper PCB pads are clean and free
of oxidization.
Insert component leads into holes and bend leads at about 30 degrees from
vertical.
Using small angle cutters, cut the leads at about 0.1 - 0.2 of an inch (about 2 -
4 mm) above copper pad.
Bring tinned soldering iron tip into contact with both the component lead and
the PCB pad. This ensures that both surfaces undergo the same temperature
rise.
Bring resin cored solder in contact with the lead and the copper pad. Feed just
enough solder to flow freely over the pad and the lead without a blobbing
effect. The final solder joint should be shiny and concave indicating good
wetting of both the copper pad and the component lead. If a crack appears at
the solder to metal interface then the potential for forming a dry joint exists. If
an unsatisfactory joint is formed, suck all the solder off the joint using a solder
sucker or solder wick (braid) and start again.
PRECAUTIONS
1. Mount the components at the appropriate places before soldering. Follow the
circuit description and components details, leads identification etc. Do not
start soldering before making it confirm that all the components are mounted
at the right place.
2. Do not use a spread solder on the board, it may cause short circuit.
3. Do not sit under the fan while soldering.
4. Position the board so that gravity tends to keep the solder where you want it.



21
5. Do not over heat the components at the board. Excess heat may damage the
components or board.
6. The board should not vibrate while soldering otherwise you have a dry or a
cold joint.
7. Do not put the kit under or over voltage source. Be sure about the voltage
either is DC or AC while operating the gadget.
8. Do spare the bare ends of the components leads otherwise it may short circuit
with the other components. To prevent this use sleeves at the component leads
or use sleeved wire for connections.
9. Do not use old dark colors solder. It may give dry joint. Be sure that all the
joints are clean and well shiny.
10. Do make loose wire connections especially with cell holder, speaker, probes
etc. Put knots while connections to the circuit board, otherwise it may get
loose.

5. REGULATED POWER SUPPLY
Power supplies are designed to convert high voltage AC mains to a suitable low
voltage supply for electronic circuits and other devices. A power supply can be
broken down into a series of blocks, each of which performs a particular function.
For example a 5V regulated supply:

Each of the blocks has its own function as described below
1. Transformer steps down high voltage AC mains to low voltage AC.
2. Rectifier converts AC to DC, but the DC output is varying.
3. Smoothing smoothes the DC from varying greatly to a small ripple.
4. Regulator eliminates ripple by setting DC output to a fixed voltage.
5.1 Transformer
Transformers convert AC electricity from one voltage to another with little loss of
power. Transformers work only with AC and this is one of the reasons why mains
electricity is AC. The two types of transformers
Step-up transformers increase voltage,



22
Step-down transformers reduce voltage.
Most power supplies use a step-down transformer to reduce the dangerously
high mains voltage (230V in UK) to a safer low voltage. The input coil is called
the primary and the output coil is called the secondary. There is no electrical
connection between the two coils, instead they are linked by an alternating
magnetic field created in the soft-iron core of the transformer. The two lines in the
middle of the circuit symbol represent the core.


Transformers waste very little power so the power out is (almost) equal to the power
in. Note that as voltage is stepped down current is stepped up. The ratio of the number
of turns on each coil, called the turn ratio, determines the ratio of the voltages. A step-
down transformer has a large number of turns on its primary (input) coil which is
connected to the high voltage mains supply, and a small number of turns on its
secondary (output) coil to give a low output voltage.
Turns Ratio =



And Power Out = Power In
Vs Is = Vp Ip
Where
Vp = primary (input) voltage
Np = number of turns on primary coil
Ip = primary (input) current
Ns = number of turns on secondary coil
Is = secondary (output) current
Vs = secondary (output) voltage



23
5.2 Bridge Rectifier
A bridge rectifier can be made using four individual diodes, but it is also available in
special packages containing the four diodes required. It is called a full-wave rectifier
because it uses all AC wave (both positive and negative sections). 1.4V is used up in
the bridge rectifier because each diode uses 0.7V when conducting and there are
always two diodes conducting, as shown in the diagram below. Bridge rectifiers are
rated by the maximum current they can pass and the maximum reverse voltage they
can withstand (this must be at least three times the supply RMS voltage so the
rectifier can withstand the peak voltages). In this alternate pairs of diodes conduct,
changing over the connections so the alternating directions of AC are converted to the
one direction of DC.

OUTPUT Full-wave Varying DC
5.3 SMOOTHING
Smoothing is performed by a large value electrolytic capacitor connected across the
DC supply to act as a reservoir, supplying current to the output when the varying
DC voltage from the rectifier is falling. The diagram shows the unsmoothed
varying DC (dotted line) and the smoothed DC (solid line). The capacitor charges
quickly near the peak of the varying DC, and then discharges as it supplies current to
the output.



24


Note that smoothing significantly increases the average DC voltage to almost the peak
value (1.4 RMS value). For example 6V RMS AC is rectified to full wave DC of
about 4.6V RMS (1.4V is lost in the bridge rectifier), with smoothing this
increases to almost the peak value giving 1.4 4.6 = 6.4V smooth DC.
Smoothing is not perfect due to the capacitor voltage falling a little as it discharges,
giving a small ripple voltage. For many circuits a ripple which is 10% of the supply
voltage is satisfactory and the equation below gives the required value for the
smoothing capacitor. A larger capacitor will give fewer ripples. The capacitor value
must be doubled when smoothing half-wave DC.
Smoothing capacitor for 10% ripple, C = 5 Io
Vs f
Where
C = smoothing capacitance in farads (F)
Io = output current from the supply in amps (A)
Vs = supply voltage in volts (V), this is the peak value of the unsmoothed DC
f = frequency of the AC supply in hertz (Hz), 50Hz in the UK
5.4 REGULATOR





25
Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or variable
output voltages. They are also rated by the maximum current they can pass. Negative
voltage regulators are available, mainly for use in dual supplies. Most regulators
include some automatic protection from excessive current (overload protection') and
overheating (thermal protection'). Many of the fixed voltage regulator ICs has 3 leads
and look like power transistors, such as the 7805 +5V 1A regulator shown on the
right. They include a hole for attaching a heat sink if necessary.
6. Working of Power Supply
Transformer

The low voltage AC output is suitable for lamps, heaters and special AC motors. It is
not suitable for electronic circuits unless they include a rectifier and a smoothing
capacitor.
Transformer + Rectifier


The varying DC output is suitable for lamps, heaters and standard motors. It is not
suitable for electronic circuits unless they include a smoothing capacitor.
Transformer + Rectifier + Smoothing





26
The smooth DC output has a small ripple. It is suitable for most electronic circuits.
Transformer + Rectifier + Smoothing + Regulator

The regulated DC output is very smooth with no ripple. It is suitable for all electronic
circuits.
7. LED INTERFACING
When you need to add light to a model, an ordinary filament lamp is the first thing
that springs to mind. But if you dont need a high light output, or you need light as an
indicator, an LED has many advantages over a lamp. LEDS are basically the single
light display that include incandescent and are treated as single binary points to be
switched on and off by programmer instructions. The individual light display is easy
to use. A port presents a bit or a character and then strobe the device.
Like a normal diode, an LED consists of a chip of semiconducting material
impregnated, or doped, with impurities to create a p-n junction. As in other diodes,
current flows easily from the p-side, or anode, to the n-side, or cathode, but not in the
reverse direction. Charge-carrierselectrons and holesflow into the junction from
electrodes with different voltages. When an electron meets a hole, it falls into a lower
energy level, and releases energy in the form of a photon. The wavelength of the light
emitted, and therefore its color, depends on the band gap energy of the materials
forming the p-n junction. In silicon or germanium diodes, the electrons and holes
recombine by a non-radiative transition which produces no optical emission, because
these are indirect band gap materials. The materials used for an LED have a direct
band gap with energies corresponding to near-infrared, visible or near-ultraviolet
light. LED development began with infrared and red devices made with gallium
D2
C1
1000uf
1N4007 +5V
V
LM7805
1 2
3
VIN VOUT
G
N
D
J1
1
2
3
D3
gnd
D4
D1



27
arsenide. Advances in materials science have made possible the production of devices
with ever-shorter wavelengths, producing light in a variety of colors.
LED symbol

6.1Connecting and soldering
LEDs must be connected the correct way round, the diagram may be labeled a or + for
anode and k or - for cathode (yes, it really is k, not c, for cathode!). The cathode is the
short lead and there may be a slight flat on the body of round LEDs. If you can see
inside the LED the cathode is the larger electrode (but this is not an official
identification method).



LEDs can be damaged by heat when soldering, but the risk is small unless you are
very slow. No special precautions are needed for soldering most LEDs.
6.2 Advantages of LEDs
Shapes and Sizes
LEDs are available in many shapes and sizes, some of which are shown in the
selection below. The 'standard' LED shape is the 5mm diameter domed type, and the
smaller 3mm domed type is also popular.
1. Tri-LED array
2. 10 segment bar displays
3. Domed LED sizes 3, 5, 8, 10mm
4. Panel mounting LED
5. PCB mounting LED
6. 26mm red & green LED cluster



28
6.3 Colors:
LEDs have traditionally been red, orange, yellow, or green, but advances in LED
technology mean that blue and white LEDs are now available, though at a much
higher price. These LEDs are considerably brighter than standard LEDs so they could
be used for lighting, but you will find the ones described as 'white' still have a blue
tinge.






The table below shows typical technical data for some 5mm diameter round LEDs
with diffused packages (plastic bodies). Only three columns are important and these
are shown in bold. Please see below for explanations of the quantities.
Type Colour I
F

max.
V
F

typ.
V
F

max.
V
R

ma
x
Luminous
intensity
Viewi
ng
angle
Wavelen
gth
Standar
d
Red 30mA 1.7V 2.1v 5v 5mcd @ 10mA 60 660nm
Standar
d
Bright
red
30mA 2.0V 2.5v 5v 80mcd @ 10mA 60 625nm
Standar
d
Yellow 30mA 2.1V 2.5v 5v 32mcd @ 10mA 60 590nm
Standar
d
Green 25mA 2.2V 2.5v 5v 32mcd @ 10mA 60 565nm
High
intensity
Blue 30mA 4.5v 5.5v 5v 60mcd @ 20mA 50 430nm
Super
bright
Red 30mA 1.85v 2.5v 5v 500mcd@ 20mA 60 660nm
Low
current
Red 30mA 1.7v 2.0v 5v 5mcd @ 2mA 60 625nm




29
I
F
max.: Maximum forward current, forward just means with the LED connected
correctly.
V
F
typ.: Typical forward voltage VL

in the LED resistor calculation.
This is about 2V, except for blue and white LEDs for which it is about 4V.
V
F
max.: Maximum forward voltage.
V
R
max.: Maximum reverse voltage .
You can ignore this for LEDs connected the correct way round.
Luminous intensity Brightness of the LED at the given current, mcd = milli-candela.
Viewing angle Standard LEDs have a viewing angle of 60, others emit a narrower
beam of about 30.
Wavelength The peak wavelength of the light emitted, this determines the colour of
the LED.
nm = nanometer.
Also available are LEDs described as 'bi-color' and 'tri-color'. Bi-color LEDs typically
incorporate one red and one green LED in the same package. Since they have only
two leads, only one LED can be on at any time. Tri-color LEDs also have two LEDs
in one package, but because they have three leads, both LEDs can be switched on
together, their light combining to make a third color, typically orange. The central
lead of such a package is the common for both LEDs. Some manufacturers produce
true 'tri-color' LEDs incorporating red, green, and blue LEDs, so in theory it is
possible to create light of any color. The physical color of an LED package does not
necessarily indicate the color it will be when switched on. Some LEDs have a clear
plastic package, while others may have a diffused plastic package.
1. Standard red, green and yellow LEDs
2. Bi-color LEDs
3. Tri-color LEDs
Current Consumption
LEDs consume much less current than lamps - usually only 20mA - so they are ideal
for battery powered models.
Long Life:
LEDs rarely fail (unless you supply them with the wrong voltage!) so are handy in
parts of a model that are hard to reach.
Which Way Around?



30
How can you tell which lead on an LED is which? Figure 2 shows a standard domed
LED. If brought new, you will find that the longest lead is the positive lead, or
'anode', and the shortest lead is the negative lead, or 'cathode'. If the leads have been
cut there are a few other ways to find out the polarity:
The plastic package nearest the cathode will be flattened slightly.
When holding the LED up to a light, the largest triangular section inside will be
nearest the cathode. You can also connect up the LED (as in Figure 1) both ways
around to see which is correct - reverse biasing the LED won't do it any harm.

6.4 LED ON I/O PORTS
Since TTL an output is designed to feed multiple TTL inputs, they are good at current
sinking but poor at current sourcing. The Standard TTL can sink up to 16mA and
source 250uA. The LS logic family can sink 8mA and source 100uA. The 8051 port
pin can sink 1.6mA (3.2mA for port 0) and source 60uA. Therefore, if you drive
significant current, try to arrange your circuits to use current sinking.
Unlike diodes, Light-emitting diodes have a forward voltage drop from 1.7 to 2.5
volts and most of them flow a forward current 20mA.
Poor circuit
Since the TTL output can't source above 1mA so the LED will be very dim.
Fair circuit
The LED will conduct heavily at about 2V and the extra 3V has to be dropped in the
TTL circuitry. This causes high power dissipation in the TTL or the LED fails.
Good circuit
The resistor limits the current. The resistance can be calculated by assuming its
voltage is about 2.5V and the TTL output is 0.9V. For 2.2V LED, 1.9V is across the
resistor so the 220ohm would limit the current to 8.6mA (1.9/220). For 1.7V LED,
2.4V is across the resistor so it would limit the current to 10.9mA (2.4/220). The
resistor should not less than 100ohm or the LED would fail.







31
7. Interfacing of LED with 8051 Microcontroller
For interfacing a single Led to 89c51 microcontroller, we connect the anode (+) end
of LED to the designated port pin via a pull-up resistor. While the cathode end of
LED is connected to GND. Connection of 1 LED to 89c51 port pins. For glowing a
LED, a high logic is required at the anode (+), so port pin is set to high for glowing
LED. One end of single LED is connected to port pin of 89c51 via a pull up resistor
and other one is grounded.

Four ON-Four OFF Pattern

#include<reg51.h> // This file contains the Ports and SFR address of 8051
#include<delay.h> // This file is used to produce seconds and milliseconds delay
#define led P1 // 'P1' is given the another name as led, you can use 'led'
Or directly 'P1' //for programming

void main() // main program starts from here
{
while (1) // Repeat forever
{
led=0xf0; // light on lower 4 leds '0'-> ON (11110000)
secdelay(1); // 1 secdelay
led=0x0f; // light on upper 4 leds '1'-> OFF (00001111)
D3
LED
C?
CAP NP
D7
LED
D4
LED
D5
LED
D8
LED
U?
AT89C52
9
18
19 29
30
31
1
2
3
4
5
6
7
8
21
22
23
24
25
26
27
28
10
11
12
13
14
15
16
17
39
38
37
36
35
34
33
32
RST
XTAL2
XTAL1 PSEN
ALE/PROG
EA/VPP
P1.0/T2
P1.1/T2-EX
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
P2.0/A8
P2.1/A9
P2.2/A10
P2.3/A11
P2.4/A12
P2.5/A13
P2.6/A14
P2.7/A15
P3.0/RXD
P3.1/TXD
P3.2/INTO
P3.3/INT1
P3.4/TO
P3.5/T1
P3.6/WR
P3.7/RD
P0.0/AD0
P0.1/AD1
P0.2/AD2
P0.3/AD3
P0.4/AD4
P0.5/AD5
P0.6/AD6
P0.7/AD7
D1
LED
R1
R
40
D2
LED
Y?
CRYSTAL
VCC
D6
LED
20



32
secdelay (1);
}
}
All ON-All OFF Pattern

#include<reg51.h> // This file contains the Ports and SFR address of 8051
#include<delay.h> // This file is used to produce seconds and milliseconds delay
#define led P1 // 'P1' is given the another name as led, you can use 'led'
Or directly 'P1' //for programming

void main() // main program starts from here
{
while (1) // Repeat forever
{
led=0x00; // All leds on '0'-> ON (00000000)
secdelay(1); // 1 secdelay
led=0x0f; // All leds off '1'-> OFF (11111111)
secdelay (1);
}
}
8. KEYPAD INTERFACING:
In electrical engineering, a switch is an electrical component that can break
an electrical circuit, interrupting the current or diverting it from one conductor to
another.
The most familiar form of switch is a manually operated electromechanical device
with one or more sets of electrical contacts, which are connected to external circuits.
Each set of contacts can be in one of two states: either "closed" meaning the contacts
are touching and electricity can flow between them, or "open", meaning the contacts
are separated and the switch is non-conducting. The mechanism actuating the
transition between these two states (open or closed) can be either a "toggle" (flip
switch for continuous "on" or "off") or "momentary" (push-for "on" or push-for "off")
type.
A switch may be directly manipulated by a human as a control signal to a system,
such as a computer keyboard button, or to control power flow in a circuit, such as
a light switch. Automatically operated switches can be used to control the motions of
machines, for example, to indicate that a garage door has reached its full open
position or that a machine tool is in a position to accept another work piece. Switches
may be operated by process variables such as pressure, temperature, flow, current,



33
voltage, and force, acting as sensors in a process and used to automatically control a
system. For example, a thermostat is a temperature-operated switch used to control a
heating process. A switch that is operated by another electrical circuit is called a relay.
Large switches may be remotely operated by a motor drive mechanism. Some
switches are used to isolate electric power from a system, providing a visible point of
isolation that can be pad-locked if necessary to prevent accidental operation of a
machine during maintenance, or to prevent electric shock.

Various Types of Switches
Electrical switches. Top, left to right: circuit breaker, mercury switch, wafer
switch, DIP switch, surface mount switch, reed switch. Bottom, left to right: wall
switch (U.S. style), miniature toggle switch, in-line switch, push-button switch, rocker
switch, micro-switch.
In electronics engineering, an ideal switch describes a switch that:
has no current limit during its ON state
has infinite resistance during its OFF state
has no voltage drop across the switch during its ON state
has no voltage limit during its OFF state
has zero rise time and fall time during state changes
switches without "bouncing" between on and off positions
Practical switches fall short of this ideal, and have resistance, limits on the current and
voltage they can handle, finite switching time, etc. The ideal switch is often used in
circuit analysis as it greatly simplifies the system of equations to be solved, however
this can lead to a less accurate solution.



34
Contacts
In the simplest case, a switch has two conductive pieces, often metal, called contacts,
connected to an external circuit, that touch to complete (make) the circuit, and
separate to open (break) the circuit. The contact material is chosen for its resistance
to corrosion, because most metals form insulating oxides that would prevent the
switch from working. Contact materials are also chosen on the basis of electrical
conductivity, hardness (resistance to abrasive wear), mechanical strength, low cost
and low toxicity.
Sometimes the contacts are plated with noble metals. They may be designed to wipe
against each other to clean off any contamination. Nonmetallic conductors, such as
conductive plastic, are sometimes used. To prevent the formation of insulating oxides,
a minimum wetting current may be specified for a given switch design.
Contact bounce

Contact bounce (also called chatter) is a common problem with mechanical switches
and relays. Switch and relay contacts are usually made of springy metals that are
forced into contact by an actuator. When the contacts strike together, their momentum
and elasticity act together to cause bounce. The result is a rapidly pulsed electric
current instead of a clean transition from zero to full current. The effect is usually
unimportant in power circuits, but causes problems in some analogue and logic
circuits that respond fast enough to misinterpret the on-off pulses as a data stream.
The effects of contact bounce can be eliminated by use of mercury-wetted contacts,
but these are now infrequently used because of the hazard of mercury release.
A micro switch is a switch which can be operated using a very small force and also
possibly using a small movement.




35
This is a two terminal switch. Both terminals get shorted when it is pressed (i.e. in
closed state) and both the terminals get disconnected when it is released (i.e. in open
state). Any input signal is applied at one of its terminals and when it is pressed (i.e. in
closed position) the same input signal is received at the other terminal.
The switches can be used in two ways:
(a) Switch in Press Position when the MCU performs its task immediately after
pressing the switch
(b) Switch in release Position when MCU does not perform any task but waits for
the release of switch and performs the task after releasing the switch.
In our switch pad, there are three micro switches connected to the microcontroller I/O
pins. One end of each switch is grounded and other is connected to the
microcontroller port, as in Figure. When any switch is pressed that particular port is
grounded. The microcontroller always monitors these switches in real time (i.e. in
continuous mode).
Interfacing of Switches with C

LEDs + Switches
#include<reg51.h> //This file contains the Ports and SFR address
of 8051
#include<delay.h> //This file is used to produce seconds and
miliseconds delay
#define led P1 // 'P1' is given the another name as 'led' ,u can use
'led' Or directly 'P1'
//for programming
sbit s1=P3^2; // define only single bit using sbit syntex



36
sbit s2=P3^3;
sbit s3=P3^4;
void main() // main program starts from here
{
led=0xff;
while(1) // Infinite Loop for infinite rotation
{
if(s1==0)
{
led=0x00;
secdelay(1);
led=0xff;
secdelay(1);
}
else if(s2==0)
{
led=0xf0;
secdelay(1);
led=0x0f;
secdelay(1);
}
else if(s3==0)
{
led=0xaa;
secdelay(1);
led=0x55;
secdelay(1);
}
else
{
led=0xff;
}
}
}
9. SEVEN SEGMENT DISPLAY INTERFACING
Character display that is commonly used these days is called seven segment displays
because they are easy to read under low ambient light. Another type of display is
called LCD display which is useful in low power or battery operated system. Unlike
LEDs, LCDs are visible in bright ambient light. Since LCDs do not emit light, they
are visible in low light environment. These days, a combination of LCDs and LEDs
are used to enable LCDs to be visible even in low ambient light environment. LCDs
are not efficient at low temperature environment. The characters size available is in
0.3 inch, 0.6 inch and larger sizes.



37
A seven segment LED display is a special arrangement of 7 LED elements to form a
rectangular shape using two vertical segments on each side with one horizontal
segment on the top, middle, and bottom. By individually turning the segments on or
off, numbers from 0 to 9 and some letters can be displayed. Seven segment displays
sometime also have an eighth segment to display the decimal point. Therefore, a
seven-segment display will require seven outputs from the microcontroller to display
a number, and one more output if the decimal point is to be displayed too.
A common technique is to use a shaped piece of translucent plastic to operate as a
specialized optical fiber, to distribute the light from the LED evenly over a fixed bar
shape. The seven bars are laid out as a squared-off figure "8". The result is known as a
seven-segment LED.


The segments are marked with non-capital letters: a, b, c, d, e, f, g and dp, where dp is
the decimal point. The 8 LEDs inside the display can be arranged with a common
cathode or common anode configuration.



Packages




38
Seven-segment displays can be packaged in a number of ways. Three typical
packages are shown above. On the left we see three small digits in a single 12-pin DIP
package. The second package is essentially a 14-pin DIP designed to be installed
vertically. Note that for this particular device, the decimal point is on the left. This is
not true of all seven-segment displays in this type of package.
One limitation of the DIP package is that it cannot support larger digits. To get larger
displays for easy reading at a distance, it is necessary to change the package size and
shape. The package on the right above is larger than the other two, and thus can
display a digit that is significantly larger than will fit on a standard DIP footprint.
Even larger displays are also available; some digital clocks sport digits that are two to
five inches tall.
9.1 Types of Seven Segment Display
Seven segment displays can be divided into 2 types of connection.
Common cathode
With a common cathode display, the cathodes of all segment LEDs are tied together
and this common point must be connected to the ground. A required LED segment is
then turned on by applying logic 1 to its anode.

Common anode
In common anode displays, all the anodes are tied together and the common anode is
connected to the supply voltage Vcc. Individual segments are turned on by applying
logic 0 to their cathodes.




39
9.2 Interfacing seven segment display to 8051

Hexadecimal display
This table gives the hexadecimal encodings for displaying the digits 0 to F:




40
9.3 Applications
Seven segment LED displays are often found in clock radios, VCRs, microwave
ovens, toys and many other household items. They are primarily used to display
decimal numbers but they can also display a few alphabets and other characters. You
will make a hexadecimal counter that counts from 0 (00h) to 15 (0Fh) and display the
value on the seven segment LED display.
Up counter on seven segment display:
#include<reg51.h>
#include<delay.h>
#define seg_port P2 // define segment port
// array is used to store the value of data to be sent on the port to
display
// any digit on seven segment as below
unsigned char i,
seg_array[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
void main()
{
while(1)
{
for(i=0;i<=9,i++)
{
seg_port=seg_array[maxlen]; // show '0' on 7 segment
secdelay(1); // 1second delay
}
}
}

10. LIQUID CRYSTAL DISPLAY (LCD)
Liquid crystal displays (LCD) are widely used in recent years as compares to LEDs.
This is due to the declining prices of LCD, the ability to display numbers, characters
and graphics, incorporation of a refreshing controller into the LCD, their by relieving
the CPU of the task of refreshing the LCD and also the ease of programming for
characters and graphics. HD 44780 based LCDs are most commonly used.
The LCD, which is used as a display in the system, is LMB162A. The main features
of this LCD are: 16 X 2 display, intelligent LCD, used for alphanumeric characters &
based on ASCII codes. This LCD contains 16 pins, in which 8 pins are used as 8-bit
data I/O, which are extended ASCII. Three pins are used as control lines these are
Read/Write pin, Enable pin and Register select pin. Two pins are used for Backlight
and LCD voltage, another two pins are for Backlight & LCD ground and one pin is
used for contrast change.



41
LCD pin description
LCD pin description
The LCD discuss in this section has the most common connector used for the Hitachi
44780 based LCD is 14 pins in a row and modes of operation and how to program and
interface with microcontroller is describes in this section.


LCD Pin Description Diagram

Vcc
16
15
14
13
12
11
10
9
8
6
5
4
3
2
1
7
16
15
14
13
12
11
10
9
8
6
5
4
3
2
1
7
D7
E
Vcc
D4
Contrast
RS
Gnd
R/W
Gnd
D0
D3
D6
D5
1
3
2
D2
D1
Pin Symbol I/O Description
1 VSS - Ground
2 VCC - +5V power supply
3 VEE - Power supply to control contrast
4 RS I RS=0 to select command register, RS=1 to select data
register.
5 R/W I R/W=0 for write, R/W=1 for read
6 E I/O Enable
7 DB0 I/O The 8 bit data bus
8 DB1 I/O The 8 bit data bus
9 DB2 I/O The 8 bit data bus
10 DB3 I/O The 8 bit data bus
11 DB4 I/O The 8 bit data bus
12 DB5 I/O The 8 bit data bus
13 DB6 I/O The 8 bit data bus
14 DB7 I/O The 8 bit data bus



42
V
CC
, V
SS
, V
EE

The voltage V
CC
and V
SS
provided by +5V and ground respectively while V
EE
is used
for controlling LCD contrast. Variable voltage between Ground and V
cc
is used to
specify the contrast (or "darkness") of the characters on the LCD screen.
RS (register select)
There are two important registers inside the LCD. The RS pin is used for their
selection as follows. If RS=0, the instruction command code register is selected, then
allowing to user to send a command such as clear display, cursor at home etc.. If
RS=1, the data register is selected, allowing the user to send data to be displayed on
the LCD.
R/W (read/write)
The R/W (read/write) input allowing the user to write information from it. R/W=1,
when it read and R/W=0, when it writing.
EN (enable)
The enable pin is used by the LCD to latch information presented to its data pins.
When data is supplied to data pins, a high power, a high-to-low pulse must be applied
to this pin in order to for the LCD to latch in the data presented at the data pins.
D0-D7 (data lines)
The 8-bit data pins, D0-D7, are used to send information to the LCD or read the
contents of the LCDs internal registers. To displays the letters and numbers, we send
ASCII codes for the letters A-Z, a-z, and numbers 0-9 to these pins while making RS
=1. There are also command codes that can be sent to clear the display or force the
cursor to the home position or blink the cursor.
We also use RS =0 to check the busy flag bit to see if the LCD is ready to receive the
information. The busy flag is D7 and can be read when R/W =1 and RS =0, as
follows: if R/W =1 and RS =0, when D7 =1(busy flag =1), the LCD is busy taking
care of internal operations and will not accept any information. When D7 =0, the LCD
is ready to receive new information.

10.1 Interfacing of micro controller with LCD display
In most applications, the "R/W" line is grounded. This simplifies the application
because when data is read back, the microcontroller I/O pins have to be alternated
between input and output modes.



43
In this case, "R/W" to ground and just wait the maximum amount of time for each
instruction (4.1ms for clearing the display or moving the cursor/display to the "home
position", 160s for all other commands) and also the application software is simpler,
it also frees up a microcontroller pin for other uses. Different LCD execute
instructions at different rates and to avoid problems later on (such as if the LCD is
changed to a slower unit). Before sending commands or data to the LCD module, the
Module must be initialized. Once the initialization is complete, the LCD can be
written to with data or instructions as required. Each character to display is written
like the control bytes, except that the "RS" line is set. During initialization, by setting
the "S/C" bit during the "Move Cursor/Shift Display" command, after each character
is sent to the LCD, the cursor built into the LCD will increment to the next position
(either right or left). Normally, the "S/C" bit is set (equal to "1")

Interfacing of Microcontroller with LCD
LCD Command Code
LCD
1234567891
0
1
1
1
2
1
3
1
4
1
5
1
6
8 Bit Data Bus
of LCD To MCU
Port
Control Pins of
LCD To MCU Port
Pins
VCC
Code
(HEX)
Command to LCD Instruction
Register
1 Clear the display screen
2 Return home
4 Decrement cursor(shift cursor to left)
6 Increment cursor(shift cursor to right)
7 Shift display right



44




Circuit:


LCD Display:
#include<reg51.h>
#include<delay.h>
#define DATA P1 // define DATA and Control Pins of LCD
sbit RS=P3^5;
sbit RW=P3^6;
sbit E=P3^7;
void lcd_cmd(unsigned char datax) // function to write command at
lcd port
{
ms_delay(20);
DATA=datax;
RS=0; //clear RS (ie. RS=0) to write command
RW=0; // write operation
E=1; // send H-L pulse at E pin
ms_delay(5);
E=0;
}
void lcd_data (unsigned char datax) // function to write data at lcd
port
{
ms_delay(20);
DATA=datax;
RS=1; // set RS=1 to write DATA
RW=0; // write operation
E=1; // send H-L pulse at E pin
ms_delay (5);
E=0;
}
VCC(5V)
R2
10 Kohm
C3
22 uF
D6
LED
LCD
1234567891
0
1
1
1
2
1
3
1
4
1
5
1
6
C2
33 pF
VCC(5V)
8051
MCU
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
P10
P11
P12
P13
P14
P15
P16
P17
RST
P30
P31
P32
P33
P34
P35
P36
P37
XTAL1
XTAL2
GND P20
P21
P22
P23
P24
P25
P26
P27
PSEN
ALE
EA
P07
P06
P05
P04
P03
P02
P01
P00
VCC
LM7805
123
I
N
G
N
D
O
U
T
T1
TRANSFORMER
1 3
2 4
IN4007
DIODE
IN4007
DIODE
SW1
220 V A/C
VCC(5V)
C6
1000 uF
C1
33 pF
IN4007
DIODE
Y2
11.0592 MHz
IN4007
DIODE
470 ohm
RESISTOR
VCC(5V)
8 Shift display left
9 Display off, cursor off
A Display off, cursor on
C Display on, cursor off
E Display on, cursor blinking
F Display on, cursor blinking
10 Shift cursor position to left
14 Shift cursor position to right
18 Shift the entire display to left
1C Shift the entire display to right
80 Force cursor to the beginning of 1
st
line
C0 Force cursor to the beginning of 2nd line
38 2 line and 57 matrix



45
void lcd_init() // function to initialize the LCD at
power on time
{
lcd_cmd(0x38); // 2x16 display select
ms_delay(3);
lcd_cmd (0x38); // 2x16 display select
ms_delay(3);
lcd_cmd (0x0c); // display on cursor off command
ms_delay(3);
lcd_cmd (0x06); // automatic cursor movement to
right
ms_delay(3);
lcd_cmd (0x01); // lcd clear command
ms_delay(3);
lcd_cmd (0x80); // first row first coloumn select
command
ms_delay(3);
}

void lcd_puts(unsigned char *str) // function to display string to lcd
{
while(*str!='\0')
{
lcd_data(*str);
str++;
}
}

void main()
{
lcd_init();
while(1)
{
lcd_cmd(0x80);
lcd_puts("Hello");
}

Number Display:

void main()
{
unsigned char start_loc=0x80,count;
lcd_init();
while(1)
{
for(count=0;count<10;count++) // loop to count from 0 to 9
{
lcd_cmd(start_loc); // set start location as 0x80
lcd_data(count+48); // add 48 to the count to
convert it to ASCII value



46
secdelay(1); // wait for one second
start_loc++; // increment start location
if(start_loc==0x90) // if the cursor is at 17th
location
start_loc=0xc0; // change the location to 0xc0
(2nd row 1st column)
if(start_loc==0xd0) // if the cursor is at 33rd
location then
{
lcd_cmd(0x01); //clear lcd and
start_loc=0x80; // change the location to 0x80
(1st row 1st column)
}
}
} }

A-Z Display:

void main()

{
unsigned char start_loc=0x80,count,ch;
lcd_init();
while(1)
{
ch=65; // ASCII value of 'A' is 65 (u can
also write ch='A')
for(count=0;count<26;count++) // loop to count from 0 to 26 as
A-Z total 26 character
{
lcd_cmd(start_loc); // set start location as 0x80
lcd_data(ch+count); // add to the count to convert
it to ASCII value
secdelay(1); // wait for one second
start_loc++; // increment start location
if(start_loc==0x90) // if the cursior is at 17th
location
start_loc=0xc0; // change the location to 0xc0
(2nd row 1st column)
if(start_loc==0xd0) // if the cursor is at 33rd
location then
{
lcd_cmd(0x01); //clear lcd and
start_loc=0x80; }}}}
// change the location to 0x80 (1st row 1st column)
}
}
}





47

In this circuit the MCU is connected to transistor through optocoupler, means there is
an optical connected between microcontroller and transistor not any physical
connection, so the spike generated by the transistor wouldn't be reach controller, so by
using this circuit we've isolated the controller from Power transistor. The PNP Power
transistor used here is BC369.

11. Power Transistor (BC 369)
High current gain
High collector current
Low collector-emitter saturation voltage
Complementary type: BC 368 (NPN)

Terminal 1: Emitter
Terminal 2: Collector
Terminal3: Base
12. RELAY INTERFACING:
Relay is an electrically operated switch. Current flowing through the coil of the relay
creates a magnetic field which attracts a lever and changes the switch contacts. The
coil current can be on or off so relays have two switch positions and most have double
throw (changeover) switch contacts as shown in the diagram.




48
The relay's switch connections are usually labelled COM, NC and NO:
COM = Common, always connect to the moving part of the switch.
NC = Normally Closed, COM is connected to this when the relay coil is off.
NO = Normally Open, COM is connected to this when the relay coil is on.
Relays allow one circuit to switch a second circuit which can be completely
separate from the first. For example a low voltage battery circuit can use a relay to
switch a 230V AC mains circuit. There is no electrical connection inside the relay
between the two circuits; the link is magnetic and mechanical.

The coil of a relay passes a relatively large current, typically 30mA for a 12V relay,
but it can be as much as 100mA for relays designed to operate from lower voltages.
Most ICs (chips) cannot provide this current and a transistor is usually used to amplify
the small IC current to the larger value required for the relay coil. The maximum
output current for the popular 555 timer IC is 200mA so these devices can supply
relay coils directly without amplification.
Pole and Throw
Since relays are switches, the terminology applied to switches is also applied to
relays. A relay will switch one or more poles, each of whose contacts can be thrown
by energizing the coil in one of three ways:
Normally-open (NO) contacts connect the circuit when the relay is activated;
the circuit is disconnected when the relay is inactive. It is also called a Form
A contact or "make" contact.
Normally-closed (NC) contacts disconnect the circuit when the relay is
activated; the circuit is connected when the relay is inactive. It is also called a
Form B contact or "break" contact.
Change-over (CO), or double-throw (DT), contacts control two circuits: one
normally-open contact and one normally-closed contact with a common
terminal. It is also called a Form C contact or transfer contact ("break



49
before make"). If this type of contact utilizes make before break
functionality, then it is called a Form D contact.
The following designations are commonly encountered:
SPST Single Pole Single Throw. These have two terminals which can be
connected or disconnected. Including two for the coil, such a relay has four
terminals in total. It is ambiguous whether the pole is normally open or
normally closed. The terminology "SPNO" and "SPNC" is sometimes used to
resolve the ambiguity.

SPDT Single Pole Double Throw. A common terminal connects to either of
two others. Including two for the coil, such a relay has five terminals in total.
DPST Double Pole Single Throw. These have two pairs of terminals.
Equivalent to two SPST switches or relays actuated by a single coil. Including
two for the coil, such a relay has six terminals in total. The poles may be Form
A or Form B (or one of each).
DPDT Double Pole Double Throw. These have two rows of change-over
terminals. Equivalent to two SPDT switches or relays actuated by a single coil.
Such a relay has eight terminals, including the coil.
The "S" or "D" may be replaced with a number, indicating multiple switches
connected to a single actuator. For example 4PDT indicates a four pole double throw
relay (with 14 terminals)
Choosing a relay
You need to consider several features when choosing a relay:
1. Physical size and pin arrangement
If you are choosing a relay for an existing PCB you will need to ensure that its
dimensions and pin arrangement are suitable. You should find this information
in the supplier's catalogue.
2. Coil voltage



50
The relay's coil voltage rating and resistance must suit the circuit powering the
relay coil. Many relays have a coil rated for a 12V supply but 5V and 24V
relays are also readily available. Some relays operate perfectly well with a
supply voltage which is a little lower than their rated value.
3. Coil resistance
The circuit must be able to supply the current required by the relay coil. You
can use Ohm's law to calculate the current:
Relay coil current =
supply voltage
coil resistance
For example: A 12V supply relay with a coil resistance of 400 passes a
current of 30mA. This is OK for a 555 timer IC (maximum output current
200mA), but it is too much for most ICs and they will require a transistor to
amplify the current.
4. Switch ratings (voltage and current)
The relay's switch contacts must be suitable for the circuit they are to control.
You will need to check the voltage and current ratings. Note that the voltage
rating is usually higher for AC, for example: "5A at 24V DC or 125V AC".
5. Switch contact arrangement (SPDT, DPDT etc)
Most relays are SPDT or DPDT which are often described as "single pole
changeover" (SPCO) or "double pole changeover" (DPCO).
Protection diodes for relays
Relay coils produce brief high voltage 'spikes' when they are switched off and this can
destroy transistors and ICs in the circuit. To prevent damage you must connect a
protection diode across the relay coil.
Current flowing through a relay coil creates a magnetic field which collapses
suddenly when the current is switched off. The sudden collapse of the magnetic field
induces a brief high voltage across the relay coil which is very likely to damage
transistors and ICs. The protection diode allows the induced voltage to drive a brief
current through the coil (and diode) so the magnetic field dies away quickly rather
than instantly. This prevents the induced voltage becoming high enough to cause
damage to transistors and ICs.




51
Relay and transistor comparison as switch
Like relays, transistors can be used as an electrically operated switch. For switching
small DC currents (< 1A) at low voltage they are usually a better choice than a relay.
However, transistors cannot switch AC (such as mains electricity) and in simple
circuits they are not usually a good choice for switching large currents (> 5A). In
these cases a relay will be needed, but note that a low power transistor may still be
needed to switch the current for the relay's coil. The main advantages and
disadvantages of relays are listed below:
12.1 Advantages of relays:
Relays can switch AC and DC, transistors can only switch DC.
Relays can switch higher voltages than standard transistors.
Relays are often a better choice for switching large currents (> 5A).
Relays can switch many contacts at once.
12.2 Disadvantages of relays:
Relays are bulkier than transistors for switching small currents.
Relays cannot switch rapidly (except reed relays), transistors can switch many
times per second.
Relays use more power due to the current flowing through their coil.
Relays require more current than many ICs can provide, so a low power
transistor may be needed to switch the current for the relay's coil.
12.3 Relay Driver:
For its interfacing with microcontrollers or other low current digital ICs, a power or
current amplifier circuit is required, known as relay driver circuits. Mainly two such
driver circuits i.e. ULN2003 and transistor/opto-couplers are often used.
12.4 Interfacing with microcontroller:




52
Here a circuit of ULN2003 with relay is interfaced with microcontroller, is shown.
whenever a high logic from controller is fed to ULN2003 then against this input the
ULN2003 IC gives a GND output to relay coil, since other terminal of the coil is
given with +12V so the coil of relay gets magnetised thus relay gets ON and vice-
versa.
Relay ON/OFF:
#include<reg51.h>
#include<delay.h>
sbit dev=P0^6; // define the 220v device using sbit as dev
#define ON 1
#define OFF 0
void main()
{
while(1)
{
dev=ON;
secdelay(5);
dev=OFF;
secdelay(3);
}
}



















53
BIBLIOGRAPHY:
[1] www.google.com
[2] Muhammad Ali Mazidis .

You might also like