Smart Card Based Access System: A Major Project Report On

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 40

A MAJOR PROJECT REPORT ON

Smart Card Based


Access System
ABSTRACT

Smart cards are secure tokens that can provide security services to a wide range of applications.
Along with other technology advances, smart card technology has changed dramatically as well.
However, its communication standards, largely unchanged, do not match with those of
mainstream computing, which has limited its success in the Internet age.

In our daily life we are seeing gates. We are going to change them in to automatic gates based on
embedded technology.

So to lock the normal gates we have to lock it with a lock where security risk is very much high,
but instead of that as the technology is growing we can make use of smart card which is nothing
but like a memory card in which we are going to store the details of particular person and access
details for opening or closing the gates.

The main objective of this project is to allowing or denying the access using smart card. Smart
card must be swapped in front of reader & then he needs to enter his password using keypad.
Being our project a prototype, we consider here 4 identity cards each having barcode type (Black
& White Lines) strip on it with different combinations. IR sensors will detect the card and fed
this information to 8051 through LM324 op-amp. If card is valid the system asks for password.
On the verification of password access is granted, otherwise controller will not activate the relay
section & access is declined.

1
BLOCK DIAGRAM:

Project is divided in to 6 Sections


1. INFRARED BASED CARD READER

2. ANALOG TO DIGITAL CONVERTER

3. MICROCONTROLLER

4. LCD DETAIL
2
5. RELAY SECTION

6. DC MOTORS

CIRCUIT DIAGRAM:

3
Working:-

4
A Photodiode is a p-n junction or p-i-n structure. When an infrared photon of sufficient energy
strikes the diode, it excites an electron thereby creating a mobile electron and a positively
charged electron hole. If the absorption occurs in the junction's depletion region, or one diffusion
length away from it, these carriers are swept from the junction by the built-in field of the
depletion region, producing a photocurrent.
Analog to Digital conversion done by IC LM324. IC LM324
is a comparator IC that digitizes the analog signal from the sensor array. Since the output of
LM324 is TTL compatible it can be directly fed to the master microcontroller.
The AT89C51 is a low-power, high-performance CMOS 8-
bit microcomputer with 4Kbytes of Flash Programmable and Erasable Read Only Memory
(PEROM).The device is manufactured using Atmel’s high density nonvolatile memory
technology and is compatible with the industry standard MCS-51Ô instruction set and pin out.
The on-chip Flash allows the program memory to be reprogrammed in-system or by a
conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash
on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides a highly
flexible and cost effective solution to many embedded control applications. The AT89C51
provides the following standard features: 4Kbytes of Flash, 128 bytes of RAM, 32 I/O lines, two
16-bit timer/counters, five vector two-level interrupt architecture, a full duplex serial port, on-
chip oscillator and clock circuitry. In addition, the AT89C51 is designed with static logic for
operation down to zero frequency and supports two software selectable power saving modes. The
Idle Mode stops the CPU while allowing the RAM, timer /counters serial port and interrupt
system to continue functioning. The Power down Mode saves the RAM contents but freezes the
oscillator disabling all other chip functions until the next hardware reset. In the relay drive logic
we interface the microcontroller with the load. On this negative data is available. To interface the
negative data to control the relay we use two transistor circuits. Output from the microcontroller
is connected to the PNP transistor through 1 k ohm resistor and output of the PNP transistor is
connected to the base of the npn transistor through 1 k ohmresistor. Output of the npn transistor
is directly connected to relay driver coil. Relay is a electromagnetic switch when switch on by
the npn transistor then relay transfer the main supply to the receiver unit directly. A opto
coupler is installed in between microcontroller & relay to avoid effects of back emf from relay
section.

5
An opto-isolator integrated circuit. contains an infrared LED and silicon photodiode with an
integrated amplifier stage. In electronics, an opto-isolator (or optical isolator, optical coupling
device, opto coupler, photo coupler, or photo moss) is a device that uses a short optical
transmission path to transfer an electronic signal between elements of a circuit, typically a
transmitter and a receiver, while keeping them electrically isolated—since the electrical signal is
converted to a light beam, transferred, then converted back to an electrical signal, there is no
need for electrical connection between the source and destination circuits. Isolation between
input and output is rated at 7500 Volt peak for 1 second for a typical component. These are very
commonly used in robotics. DC motors can rotate in both directions depending upon the polarity
of current through the motor. These motors have free running torque and current ideally zero.
These motors have high speed which can be reduced with the help of gears and traded off for
torque. Speed Control of DC motors is done through Pulse Width Modulation techniques, i.e.
sending the current in intermittent bursts. PWM can be generated by 555 timer IC with adjusted
duty cycle. Varying current through the motor varies the torque Frequently, an 8051 program
must interact with the outside world using input and output devices that communicate directly
with a human being. One of the most common devices attached to an 8051 is an LCD display.
Some of the most common LCDs connected to the 8051 are 16x2 and 20x2 displays. This means
16 characters per line by 2 lines and 20 characters per line by 2 lines, respectively. Fortunately,
a very popular standard exists which allows us to communicate with the vast majority of LCDs
regardless of their manufacturer.

Section Details:-

1. INFRARED BASED CARD READER


6
Principle of operation of the I.R. LED and Phototransistor: -
A Photodiode is a p-n junction or p-i-n structure. When an infrared photon of sufficient energy
strikes the diode, it excites an electron thereby creating a mobile electron and a positively
charged electron hole. If the absorption occurs in the junction's depletion region, or one
diffusion length away from it, these carriers are swept from the junction by the built-in field
of the depletion region, producing a photocurrent. Photodiodes can be used under either zero
bias (photovoltaic mode) or reverse bias (photoconductive mode). Reverse bias induces only
little current (known as saturation or back current) along its direction. But a more important
effect of reverse bias is widening of the depletion layer therefore expanding the reaction volume
and strengthening the photocurrent when infrared falls on it. There is a limit on the distance
between I.R. L.E.D. and infrared sensor for the pair to operate in the desired manner. In our case
distance is about 5mm. Infra-Red emitter sends out IR pulses. Position calculation is done
through intensity of reflected light received by the detector. Ambient interference is negligible

POS IT IONING OF SENSORS:-


The resistance of the sensor decreases when IR (infrared) light falls on it. A good sensor will
have near zero resistance in presence of light and a very large resistance in absence of
light. Whether the sensors are Light Dependent Resistors, laser diode, Infrared Sensors,
Ultrasonic Sensors or anything else, the outputs of the sensor modules are fed to the Non-
inverting input of a comparator. The reference voltage of the comparator isfed to the inverting
input of the comparator by a trim pot or a tuning device connected between the supply lines.
LM339 is a comparator IC that digitizes the analog signal from the sensor array. Since the output
of LM339 is TTL compatible it can be directly fed to the master microcontroller.

7
The generalized connection diagram of Sensor Interfacing with microcontroller is shown
below:-

CONNECTING INFRARED MODULE WITH MICROCONTROLLER

When the sensor/emitter pair is on shining surface sensor is on i.e. in low impedance mode
which one can easily view as L.E.D. corresponding to that sensor doesn’t glow. The
output of the op-amp is HIGH SIGNAL and this HIGH S IGNAL is given to the microcontroller
8
and when the sensor is on normal non-reflecting surface it’s off i.e. In HIGH
IMPEDANCE state which one can easily view as L.E.D. corresponding to that sensor glows up
and LOW SIG NAL is given to the microcontroller.

Infra-Red Sensor Array

9
ANALOG TO DIGITAL CONVERTER:-

It is clear that the output of the potential divider is an analog voltage. But
Microcontroller does not accept the analog voltage. So we need to convert the analog voltage
to digital before we feed it to the microcontroller. For this conversion we can use

1. Comparators

2. ADCs

10
LM324 COMPARATOR:-
PINDIAGRAM OF LM324:-

This device consists of four independent precision voltage comparators with an offset voltage
specifications as low as 2mV. This comparator is designed to specifically operate from a single
power supply over a wide range of voltages. Operation from split power supplies is also possible.
This comparator also has a unique characteristic which is that the input common-mode
voltage range includes ground even though operated from a single power supply voltage.

FUNCTION OF THE COMPARATOR:-

11
ELECTRICAL CHARAC TERISTICS

12
Symbol Conditions Value Unit
Vio 0 mV
Avd RL = 2k 100 V/mV
Icc No load, per amplifier 350 A
Vicm -15 to +13.5 V
VOH RL = 2k (VCC+=15V) +13.5 V
VOL RL = 10k 5 mV
Ios Vo = +2V, VCC = +15V +40 mA
GBP RL = 2k CL = 100pF 1.3 MHz
SR RL = 2k CL = 100pF 0.4 V/ s

MICROCONTROLLER 89s51.

89s51 microcontroller is a main IC of this project. To drive the lcd, to check the balance amount
and balance comparison all this activity is done in the this IC. Here we use microcontroller for
this purpose. We wrote a program for this IC. Program is to be written in the ASM codes and
then this code is converted into hex code with the help of the assembler. In this project we use
8051 kiel software to assemble the asm codes into hex code. Once the code is converted into hex
code then we tranfer this code in the blank IC with the help of program kit connected with the
computer. After transfer the hex code the IC is ready for the project.

89S51

The world of Micro controllers

What is the primary difference between a microprocessor and a micro controller? Unlike the
microprocessor, the micro controller can be considered to be a true “Computer on a chip”.

In addition to the various features like the ALU, PC, SP and registers found on a microprocessor,
the micro controller also incorporates features like the ROM, RAM, Ports, timers, clock circuits,
counters, reset functions etc.

While the microprocessor is more a general-purpose device, used for read, write and calculations
on data, the micro controller, in addition to the above functions also controls the environment.

We have used a whole lot of technical terms already! Don’t get worried about the meanings at
this point. We shall understand these terms as we proceed further

For now just be aware of the fact, that all these terms literally mean what they say.

Bits and Bytes

Before starting on the 8051, here is a quick run through on the bits and bytes. The basic unit of
data for a computer is a bit. Four bits make a nibble. Eight bits or two nibbles make a byte.
Sixteen bits or four nibbles or two bytes make a word.

1024 bytes make a kilobyte or 1KB, and 1024 KB make a Mega Byte or 1MB.

Thus when we talk of an 8-bit register, we mean the register is capable of holding data of 8 bits
only.

The 8051

The 8051 developed and launched in the early 80`s, is one of the most popular micro controller
in use today. It has a reasonably large amount of built in ROM and RAM. In addition it has the
ability to access external memory.

The generic term `8x51` is used to define the device. The value of x defining the kind of ROM,
i.e. x=0, indicates none, x=3, indicates mask ROM, x=7, indicates EPROM and x=9 indicates
EEPROM or Flash.

A note on ROM

The early 8051, namely the 8031 was designed without any ROM. This device could run only
with external memory connected to it. Subsequent developments lead to the development of the
PROM or the programmable ROM. This type had the disadvantage of being highly unreliable.

The next in line, was the EPROM or Erasable Programmable ROM. These devices used
ultraviolet light erasable memory cells. Thus a program could be loaded, tested and erased using
ultra violet rays. A new program could then be loaded again.

An improved EPROM was the EEPROM or the electrically erasable PROM. This does not
require ultra violet rays, and memory can be cleared using circuits within the chip itself.

Finally there is the FLASH, which is an improvement over the EEPROM. While the terms
EEPROM and flash are sometimes used interchangeably, the difference lies in the fact that flash
erases the complete memory at one stroke, and not act on the individual cells. This results in
reducing the time for erasure.

Understanding the basic features of the 8051 core

Let’s now move on to a practical example. We shall work on a simple practical application and
using the example as a base, shall explore the various features of the 8051 microcontroller.

Consider an electric circuit as follows,

The positive side (+ve) of the battery is connected to one side of a switch. The other side of the
switch is connected to a bulb or LED (Light Emitting Diode). The bulb is then connected to a
resistor, and the other end of the resistor is connected to the negative (-ve) side of the battery.

When the switch is closed or ‘switched on’ the bulb glows. When the switch is open or ‘switched
off’ the bulb goes off

If you are instructed to put the switch on and off every 30 seconds, how would you do it?
Obviously you would keep looking at your watch and every time the second hand crosses 30
seconds you would keep turning the switch on and off.

Imagine if you had to do this action consistently for a full day. Do you think you would be able
to do it? Now if you had to do this for a month, a year??
No way, you would say!

The next step would be, then to make it automatic. This is where we use the Microcontroller.

But if the action has to take place every 30 seconds, how will the microcontroller keep track of
time?

Execution time

Look at the following instruction,

clr p1.0

This is an assembly language instruction. It means we are instructing the microcontroller to put a
value of ‘zero’ in bit zero of port one. This instruction is equivalent to telling the microcontroller
to switch on the bulb. The instruction then to instruct the microcontroller to switch off the bulb
is,

Setb p1.0

This instructs the microcontroller to put a value of ‘one’ in bit zero of port one.

Don’t worry about what bit zero and port one means. We shall learn it in more detail as we
proceed.

There are a set of well defined instructions, which are used while communicating with the
microcontroller. Each of these instructions requires a standard number of cycles to execute. The
cycle could be one or more in number.

How is this time then calculated?

The speed with which a microcontroller executes instructions is determined by what is known as
the crystal speed. A crystal is a component connected externally to the microcontroller. The
crystal has different values, and some of the used values are 6MHZ, 10MHZ, and 11.059 MHz
etc.

Thus a 10MHZ crystal would pulse at the rate of 10,000,000 times per second.

The time is calculated using the formula

No of cycles per second = Crystal frequency in HZ / 12.

For a 10MHZ crystal the number of cycles would be,

10,000,000/12=833333.33333 cycles.
This means that in one second, the microcontroller would execute 833333.33333 cycles.

Therefore for one cycle, what would be the time? Try it out.

The instruction clr p1.0 would use one cycle to execute. Similarly, the instruction setb p1.0 also
uses one cycle.

So go ahead and calculate what would be the number of cycles required to be executed to get a
time of 30 seconds!

Getting back to our bulb example, all we would need to do is to instruct the microcontroller to
carry out some instructions equivalent to a period of 30 seconds, like counting from zero
upwards, then switch on the bulb, carry out instructions equivalent to 30 seconds and switch off
the bulb.

Just put the whole thing in a loop, and you have a never ending on-off sequence.

Simple isn’t it?

Let us now have a look at the features of the 8051 core, keeping the above example as a
reference,

1. 8-bit CPU.( Consisting of the ‘A’ and ‘B’ registers)

Most of the transactions within the microcontroller are carried out through the ‘A’ register, also
known as the Accumulator. In addition all arithmetic functions are carried out generally in the
‘A’ register. There is another register known as the ‘B’ register, which is used exclusively for
multiplication and division.

Thus an 8-bit notation would indicate that the maximum value that can be input into these
registers is ‘11111111’. Puzzled?

The value is not decimal 111, 11,111! It represents a binary number, having an equivalent
value of ‘FF’ in Hexadecimal and a value of 255 in decimal.

We shall read in more detail on the different numbering systems namely the Binary and
Hexadecimal system in our next module.
2. 4K on-chip ROM

Once you have written out the instructions for the microcontroller, where do you put
these instructions?

Obviously you would like these instructions to be safe, and not get deleted or changed
during execution. Hence you would load it into the ‘ROM’

The size of the program you write is bound to vary depending on the application, and the
number of lines. The 8051 microcontroller gives you space to load up to 4K of program
size into the internal ROM.

4K, that’s all? Well just wait. You would be surprised at the amount of stuff you can load
in this 4K of space.

Of course you could always extend the space by connecting to 64K of external ROM if
required.

3. 128 bytes on-chip RAM

This is the space provided for executing the program in terms of moving data, storing
data etc.

4. 32 I/O lines. (Four- 8 bit ports, labeled P0, P1, P2, P3)

In our bulb example, we used the notation p1.0. This means bit zero of port one. One bit
controls one bulb.
Thus port one would have 8 bits. There are a total of four ports named p0, p1, p2, p3,
giving a total of 32 lines. These lines can be used both as input or output.

5. Two 16 bit timers / counters.

A microcontroller normally executes one instruction at a time. However certain


applications would require that some event has to be tracked independent of the main
program.

The manufacturers have provided a solution, by providing two timers. These timers
execute in the background independent of the main program. Once the required time has
been reached, (remember the time calculations described above?), they can trigger a
branch in the main program.

These timers can also be used as counters, so that they can count the number of events,
and on reaching the required count, can cause a branch in the main program.

6. Full Duplex serial data receiver / transmitter.

The 8051 microcontroller is capable of communicating with external devices like the PC
etc. Here data is sent in the form of bytes, at predefined speeds, also known as baud rates.

The transmission is serial, in the sense, one bit at a time

7. 5- interrupt sources with two priority levels (Two external and three internal)

During the discussion on the timers, we had indicated that the timers can trigger a branch
in the main program. However, what would we do in case we would like the
microcontroller to take the branch, and then return back to the main program, without
having to constantly check whether the required time / count has been reached?

This is where the interrupts come into play. These can be set to either the timers, or to
some external events. Whenever the background program has reached the required
criteria in terms of time or count or an external event, the branch is taken, and on
completion of the branch, the control returns to the main program.

Priority levels indicate which interrupt is more important, and needs to be executed first
in case two interrupts occur at the same time.

8. On-chip clock oscillator.

This represents the oscillator circuits within the microcontroller. Thus the hardware is
reduced to just simply connecting an external crystal, to achieve the required pulsing rate.

LCD SECTION

Frequently, an 8051 program must interact with the outside world using input and output devices
that communicate directly with a human being. One of the most common devices attached to an
8051 is an LCD display. Some of the most common LCDs connected to the 8051 are 16x2 and
20x2 displays. This means 16 characters per line by 2 lines and 20 characters per line by 2 lines,
respectively.

Fortunately, a very popular standard exists which allows us to communicate with the vast
majority of LCDs regardless of their manufacturer. The standard is referred to as HD44780U,
which refers to the controller chip which receives data from an external source (in this case, the
8051) and communicates directly with the LCD.

44780 BACKGROUND

The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the data bus. The
user may select whether the LCD is to operate with a 4-bit data bus or an 8-bit data bus. If a 4-bit
data bus is used, the LCD will require a total of 7 data lines (3 control lines plus the 4 lines for
the data bus). If an 8-bit data bus is used, the LCD will require a total of 11 data lines (3 control
lines plus the 8 lines for the data bus).

The three control lines are referred to as EN, RS, and RW.
The EN line is called "Enable." This control line is used to tell the LCD that you are sending it
data. To send data to the LCD, your program should first set this line high (1) and then set the
other two control lines and/or put data on the data bus. When the other lines are completely
ready, bring EN low (0) again. The 1-0 transition tells the 44780 to take the data currently found
on the other control lines and on the data bus and to treat it as a command.

The RS line is the "Register Select" line. When RS is low (0), the data is to be treated as a
command or special instruction (such as clear screen, position cursor, etc.). When RS is high (1),
the data being sent is text data which should be displayed on the screen. For example, to display
the letter "T" on the screen you would set RS high.

The RW line is the "Read/Write" control line. When RW is low (0), the information on the data
bus is being written to the LCD. When RW is high (1), the program is effectively querying (or
reading) the LCD. Only one instruction ("Get LCD status") is a read command. All others are
write commands--so RW will almost always be low.

Finally, the data bus consists of 4 or 8 lines (depending on the mode of operation selected by the
user). In the case of an 8-bit data bus, the lines are referred to as DB0, DB1, DB2, DB3, DB4,
DB5, DB6, and DB7.

AN EXAMPLE HARDWARE CONFIGURATION

As we've mentioned, the LCD requires either 8 or 11 I/O lines to communicate with. For the sake
of this tutorial, we are going to use an 8-bit data bus--so we'll be using 11 of the 8051's I/O pins
to interface with the LCD.

Let's draw a sample psuedo-schematic of how the LCD will be connected to the 8051.
As you can see, we've established a 1-to-1 relation between a pin on the 8051 and a line on the
44780 LCD. Thus as we write our assembly program to access the LCD, we are going to equate
constants to the 8051 ports so that we can refer to the lines by their 44780 name as opposed to
P0.1, P0.2, etc. Let's go ahead and write our initial equates:

DB0 EQU P1.0


DB1 EQU P1.1
DB2 EQU P1.2
DB3 EQU P1.3
DB4 EQU P1.4
DB5 EQU P1.5
DB6 EQU P1.6
DB7 EQU P1.7
EN EQU P3.7
RS EQU P3.6
RW EQU P3.5
DATA EQU P1
Having established the above equates, we may now refer to our I/O lines by their 44780 name.
For example, to set the RW line high (1), we can execute the following insutrction:
SETB RW
HANDLING THE EN CONTROL LINE

As we mentioned above, the EN line is used to tell the LCD that you are ready for it to execute
an instruction that you've prepared on the data bus and on the other control lines. Note that the
EN line must be raised/lowered before/after each instruction sent to the LCD regardless of
whether that instruction is read or write, text or instruction. In short, you must always manipulate
EN when communicating with the LCD. EN is the LCD's way of knowing that you are talking to
it. If you don't raise/lower EN, the LCD doesn't know you're talking to it on the other lines.

Thus, before we interact in any way with the LCD we will always bring the EN line high with
the following instruction:

SETB EN
And once we've finished setting up our instruction with the other control lines and data bus lines,
we'll always bring this line back low:
CLR EN
Programming Tip: The LCD interprets and executes our command at the instant the EN
line is brought low. If you never bring EN low, your instruction will never be executed.
Additionally, when you bring EN low and the LCD executes your instruction, it requires
a certain amount of time to execute the command. The time it requires to execute an
instruction depends on the instruction and the speed of the crystal which is attached to the
44780's oscillator input.

CHECKING THE BUSY STATUS OF THE LCD

As previously mentioned, it takes a certain amount of time for each instruction to be executed by
the LCD. The delay varies depending on the frequency of the crystal attached to the oscillator
input of the 44780 as well as the instruction which is being executed.

While it is possible to write code that waits for a specific amount of time to allow the LCD to
execute instructions, this method of "waiting" is not very flexible. If the crystal frequency is
changed, the software will need to be modified. Additionally, if the LCD itself is changed for
another LCD which, although 44780 compatible, requires more time to perform its operations,
the program will not work until it is properly modified.

A more robust method of programming is to use the "Get LCD Status" command to determine
whether the LCD is still busy executing the last instruction received.

The "Get LCD Status" command will return to us two tidbits of information; the information that
is useful to us right now is found in DB7. In summary, when we issue the "Get LCD Status"
command the LCD will immediately raise DB7 if it's still busy executing a command or lower
DB7 to indicate that the LCD is no longer occupied. Thus our program can query the LCD until
DB7 goes low, indicating the LCD is no longer busy. At that point we are free to continue and
send the next command.

Since we will use this code every time we send an instruction to the LCD, it is useful to make it a
subroutine. Let's write the code:

WAIT_LCD:
SETB EN ;Start LCD command
CLR RS ;It's a command
SETB RW ;It's a read command
MOV DATA,#0FFh ;Set all pins to FF initially
MOV A,DATA ;Read the return value
JB ACC.7,WAIT_LCD ;If bit 7 high, LCD still busy
CLR EN ;Finish the command
CLR RW ;Turn off RW for future commands
RET
Thus, our standard practice will be to send an instruction to the LCD and then call our
WAIT_LCD routine to wait until the instruction is completely executed by the LCD. This will
assure that our program gives the LCD the time it needs to execute instructions and also makes
our program compatible with any LCD, regardless of how fast or slow it is.
Programming Tip: The above routine does the job of waiting for the LCD, but were it to be
used in a real application a very definite improvement would need to be made: as written, if the
LCD never becomes "not busy" the program will effectively "hang," waiting for DB7 to go low.
If this never happens, the program will freeze. Of course, this should never happen and won't
happen when the hardware is working properly. But in a real application it would be wise to put
some kind of time limit on the delay--for example, a maximum of 256 attempts to wait for the
busy signal to go low. This would guarantee that even if the LCD hardware fails, the program
would not lock up.

INITIALIZING THE LCD

Before you may really use the LCD, you must initialize and configure it. This is accomplished by
sending a number of initialization instructions to the LCD.

The first instruction we send must tell the LCD whether we'll be communicating with it with an
8-bit or 4-bit data bus. We also select a 5x8 dot character font. These two options are selected by
sending the command 38h to the LCD as a command. As you will recall from the last section, we
mentioned that the RS line must be low if we are sending a command to the LCD. Thus, to send
this 38h command to the LCD we must execute the following 8051 instructions:

SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD

Programming Tip: The LCD command 38h is really the sum of a number of option bits.
The instruction itself is the instruction 20h ("Function set"). However, to this we add the
values 10h to indicate an 8-bit data bus plus 08h to indicate that the display is a two-line
display.

We've now sent the first byte of the initialization sequence. The second byte of the initialization
sequence is the instruction 0Eh. Thus we must repeat the initialization code from above, but now
with the instruction. Thus the next code segment is:
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD

Programming Tip: The command 0Eh is really the instruction 08h plus 04h to turn the
LCD on. To that an additional 02h is added in order to turn the cursor on.
The last byte we need to send is used to configure additional operational parameters of the LCD.
We must send the value 06h.
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
Programming Tip: The command 06h is really the instruction 04h plus 02h to configure
the LCD such that every time we send it a character, the cursor position automatically
moves to the right.

So, in all, our initialization code is as follows:

INIT_LCD:
SETB EN
CLR RS
MOV DATA,#38h
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#0Eh
CLR EN
LCALL WAIT_LCD
SETB EN
CLR RS
MOV DATA,#06h
CLR EN
LCALL WAIT_LCD
RET

Having executed this code the LCD will be fully initialized and ready for us to send display data
to it.

CLEARING THE DISPLAY

When the LCD is first initialized, the screen should automatically be cleared by the 44780
controller. However, it's always a good idea to do things yourself so that you can be completely
sure that the display is the way you want it. Thus, it's not a bad idea to clear the screen as the
very first opreation after the LCD has been initialiezd.

An LCD command exists to accomplish this function. Not suprisingly, it is the command 01h.
Since clearing the screen is a function we very likely will wish to call more than once, it's a good
idea to make it a subroutine:

CLEAR_LCD:
SETB EN
CLR RS
MOV DATA,#01h
CLR EN
LCALL WAIT_LCD
RET

How that we've written a "Clear Screen" routine, we may clear the LCD at any time by simply
executing an LCALL CLEAR_LCD.
Programming Tip: Executing the "Clear Screen" instruction on the LCD also positions
the cursor in the upper left-hand corner as we would expect.

WRITING TEXT TO THE LCD

Now we get to the real meat of what we're trying to do: All this effort is really so we can display
text on the LCD. Really, we're pretty much done.

Once again, writing text to the LCD is something we'll almost certainly want to do over and
over--so let's make it a subroutine.

WRITE_TEXT:
SETB EN
SETB RS
MOV DATA,A
CLR EN
LCALL WAIT_LCD
RET

The WRITE_TEXT routine that we just wrote will send the character in the accumulator to the
LCD which will, in turn, display it. Thus to display text on the LCD all we need to do is load the
accumulator with the byte to display and make a call to this routine. Pretty easy, huh?

A "HELLO WORLD" PROGRAM

Now that we have all the component subroutines written, writing the classic "Hello World"
program--which displays the text "Hello World" on the LCD is a relatively trivial matter.
Consider:

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#' '
LCALL WRITE_TEXT
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT

The above "Hello World" program should, when executed, initialize the LCD, clear the LCD
screen, and display "Hello World" in the upper left-hand corner of the display.

CURSOR POSITIONING

The above "Hello World" program is simplistic in the sense that it prints its text in the upper left-
hand corner of the screen. However, what if we wanted to display the word "Hello" in the upper
left-hand corner but wanted to display the word "World" on the second line at the tenth
character? This sounds simple--and actually, it is simple. However, it requires a little more
understanding of the design of the LCD.
The 44780 contains a certain amount of memory which is assigned to the display. All the text we
write to the 44780 is stored in this memory, and the 44780 subsequently reads this memory to
display the text on the LCD itself. This memory can be represented with the following "memory
map":

Thus, the first character in the upper left-hand corner is at address 00h. The following character
position (character #2 on the first line) is address 01h, etc. This continues until we reach the 16th
character of the first line which is at address 0Fh.

However, the first character of line 2, as shown in the memory map, is at address 40h. This
means if we write a character to the last position of the first line and then write a second
character, the second character will not appear on the second line. That is because the second
character will effectively be written to address 10h--but the second line begins at address 40h.

Thus we need to send a command to the LCD that tells it to position the cursor on the second
line. The "Set Cursor Position" instruction is 80h. To this we must add the address of the location
where we wish to position the cursor. In our example, we said we wanted to display "World" on
the second line on the tenth character position.

Referring again to the memory map, we see that the tenth character position of the second line is
address 4Ah. Thus, before writing the word "World" to the LCD, we must send a "Set Cursor
Position" instruction--the value of this command will be 80h (the instruction code to position the
cursor) plus the address 4Ah. 80h + 4Ah = C4h. Thus sending the command C4h to the LCD will
position the cursor on the second line at the tenth character position:

SETB EN
CLR RS
MOV DATA,#0C4h
CLR EN
LCALL WAIT_LCD
The above code will position the cursor on line 2, character 10. To display "Hello" in the upper
left-hand corner with the word "World" on the second line at character position 10 just requires
us to insert the above code into our existing "Hello World" program. This results in the
following:

LCALL INIT_LCD
LCALL CLEAR_LCD
MOV A,#'H'
LCALL WRITE_TEXT
MOV A,#'E'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
SETB EN
CLR RS
MOV DATA,#0C4h
CLR EN
LCALL WAIT_LCD
MOV A,#'W'
LCALL WRITE_TEXT
MOV A,#'O'
LCALL WRITE_TEXT
MOV A,#'R'
LCALL WRITE_TEXT
MOV A,#'L'
LCALL WRITE_TEXT
MOV A,#'D'
LCALL WRITE_TEXT

PIN WISE DETAIL OF LCD

1. Vss GROUND

2. Vcc +5VOLT SUPPLY

3 Vee POWER SUPPLY TO CONTROL CONTRAST

4. RS RS = 0 TO SELECT COMMAND REGISTER


RS = 1 TO SELECT DATA REGISTER

5. R/W R/W = 0 FOR WRITE


R/W = 1 FOR READ

6 E ENABLE

7 DB0

8 DB1

9. DB2

10. DB3

11. DB4

12. DB5

13. DB6

14. DB7

15 ,16 FOR BACK LIGHT DISPLAY


RELAY SECTION
RELAY DRIVER LOGIC.
In the relay drive logic we interface the micrcontroller with the load . If the balance is shown on
the lcd then microcontroller gives a output from the output on any pre decided pin. On this
negative data is available. To interface the negative data to control the relay we use two
transistor circuit. Output from the microcontroller is connected to the PNP transistor through 1 k
ohm resisitor and output of the PNP transistor is connected to the base of the npn transistor
through 1 k ohm resisitor. Output of the npn transistor is directly connected to relay driver coil.
Relay is a electromagnetic switch when switch on by the npn transitor then relay transfer the
main supply to the receiver unit directly.

OPTO-ISOLATOR
An opto-isolator integrated circuit., contains an infrared LED and silicon photodiode with an
integrated amplifier stage.In electronics, an opto-isolator (or optical isolator, optical coupling
device, optocoupler, photocoupler, or photoMOS) is a device that uses a short optical
transmission path to transfer an electronic signal between elements of a circuit, typically a
transmitter and a receiver, while keeping them electrically isolated—since the electrical signal is
converted to a light beam, transferred, then converted back to an electrical signal, there is no
need for electrical connection between the source and destination circuits. Isolation between
input and output is rated at 7500 Volt peak for 1 second for a typical component.
The opto-isolator is simply a package that contains both an infrared light-emitting diode (LED)
and a photodetector such as a photosensitive silicon diode, transistor Darlington pair, or silicon
controlled rectifier (SCR). The wave-length responses of the two devices are tailored to be as
identical as possible to permit the highest measure of coupling possible. Other circuitry—for
example an output amplifier—may be integrated into the package. An opto-isolator is usually
thought of as a single integrated package, but opto-isolation can also be achieved by using
separate devices.
Digital opto-isolators change the state of their output when the input state changes; analog
isolators produce an analog signal which reproduces the input.

Configurations
Schematic diagram of a very simple opto-isolator with an LED and phototransistor. The dashed
line represents the isolation barrier, over which there is no electrical contact.
A common implementation is a LED(i) and a phototransistor in a light-tight housing to exclude
ambient light and without common electrical connection, positioned so that light from the LED
will impinge on the photodetector. When an electrical signal is applied to the input of the opto-
isolator, its LED lights and illuminates the photodetector, producing a corresponding electrical
signal in the output circuit. Unlike a transformer the opto-isolator allows DC coupling and can
provide any desired degree of electrical isolation and protection from serious overvoltage
conditions in one circuit affecting the other. A higher transmission ratio can be obtained by using
a Darlington instead of a simple phototransistor, at the cost of reduced noise immunity and
higher delay.
With a photodiode as the detector, the output current is proportional to the intensity of incident
light supplied by the emitter. The diode can be used in a photovoltaic mode or a photoconductive
mode. In photovoltaic mode, the diode acts as a current source in parallel with a forward-biased
diode. The output current and voltage are dependent on the load impedance and light intensity. In
photoconductive mode, the diode is connected to a supply voltage, and the magnitude of the
current conducted is directly proportional to the intensity of light. This optocoupler type is
significantly faster than the photo transistor type, but the transmission ratio is very low; it is
common to integrate an output amplifier circuit into the same package.
The optical path may be air or a dielectric waveguide. When high noise immunity is required an
optical conductive shield can be integrated into the optical path. The transmitting and receiving
elements of an optical isolator may be contained within a single compact module, for mounting,
for example, on a circuit board; in this case, the module is often called an optoisolator or opto-
isolator. The photosensor may be a photocell, phototransistor, or an optically triggered SCR or
TRIAC. This device may in turn operate a power relay or contactor.
THE RELAY
A relay is an electromagnetic switch. In other words it is activated when a current is applied to it.
Normally a relay is used in a circuit as a type of switch (as you will see below). There are
different types of relays and they operate at different voltages. When you build your circuit you
need to consider the voltage that will trigger it.

RELAY SYMBOLS
The main part of a relay is the coil at the centre. A small current flowing through
the coil in the relay creates a magnetic field that pulls one switch contact against or away from
another. Putting it simply, when current is applied to the contacts at one side of the relay the coil
allows the contacts at the other side to work.Usually relays are used to turn on a second circuit.
The first circuit activates the relay which then ‘turns on’ the second circuit.
EXAMPLE CIRCUIT
This simple circuit activates the relay only when the LDR is dark (covered). This could be used
as part of an automatic animal feeder. For instance, if the animal was fed at night the circuit
above would activate the relay. A second circuit, connected to the other side of the relay releases
food into a dish.

TRANSISTORS
A transistor is a semiconductor device used to amplify and switch electronic signals. It is made
of a solid piece of semiconductor material, with at least three terminals for connection to an
external circuit. A voltage or current applied to one pair of the transistor's terminals changes the
current flowing through another pair of terminals. Because the controlled (output) power can be
much more than the controlling (input) power, the transistor provides amplification of a signal.
Today, some transistors are packaged individually, but many more are found embedded in
integrated circuits.

The transistor is the fundamental building block of modern electronic devices, and is ubiquitous
in modern electronic systems. Following its release in the early 1950s the transistor
revolutionised the field of electronics, and paved the way for smaller and cheaper radios,
calculators, and computers, amongst other things.
TYPES OF TRANSISTORS
There are two types of standard transistors, NPN and PNP, with different circuit symbols. The
letters refer to the layers of semiconductor material used to make the transistor. Most transistors
used today are NPN because this is the easiest type to make from silicon. This page is mostly
about NPN transistors and if you are new to electronics it is best to start by learning how to use
these first.

The leads are labeled as base (B), collector (C), emitter (E)

These terms refer to the internal operation of a transistor but they are not much help in
understanding how a transistor is used, so just treat them as labels!

A Darlington pair is two transistors connected together to give a very high current gain.
In addition to standard (bipolar junction) transistors, there are field-effect transistors which are
usually referred to as FETs. They have different circuit symbols and properties and they are not
(yet) covered by this page.

NPN vs PNP
1) NPN. If the base is at a higher voltage than the emitter, current flows from collector to emitter.
2) NPN. Small amount of current also flows from base to emitter.
3) NPN. Voltage at base controls amount of current flow through transistor (collector to emitter).

4) PNP. If the base is at a lower voltage than the emitter, current flows from emitter to collector.

5) PNP. Small amount of current also flows from emitter to base.

6) PNP. Voltage at base controls amount of current flow through transistor (emitter to collector).
7) Follow the arrow to see the direction of current flow.

SIMPLIFIED OPERATION

Simple circuit to show the labels of a bipolar transistor.

The essential usefulness of a transistor comes from its ability to use a small signal applied
between one pair of its terminals to control a much larger signal at another pair of terminals. This
property is called gain. A transistor can control its output in proportion to the input signal; that is,
it can act as an amplifier. Alternatively, the transistor can be used to turn current on or off in a
circuit as an electrically controlled switch, where the amount of current is determined by other
circuit elements.

The two types of transistors have slight differences in how they are used in a circuit. A bipolar
transistor has terminals labeled base, collector, and emitter. A small current at the base terminal
(that is, flowing from the base to the emitter) can control or switch a much larger current
between the collector and emitter terminals. For a field-effect transistor, the terminals are labeled
gate, source, and drain, and a voltage at the gate can control a current between source and drain.

The image to the right represents a typical bipolar transistor in a circuit. Charge will flow
between emitter and collector terminals depending on the current in the base. Since internally the
base and emitter connections behave like a semiconductor diode, a voltage drop develops
between base and emitter while the base current exists. The amount of this voltage depends on
the material the transistor is made from, and is referred to as VBE.

TRANSISTOR AS A SWITCH

BJT used as an electronic switch, in grounded-emitter configuration.

Transistors are commonly used as electronic switches, for both high power applications
including switched-mode power supplies and low power applications such as logic gates.
In a grounded-emitter transistor circuit, such as the light-switch circuit shown, as the base
voltage rises the base and collector current rise exponentially, and the collector voltage drops
because of the collector load resistor. The relevant equations:

VRC = ICE × RC, the voltage across the load (the lamp with resistance RC)
VRC + VCE = VCC, the supply voltage shown as 6V

If VCE could fall to 0 (perfect closed switch) then Ic could go no higher than VCC / RC, even with
higher base voltage and current. The transistor is then said to be saturated. Hence, values of input
voltage can be chosen such that the output is either completely off, or completely on. The
transistor is acting as a switch, and this type of operation is common in digital circuits where
only "on" and "off" values are relevant.

Transistor as an amplifier

Amplifier circuit, standard common-emitter configuration.

The common-emitter amplifier is designed so that a small change in voltage in (Vin) changes the
small current through the base of the transistor and the transistor's current amplification
combined with the properties of the circuit mean that small swings in Vin produce large changes
in Vout.

Various configurations of single transistor amplifier are possible, with some providing current
gain, some voltage gain, and some both.

From mobile phones to televisions, vast numbers of products include amplifiers for sound
reproduction, radio transmission, and signal processing. The first discrete transistor audio
amplifiers barely supplied a few hundred milliwatts, but power and audio fidelity gradually
increased as better transistors became available and amplifier architecture evolved.

Modern transistor audio amplifiers of up to a few hundred watts are common and relatively
inexpensive.
DC MOTOR: -

These are very commonly used Motors. DC motors can rotate in both directions depending
upon the polarity of current through the motor. These motors have free running torque and
current ideally zero. These motors have high speed which can be reduced with the help of gears
and traded off for torque. Speed Control of DC motors is done through Pulse Width Modulation
techniques, i.e. sending the current in intermittent bursts. PWM can be generated by 555 timers
IC with adjusted duty cycle. Varying current through the motor varies the torque.

PICTURE OF DC MOTOR USED

You might also like