You are on page 1of 71

CHAPHTER

1
INTRODUCTION

1.1INTRODUCTION
The project is about automatic switching on of lights.the number lights will switch on will
depend on the intensity of light.light sensor is provided is sense the light.light sensor is
connected to the Analog to digital converter which coverts the sensed analog signal to digital
signal.Analog to digital converter is connected to one of port of microcontroller .when micro
controller receives signal from the analog to digital converter it will sense intensity of light and it
will decide number of lights to be switched on and accordingly it gives signals to the relays
which inturn gives signal to lights and lights will glow accordingly.the maximum and minimum
limits of intensity of lights are mentioned in program dumped in the Micro controller chip.all the
lights will switch on when intensity sensed is less than the minimum limit and all lights will
switch off when the intensity is greater than the maximum limit.

1.2 OBJECTIVE OF STUDY AND SCOPE


In this project, automatic light on and offf control system is going to be produce by
using microcontroller. Thus, the main objectives for this project is to design and construct a
microcontroller based automatic light on and off control system.
There are some scopes which needed to achieve the objective for this project:
a)

To design a automatic light on and off control system by using microcontroller AT89C51

b)

To design the program (software) for the overall system according to the real world

c)

To integrate the hardware and software in order to simulate the functions of a basic

automatic light on and off control system

d)

To build a automatic light on and off model to simulate the actual system

1.3 LIST OF ELEMENTS


This project contains four parts. Those are:
1. Light sensor
2.

Microcontroller

3. ADC
4.

Relays

1.3.1.LDR-LIGHT SENSOR
It is a device which senses the light intensity of light. It generates analog
signl up on sensing light intensity . Light dependent resistors or LDRs are often used in
circuits where it is necessary to detect the presence orthe level of light. They can be described
by a variety of names from light dependent resistor, LDR, photoresistor ,or even photo cell
(photocell) or photoconductor. Although other devices such as photodiodes or phototransistor can also be used, LDRs are a particularly convenient electronics component to
use. They provide large change in resistance for changes in light level. In view of their low
cost,ease of manufacture, and ease of use LDRs have been used in a variety of different
applications.

At

one

time

LDRs

were used

in photographic light meters, and even

now they are stillused in a variety of applications where it is necessary to detect light levels.

Fig :1.1A light dependent resistor

1.3.2.MICROCONTROLLER
A microcontroller (abbreviated C, uC or MCU) is a single Chip computer on a
single
integrated circuit containing a processor,core, memory, and programmable peripherals
input/output This programmes memory in the form of NOR flash or OTP ROM is also often
included on chip, as well as a typically small amount of RAM. The micro controller program will
be given in the software description

1.3.3 ADC
Analog-to-digitals converters are among the most widely used devices for data acquisition.
Digital computers use binary(discrete) values, but in the physical world everything is analog
(continuous).Temperature, Pressure(wind or liquid),humidity, and velocity are a few examples
4

of physical quantities that we deal with every day. A physical is converted to electrical (voltage,
current) signals using device called a transducer. Transducers are referred to as sensors.
Sensors for temperature, pressure, light, many other natural quantities produce an output that
is voltage (or current).Therefore, we need an analog-to-digital convertor to translate the analog
signals to digital numbers so that the microcontroller can read and process them. An ADC has
n-bit resolution where n can be 8,10,12,16oreven 24 bits. The higher resolution ADC provides
a smaller step size,where step size is the smallest change that can be discerned by an ADC.this
is shown in table. .In addition to resolution ,convertion time is another major factor in judging
an ADC. Convertion time is defined as the time it takes the ADC to convert the analog input to a
digital(binary) number.The ADC CHIPS either parallel or serial.In parallel ADC ,we have only one
pin for data out..MAX1112 is an serial ADC chip.

1.3.4 RELAYS
Relays are used as interface High voltage circuits and Low voltage circuits.
The Relay circuit used in this project is takes low voltage signal from the
Microcontroller output pins and operates the switches of high voltage circuits
i.e., 230 volts circuit.

1.4Software Used
 Proteus 7 professional
 Keil uvision3
 Uc flash+
5

CHAPTER
2

OVER VIEW OF AUTOMATIC LIGHT CONTROL


SYSTEM

2.1 BLOCK DIAGRAM

Fig:2.1The block diagram of automatic light control depending on light intensisty using a micro
controller

2.2 BLOCK DIAGRAM EXPLANATION


The project entitled automatic light control depending on light intensisty using

Micro controller consist of the following components. Those are power supply,
microcontroller, crystal oscillator, ADC 0801,LDR ,light source for testing and relays etc.

2.2.1 Power Supply Unit Consists Of Following Units


 Rectifier unit
 Filter
 Regulator unit
i) Rectifier Unit

The Rectifier circuit is used to convert the AC voltage into its corresponding DC
voltage. There are Half-Wave, Full-Wave and bridge Rectifiers available for this specific
function. The most important and simple device used in Rectifier circuit is the diode. The
simple function of the diode is to conduct when forward biased and not to conduct in
reverse bias.
The Forward Bias is achieved by connecting the diodes positive with positive of
the battery and negative with batterys negative. The efficient circuit used is the full wave
Bridge rectifier circuit. The output voltage of the rectifier is in rippled form, the ripples
from the obtained DC voltage are removed using other circuits available. The circuit used
for removing the ripples is called Filter circuit.
ii) Filter
Capacitors are used as filter. The ripples from the DC voltage are removed and
pure DC voltage is obtained. And also these capacitors are used to reduce the harmonics
of the input voltage. The primary action performed by capacitor is charging and
discharging. It charges in positive half cycle of the AC voltage and it will discharge in
negative half cycle. So it allows only AC voltage and does not allow the DC voltage. This
iii) Regulator Unit
Regulator regulates the output voltage to be always constant. The output voltage is
maintained irrespective of the fluctuations in the input AC voltage. As and then the AC voltage
changes, the DC voltage also changes. Thus to avoid this Regulators are used.
8

2.2.2 LCD
Liquid crystal display (LCD) has material which combines the properties of both liquid
and crystals. They have a temperature range within which the molecules are almost as mobile as
they would be in a liquid, but are grouped together in an order form similar to a crystal
The liquid crystal display is used to visualize the status of the system.

2.2.3 Crystal Oscillator


A crystal oscillator is an electronic circuit that uses the mechanical resonance of a
vibrating crystal of piezoelectric material to create an electrical signal with a very precise
frequency.
In this project the frequency of the crystal oscillator is 11.059 MHz

2.2.4 Reset Circuit


This is used to reset all the interfacing components as well as microcontroller circuit
when there are any errors in the equipment.

2.2.5 Relay
A 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 they are double
throw (changeover) switches.
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.

2.2.6 LDR LIGHT SENSOR:


It is a device which sensee the light intensity of light. It generates analog signl up on sensing
light intensity . Light dependent resistors or LDRs are often used in
circuits where it is necessary to detect the presence orthe level of light. They can be described
by a variety ofnames from light dependent resistor, LDR, photoresistor,or even photo cell

(photocell) or photoconductor.Although other devices such as photodiodes or phototransistor can also be used, LDRs are a particularlyconvenient electronics component to
use. They provide large change in resistance for changes in light level.In view of their low
cost,ease of manufacture, and easeof use LDRs have been used in a variety of different
applications.

At

one time LDRs

were used

inphotographic light meters, and even

now they are stillused in a variety of applications where it is necessary todetect light levels.

Fig :2.2A light dependent resistor

10

CHAPTER
3
MICROCONTROLLER
AND
ANALOG TO DIGITAL CONVERTER(ADC)

11

3.1 INTRODUCTION
A micro-controller can be compared to a small stand alone computer; it is a very
powerful device, which is capable of executing a series of pre-programmed tasks and interacting
with other hardware devices. Being packed in a tiny integrated circuit (IC) whose size and weight
is usually negligible, it is becoming the perfect controller for robots or any machines requiring
some kind of intelligent automation. A single microcontroller can be sufficient to control a small
mobile robot, an automatic washer machine or a security system. Any microcontroller contains
a memory to store the program to be executed, and a number of input/output lines that can be
used to interact with other devices, like reading the state of a sensor or controlling a motor.
Nowadays, microcontrollers are so cheap and easily available that it is common to use
them instead of simple logic circuits like counters for the sole purpose of gaining some design
flexibility and saving some space. Some machines and robots will even rely on a multitude of
microcontrollers, each one dedicated to a certain task. Most recent microcontrollers are 'In
System Programmable', meaning that you can modify the program being executed, without
removing

the

microcontroller

from

3.2 FEATURES

Compatible with MCS-51 Products

4K Bytes of In-System Reprogrammable Flash Memory

Fully Static Operation: 0Hz to 24MHz

Three-level Program Memory Lock

128 x 8- bit Internal RAM

32 Programmable I/O Lines

Two 16-bit Timer/Counters

Six Interrupt Sources

Programmable Serial Channel

Low-power Idle and Power-down Mode

12

its

place.

3.3 PIN DESCRIPTION OF AT89C51


Examining the following figure, note that of the 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 Vcc, GND, XTAL1, XTAL2, RST, EA, ALE, and PSEN. Of these 8 pins, all 8051
derivatives use six of them. In other words, they must be connected in order for the system to
work.

Fig. 3.1 Pin Diagram of 89C51 Microcontroller

13

18: P1.0 to P1.7 (Port 1): Each of these pins can be used as either input or output according to
your needs. Port 1 is an 8-bit bi-directional I/O port with internal pull-ups on all pins. Port 1 pins
that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs.
As inputs, port 1 pins that are externally pulled low will source current because of the internal
pull-ups. Each pin of Port1 has an alternate function

Pin 1: T2 (P1.0) Cl-ock input of counter 0

Pin 2: T2EX (P1.1) - Timer/Counter 2 Reload / Capture / Direction Control

Pin 3: ECI (P1.2) - External Clock Input to the PCA

Pin 4: CEX0 (P1.3) - External I/O for PCA module 0

Pin 5: CEX1 (P1.4) - External I/O for PCA module 1

Pin 6: CEX2 (P1.5) - External I/O for PCA module 2

Pin 7: CEX3 (P1.6) - External I/O for PCA module 3

Pin 8: CEX4 (P1.7) - External I/O for PCA module 4


9: RST (Reset Signal): High logical state on this input halts the MCU and clears all the registers.
Bringing this pin back to logical state zero starts the program a new as if the power had just
been turned on. In another words, positive voltage impulse on this pin resets the MCU.
Depending on the device's purpose and environs, this pin is usually connected to the pushbutton, reset-upon-start circuit or a brown out reset circuit.
10-17: P3.0 to P3.7 (Port 3): As with Port 1, each of these pins can be
used as universal input or output. However, each pin of Port 3 has an
alternative function:

Pin 10:RxD(P3.0) - Serial input for asynchronous communication

Pin 11:TxD(P3.1) - Serial output for asynchronous communication

Pin 12:INT0( P 3.2) - Input for interrupt 0

Pin 13:INT1( P 3.3) - Input for interrupt 1

Pin 14:T0(P 3.4) - Clock input of counter 0

Pin 15:T1(P 3.5) - Clock input of counter 1

Pin 16:WR(P3.6) - Signal for writing to external RAM memory

Pin 17:RD(P3.7) - Signal for reading from external RAM memory

14

Table 3.1:Port 3 Alternate functions

18-19: XTAL2 and XTAL1 (Crystal input and output): Input and output of internal oscillator.
Quartz crystal controlling the frequency commonly connects to these pins.
20: VSS: Ground
21- 28: P2.0 to P2.7 (Port 2): If external memory is not present, pins of Port 2 act as universal
input/output. If external memory is connected, this is the location of the higher address byte,
i.e. addresses A8 A15. It is important to note that in cases when not all the 8 bits are used for
addressing the memory (i.e. memory is smaller than 64kB), the rest of the unused bits are not
available as input/output.
29: PSEN (Program Store Enable): MCU activates this bit (brings to low state) upon each reading
of byte instruction from program memory. If external ROM is used for storing the program,
PSEN is directly connected to its control pins.
30: ALE (Address Latch Enable): Before each reading of the external memory, MCU sends the
lower byte of the address register (addresses A0 A7) to port P0 and activates the output ALE.
External Chip (eg: 74HC373), memorizes the state of port P0 upon receiving a signal from ALE
pin, and uses it as part of the address for memory chip. During the second part of the MCU
cycle, signal on ALE is off, and port P0 is used as Data Bus. In this way, by adding only one
integrated circuit, data from port can be multiplexed and the port simultaneously used for
transferring both addresses and data.
31: EA (External Access Enable): Bringing this pin to the logical state zero designates the ports
P2 and P3 for transferring addresses regardless of the presence of the internal memory. This
means that even if there is a program loaded in the MCU it will not be executed, but the one

15

from the external ROM will be used instead. Conversely, bringing the pin to the high logical state
causes the controller to use both memories, first the internal, and then the external (if present).
32-39: P0.7 to P0.0 (Port 0): Similar to Port 2, pins of Port 0 can be used as universal
input/output, if external memory is not used. If external memory is used, P0 behaves as address
output (A0 A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin
is at low logical level.
40: VCC: Power +5V

3.4 ARCHITECTURE OF 89C51 MICROCONTROLLER


The architecture of the 8051 family of microcontrollers (8051 derivatives) is
referred to as the MCS-51 architecture (Micro Controller Series 51), or
sometimes simply as MCS-51. The block diagram of 89C51 microcontroller
is shown below.
ACCUMULATOR (ACC): Accumulator is a general-purpose register, which stores
runtime results. Before performing any operation upon an operand, operand has to be
stored in the accumulator. Results of arithmetical operations are also stored in the
accumulator. When transferring data from one register to another, it has to go through the
accumulator. Due to its versatile role, this is the most frequently used register, essential
part of every MCU.
B REGISTER: B Register is used along with the Accumulator for multiplication and
division. This B register provides temporary storage space for the result of multiplication
& division operation. Instructions of multiplication and division can be applied only to
operands located in registers A and B. Other instructions can use this register as a
secondary accumulator (A).
PORTS: Term "port" refers to a group of pins on a microcontroller which can be
accessed simultaneously, or on which we can set the desired combination of zeros and
ones, or read from them an existing status. Ports represent physical connection of Central
Processing Unit with an outside world. Microcontroller uses them in order to monitor or
control other components or devices. 89C51 has 4 ports; with each port have 8-bit length.
All the ports are bit and byte addressable.

16

Fig. 3.2.AT 89C51 Architecture


Port 0 (P0): Port 0 has two-fold role: If external memory is used, P0 behaves as address output
(A0 A7) when ALE pin is at high logical level, or as data output (Data Bus) when ALE pin is at
low logical level, otherwise all bits of the port are either input or output. Another feature of this
port comes to play when it has been designated as output. Unlike other ports, Port 0 lacks the
"pull up" resistor (resistor with +5V on one end). This seemingly insignificant change has the
following consequences:

When designated as input, pin of Port 0 acts as high impedance offering the infinite input
resistance with no "inner" voltage.

17

When designated as output, pin acts as "open drain". Clearing a port bit grounds the
appropriate pin on the case (0V). Setting a port bit makes the pin act as high impedance.
Therefore, to get positive logic (5V) at output, external "pull up" resistor needs to be
added for connecting the pin to the positive pole.
Therefore, to get one (5V) on the output, external "pull up" resistor needs to be
added for connecting the pin to the positive pole.
Port 1 (P1): Port 1 is I/O port. Having the "pull up" resistor, Port 1 is fully compatible
with TTL circuits. The alternate functions of Port1 are

Port 2 (P2): When using external memory, this port contains the higher address
byte (addresses A8A15), similar to Port 0. Otherwise, it can be used as universal I/O
port.
Port 3 (P3): Beside its role as universal I/O port, each pin of Port 3 has an alternate
function. In order to use one of these functions, the pin in question has to be designated
as input, i.e. the appropriate bit of register P3 needs to be set. By selecting one of the
functions the other one is disabled. From a hardware standpoint, Port 3 is similar to Port
0. The alternate functions of Port 3 is given below
Data Pointer (DPTR) : The Data pointer register is made up of two 8 bit registers,
named DPH (Data Pointer High) and DPL (Data Pointer Low). These registers are used
to give addresses of the internal or external memory. The DPTR is under the control of
program. DPTR is also manipulated as one 16 bit register, DPH & DPL are each assigned
an address. The 89C51 microcontroller has additional DPTR. The dual DPTR structure is
a way by which the chip will specify the address of an external data memory location.
There are two 16-bit DPTR registers that address the external memory, and a single bit
called DPS (bit0 in AUXR1) that allows the program code to switch between them.
Stack Pointer (SP) : The stack refers to an area of internal RAM that is used in
conjunction with certain opcodes to store and retrieve data quickly. The register used to
access the stack is called Stack Pointer. The 8 bit stack pointer register is used by the
89C51 to hold an internal RAM address that is called then top of the stack. The stack
pointer increments before storing the data on the stack. As retrieved from the stack the SP
is decremented by one. The number in Stack Pointer points to the location of the last
18

"valid" address within the Stack. With the beginning of every new routine, Stack Pointer
increases by 1; upon return from routine, SP decreases by 1. Upon reset (or turning the
power on), the stack pointer contains the value07h.
Program Counter (PC): Used to access code memory. Program counter always points
to the address of the next instruction in memory to be executed. Upon reset (or turning
the power on), the program counter resets to the starting location of the program.
Instruction Register: When an instruction is fetched from the Flash memory, it is loaded
in the instruction register.
Timing & Control unit: The timing and control unit synchronizes the operation of the
microcontroller and generates control signals necessary for communication between the
microcontroller and the peripherals
Program Status Word (PSW): The Program Status Word (PSW) register is an 8 bit
register. It is also referred to as the flag register. It contains the math flags, user program
flag F0, and the register select bits that identify which of the four general purpose register
banks is currently in use by the program.
Oscillator: Oscillator circuit is used for providing a microcontroller with a clock. Clock
is needed so that microcontroller could execute a program or program instructions. Stable
pace provided by the oscillator allows harmonious and synchronous functioning of all
other parts of MCU. The manufacturers make available 89C51 designs that can run at
specified maximum and minimum frequencies, typically 1 megahertz to 33 megahertz.
Minimum frequencies imply that some internal memories are dynamic and must always
operate above a minimum frequency or data will be lost.
Interrupts: An interrupt is a signal from a device attached to a computer or from a
program within the computer that causes the main program that operates the computer to
stop and points out what to do next. In general, there are hardware interrupts and software
interrupts. A hardware interrupt is related to the hardware of the system. For example,
when an I/O operation is completed such as reading some data into the computer from a
keyboard interrupt the main program. As the name implies the software interrupts related
to the software of the system. It occurs when an application program terminates or
requests certain services from the operating system.

19

Timers/Counters: Timers are usually the most complicated parts of a microcontroller.


Physically, timer is a register whose value is continually increasing toFFFFh, and then it
starts all over again: 0h, 1h, 2h, 3h, 4h...FFFFh....0h, 1h, 2h, 3h......etc. The 89C51 MCU
clock employs a quartz crystal. As this frequency is highly stable and accurate, it is ideal
for time measuring. Since one instruction takes 12 oscillator cycles to complete, the math is
easy. 89C51 has three Timers/Counters marked as T0, T1 & T2. Their purpose is to measure time
and count external occurrences, but can also be used as clock in serial communication purpose
called as, Baud Rate.
Serial Port: Serial port is used to provide communication among two devices. Serial data
communication has been widely used for long distance communication because of the ease and
the economy of using only one wire to transmit data. Serial port is also referred as RS232 port.
RS232 is a asynchronous way of communication. Asynchronous transmission allows data to be
transmitted without the sender having to send a clock signal to the receiver. Instead, the sender
and receiver must agree on timing parameters in advance and special bits are added to each
word, which are used to synchronize the sending and receiving units.

3.5 MEMORY ORGANIZATION


3.5.1 RAM (Data Memory)
RAM is used for storing temporary data and auxiliary results generated
during the runtime.
The Lower 128 bytes of RAM (addresses 00H to 7FH) are directly and
indirectly addressable.
The Upper 128 bytes of RAM (addresses 80H to FFH) are indirectly
addressable only.
The Special Function Registers, SFRs, (addresses 80H to FFH) are
directly addressable only.
The 768-bytes expanded RAM (ERAM, 00H 2FFH) are indirectly
accessed by move external instruction, MOVX.

20

Fig :3.3 RAM Organization


The

Lower

128

bytes

can

be

accessed

by

either

direct

or

indirect

addressing. The Upper 128 bytes can be accessed by indirect addressing only.
The Upper 128 bytes occupy the same address space as the SFR. That means

3.5.2 Program Memory


Figure 4.3 shows a map of the lower part of the program memory. After reset, the CPU
begins execution from location 0000H. As shown in fig.4, each interrupt is assigned a fixed
location in program memory. The interrupt causes the CPU to jump to that location, where it
executes the service routine. External Interrupt 0, for example, is assigned to location 0003H. If
External Interrupt 0 is used, its service routine must begin at location 0003H. If the interrupt is
not used, its service location is available as general purpose.

21

(0033)H

002BH
INTERRUPT
LOCATIONS

8 bytes
0023H

RESET

001BH

Fig.3.4 program Memory.


The Serial Port Interrupt is generated by the logical OR of RI and TI. Neither of
these flags is cleared by hardware when the service routine is vectored to. In fact, the
service routine will normally have to determine whether it was RI or TI that generated the
interrupt, and the bit will have to be cleared in software.
All of the bits that generate interrupts can be set or cleared by software, with the
same result as thought it had been set or cleared by hardware. This is, interrupts can be
generated or pending interrupts can be canceled in software.

Each of these interrupt sources can be individually enabled or disabled by setting


or clearing a bit in Special Function Register IE. IE also contains a global disable bit, EA,
which disables all interrupts at once.

3.6 TIMERS AND COUNTERS


3.6.1 Timer Set-Up
The tables below give some values for TMOD which can be used to set up Timer 0 and
Timer 1 in different modes. It is assumed that only one timer is being used at a time. If it is
desired to run Timers 0 and 1 simultaneously, in any mode the value in the TMOD for timer 0
22

must be ORed with value shown for Timer 1. For example, if it is desired to run Timer 0 in mode
1 GATE (external control), and Timer 1 in mode 2 COUNTER, then value that must be loaded into
TMOD is 69H (09H from the table for Timer0, ORed with 60H from the table for Timer 1).
Moreover, it is assumed that the user, at this point, is not ready to turn the timers on
and will do that at a different point in the program by setting bit TRx (in TCON) to 1.

3.7 CLOCK CONCEPT


The clock concept is found in all modern digital electronics, it is a simple circuit
that will generate pulses of electricity at a very specific frequency. Those pulses will
cadence all the events happening inside a microcontroller, those pulses will also assure
the synchronization of the events between various components inside the microcontroller.
For example, if the CPU is waiting for some result of mathematical operation from the
ALU (Arithmetic and Logic Unit), it will be known - according to very specific protocol when and where the resulting data will be delivered to the CPU. The synchronization of
those

two

devices

is

maintained

because

they

share

the

same

clock.

The clock has another very important role which is to enable the microcontroller
to count timing. Without a precise clock, it would be impossible to build a 'Real Time
System', or any other device that relies on time measurements. It can be deduced that the
precision of the timing of a microcontroller depends on the frequency of its clock.
In the AT89C51 microcontroller, the clock can be fixed to different value by
connecting a crystal to the pins 18 and 19. Those crystals are sold with the frequency
written on them in Mega Hertz. The maximum operating frequency of the AT89C51 is 33
MHz, however other manufacturers like Philips built similar 8051 microcontrollers that
can run at frequencies up to 120 MHz.

23

3.8Analog To Digital converter (ADC):


3.8.1Description of ADC:
Analog-to-digitals converters are among the most widely used devices for data acquisition.
Digital computers use binary(discrete) values, but in the physical world everything is analog
(continuous).Temperature, Pressure(wind or liquid),humidity, and velocity are a few examples of
physical quantities that we deal with every day. A physical is converted to electrical (voltage,
current) signals using device called a transducer. Transducers are referred to as sensors. Sensors
for temperature, pressure, light, many other natural quantities produce an output that is voltage
(or current).Therefore, we need an analog-to-digital convertor to translate the analog signals to
digital numbers so that the microcontroller can read and process them. An ADC has n-bit
resolution where n can be 8,10,12,16oreven 24 bits. The higher resolution ADC provides a
smaller step size,where step size is the smallest change that can be discerned by an ADC.this is
shown in table. .In addition to resolution ,convertion time is another major factor in judging an
ADC. Convertion time is defined as the time it takes the ADC to convert the analog input to a
digital(binary) number.The ADC CHIPS either parallel or serial.In parallel ADC ,we have only
one pin for data out..MAX1112 is an serial ADC chip.
Table:3.2Resolution Vs .step Size for ADC
n-bit
Number of steps
8
256
10
1024
12
4096
16
65536
Note:Vcc=5V
size is the smallest change that can be discerned by an ADC.

Step size(mV)
5/256=19.53
5/1024=4.88
5/4096=1.2
5/65536=0.076
step

The ADC 0801:


The ADC 0801 converter is designed to allow operation with the NSC800 and INS8080A
derivative control bus with TRI-STATE output latches directly driving the data bus. These A/Ds
appear like memory locations or I/O ports to the microprocessor and no interfacing logic is
needed.
Differential analog voltage inputs allow increasing the common-mode rejection and
offsetting the analog zero input voltage value. In addition, the voltage reference input can be
adjusted to allow encoding any smaller analog voltage span to the full 8 bits of resolution.
Features:

24

It has 20pins Compatible with 8080 P derivatives no interfacing logic needed access time - 135 ns
Easy interface to all microprocessors, or operates standalone
Differential analog voltage inputs
Logic inputs and outputs meet both MOS and TTL voltage level specifications
Works with 2.5V (LM336) voltage reference
On-chip clock generator
0V to 5V analog input voltage range with single 5Vsupply
No zero adjust required
0.3" standard width 20-pin DIP package
20-pin molded chip carrier or small outline package
Operates ratio metrically or with 5 V DC , 2.5 V DC , or analog span adjusted voltage
reference

Key Specifications:

Resolution 8 bits
Total error 1 4 LSB, 1 2 LSB and 1 LSB
Conversion time 100 s

Pin dagram:

Fig :3.5 pin diagram of ADC 0801

25

3.8.2Pin description:
CS (PIN 1 )
Chip select is an low active low input used to activate the ADC0804 chip.To access the
AC0804,this pin must be low.
RD (read) (PIN 2 )
This is an input signal and is active low.The ADC convertors the analog input to its binary
equivalent and holds it in an internal register.RD is to used to get the converted data out of the
ADC0804 chip. When CS=0,if a high-to-low pulseis applied to the RD pin,the 8-bit digital
output shows up at the D0-D7 data pins.The RD pin is refered is also refered to as output
enable(OE).
WR(write) (PIN 3 )
this is an active low input pin used to inform the ADC0804 to start the conversion process. If
CS=0 when WR makes a low-to-high transition,the ADC0804 starts converting the analog input
value of Vin to an 8-bit digital nuber.The amount of time it takes to convert varies depending on
CLK IN and CLK R values explained below.When the data conversion is complete, the INTR
pin is forced low by the ADC0804.
CLK IN and CLK R(PIN 4 and 19)
CLK IN is an input pin connected to an external clock source when an external clock is used for
timing.However,the 804 has an internal clock generator.To use the internal clock generator (also
called self-clocking) of the ADC0804,the CLK IN and CLK R pins are connected to a capacitor
and a resistor,as shown in figure.in that case the clock frequency is determined by the equation:
F=1/1.1RC
Typical values are R=10k ohms and C=150pf. Substituting in the above equation,we get
f=606kHz.in that case ,the conversion time is 110 us.
INTR(interrupt) (PIN 5):
This is an output pin and is active low.It is a normally high pin and when the conversion is
finished, it goes low to signal the CPU that the converted data is to be picked up.After INTR
goes low, we make CS=0 and send a high-to-low pulse to the RD pin to get data out the data out
of the AC0804 chip.
Vin(+) and Vin(-)(PIN 6 and 7 ):
26

These are the differential analog inputs wherw Vin=Vin(+)-Vin(-).often Vin(-) is connected to
the ground and Vin(+) pin is used as a analog input to be converted to digital.
Vcc(PIN 20 )
This is +5 volts power supply .it is also used as reference voktage when Vref/2 input(pin9) is
open .
Vref/2(PIN 9 )
Pin 9 is an input voltage used for the reference voltage .if this ipin is open ,the analog input
voltage for ADC is in the range of 0-5 volts(same as Vcc pin).However there are many
applications where the analog input is applied toVin needs to be other than 0-5 volts.Vref/2 is
used to implement analog input voltages other than 0-5 volts.For,example if the analog input
range needs 0-4 volts,then Vref/2 is connected to 2 volts.
D0-D7(PIN 17 to 11 ):
D0-D7(D7 is the MSB)are the digital data output pins since ADC is parallel type ADC
chip.these are tristate buffered and converted data is accesed only when CS=0 and RD is forced
low.To caluculate the output vaoltage use the fallowing formula.
Dout=Vin/step size
Where Dout=digital data output (in decimal),Vin =analog input voltage and step size (resolution)
is the smallest change ,which is(2*V ref/2)/256 f0r ADC0804.
The ADC0801 is a CMOS 8-bit successive approximation A/D converter that
differential potentiometric ladder similar to the 256R products.

uses a

Analog ground and digital ground : (PIN 8 and 10 )


These are the inpit pins providing the ground for both the analog signal and digital signal
.Analog ground is connected to the ground of the analog Vin while digital ground is connected
to the ground of the Vcc pin .The reason that we have two ground pins is to isolate the analog
Vin signal from transient volatges caused by digital switching of the out put D0-D7.Such
isolation contributes to the accuracy of digital data output .in our discussion, both are handled
separately.
From this discussion we conclude that the following steps must be followed for data conversion
by the adc chip
1.Make CS=0 and send a low to-high pulse to pin
2.Keep monitoring the INTR pin .if INTR is low ,the conversion is finished and we can go to
the next step. if INTR is high ,keep polling until it gets low.
27

3.After the INTR has become low ,we make CS =0 and send a high to low pulse to the RD pin
to get the data out of ADC0801 IC chip.
Clock source for adc 0801 the speed at which an analog input ia converted to the didgital output
Depends on the speed of clock input .according to the ADC 0801 datasheets ,the typical
operating frequency is approximately 640KHz at 5 volts .figures 13.2 and 13.3 provides two
ways of providing clock for adc 0801 .In figure 13-4,notice that the clock in for the ADC 0804
is coming from the crystal of the micro controller .Since this frequency is too high ,we use D-flip
flops (74ls74) to divide the frequency . A single flip flop converts the frequency by 2 if we
connect its Q to the D input . For high frequency crystal ,you can use 4 flip-flops

28

CHAPTER
4
IMPLEMENTATION OF HARDWARE

29

4.1 POWER SUPPLY


There are many types of power supply. Most are designed to convert high voltage AC
mains electricity to a suitable low voltage supply for electronics circuits and other devices. A
power supply can by broken down into a series of blocks, each of which performs a particular
function.
For example a 5V regulated supply:

Fig.4.1 Block Diagram of Power Supply


Each of the blocks is described in more detail below:

Transformer - steps down high voltage AC mains to low voltage AC.

Rectifier - converts AC to DC, but the DC output is varying.

Smoothing - smoothes the DC from varying greatly to a small ripple.

Regulator - eliminates ripple by setting DC output to a fixed voltage.

30

4.1.1 Transformer

Fig.4.2 Transformer
When alternating voltage is applied to the primary winding, an alternating current will
flow that will magnetize the magnetic core, first in one direction and then in the other
direction.

This alternating flux flowing around the entire length of the magnetic circuit induces

a voltage in both the primary and secondary windings. Since both windings are linked by the
same flux, the voltage induced per turn of the primary and secondary windings must be
the same value and same direction. This voltage opposes the voltage applied to the primary
winding and is called counter
counter-electromotive force (CEMF).
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 ssmoothing
moothing capacitor and
regulator to get pure type of regulated smooth DC signal without any ripples .So after the process
of smoothening this DC signal can be used in various electronic circuits.
31

4.1.2 Rectifier Unit


Transformer + Rectifier + Smoothing+ Regulator

Fig.4.3 Rectifier Circuit


The Rectifier circuit is used to convert the AC voltage into its corresponding DC voltage.
There are Half-Wave, Full-Wave and bridge Rectifiers available for this specific function. The
most important and simple device used in Rectifier circuit is the diode. The simple function of the
diode is to conduct when forward biased and not to conduct in reverse bias.
The Forward Bias is achieved by connecting the diodes positive with positive of the
battery and negative with batterys negative. The efficient circuit used is the Full wave Bridge
rectifier circuit. The output voltage of the rectifier is in rippled form, the ripples from the obtained
DC voltage are removed using other circuits available. The circuit used for removing the ripples
is called Filter circuit.
From the above graph pure type of regulated smooth DC signal can be achieved.

4.1.3 Filter
Capacitors are used as filter. The ripples from the DC voltage are removed and pure DC
voltage is obtained. And also these capacitors are used to reduce the harmonics of the input
voltage. The primary action performed by capacitor is charging and discharging. It charges in
positive half cycle of the AC voltage and itwill discharge in negative half cycle. So it allows only
AC voltage and does not allow the DC voltage. This filter is fixed before the regulator. Thus the
output is free from ripples.

32

Fig 4.4 Filter

4.1.4 Voltage Regulator


It is a device, which maintains the output voltage of an ordinary power supply constant in
irrespective of load variation (or) changes in input AC voltage is known as voltage regulator.
In this we have series voltage regulator that is IC 7805.

Fig..4.5 Voltage Regulator

4.2 LED (Light-Emitting Diode)

Fig.4.6 Symbol Of LED


A light-emitting diode (LED) is a semiconductor light source. LEDs are used as indicator
lamps in many devices, and are increasingly used for lighting.
The LED is a two terminal device. We can therefore characterize it according to two
quantities: the voltage across it, and the current through it. To a (fairly good) first order, the light
33

output of the LED, either in photons per second or in mill watts, is linearly proportional to the
current through it. This means that it is useful to think of the LED as a current-operated device.
(Of course, we could think about it as either; but there is a nice relation between the light output,
which is what we ultimately care about, and the current; this is not true for the voltage.)

4.3

Crystal Oscillator
A crystal oscillator is an electronic circuit that uses the mechanical resonance of a

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

Fig 4.7(a) Symbol Of Crystal Oscillator


Schematic symbol and equivalent circuit for a quartz crystal in an oscillator
A quartz crystal can be modeled as an electrical network with a low impedance (series) and a
high impedance (parallel) resonance point spaced closely together.
Crystals can be manufactured for oscillation over a wide range of frequencies, from a few
kilohertz up to several hundred megahertz. Many applications call for a crystal oscillator
frequency conveniently related to some other desired frequency, so hundreds of standard crystal
frequencies are made in large quantities and stocked by electronics distributors.In this project we
used 11.095MHZ crystal oscillator.

34

Fig.4.7(b) Crystal Oscillator

4.4

TRANSISTOR
A transistor is simply sandwich of one type of semiconductor material between two

layers of the other type.

Fig.4.8 Symbol of Transistor

4.5

DIODE
A PN junction is known as diode . the property of a diode is to conduct current in one

direction only and is used as a rectifier. A diode is usually represented by a symbol as shown
below.

Fig.4.9 Symbol of Diode


35

4.6

RESISTOR
The property of a material which opposes the flow of the electrons is resistance or the

element is called resistor. The unit of resistance is Ohms. The symbol of resistor is.

Fig.4.10 Symbol of Resistor

4.7 RELAYS
A 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 they are double
throw (changeover) switches.
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.

Fig 4.11 Relay

4.7.1 Circuit Diagram


The relay's switch connections are usually labeled COM, NC and NO:
COM = Common, always connect to this, it is 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.

Connect to COM and NO if you want the switched circuit to be on when the
36

relay coil is on.

Connect to COM and


nd NC if you want the switched circuit to be on when the relay coil is off.
off

Fig 4.12 Circuit symbol for relay

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.

Fig 4.13 Protection

diodes for relays

If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate
the energy from the collapsing magnetic field at deactivation, which would otherwise generate a
spike of voltage and might cause damage to circuit components Re
Relay
lay 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. Transistors and ICs
(chips) must be protected from the brief high voltage 'spike' produced when the relay coil is
switched off. The diagram shows how a signal diode (eg 1N4148) is connected across the relay
coil to provide this protection. Note that the diode is connected 'backwards' so that it will
normally not conduct. Conduction only occurs when the relay coil is switched off, at this moment
current tries to continue flowing through the coil and it is harmlessly diverted through the diode.
Without the diode no current could flow and the coil would produce a da
damaging
maging high voltage
'spike' in its attempt to keep the current flowing.

4.7.2 Advantages And Disadvantages


Advantages:

Relays can switch AC and DC


DC, transistors can only switch DC.
37

Relays can switch high voltages, transistors cannot.

Relays are a better choice for switching large currents (> 5A).

Relays can switch many contacts at once.

Disadvantages:

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 chips can provide, so a low power transistor may be
needed to switch the current for the relay's coil. Software must now be as precise as ever while
maintaining a straightforward and intuitive approach to design. The software is designed in such a
way that changes in the hardware platform used imply a minimum reprogramming effort

4.8 LDR-LIGHT SENSOR


It is a device which sensee the light intensity of light. It generates analog
signl up on sensing light intensity . Light dependent resistors or LDRs are often used in
circuits where it is necessary to detect the presence orthe level of light. They can be described
by a variety ofnames from light dependent resistor, LDR, photoresistor,or even photo cell
(photocell) or photoconductor.Although other devices such as photodiodes or phototransistor can also be used, LDRs are a particularlyconvenient electronics component to
use. They providelarge change in resistance for changes in light level.In view of their low
cost,ease of manufacture, and easeof use LDRs have been used in a variety of different
applications.

At

one

time

LDRs

were used

inphotographic light meters, and even

now they are stillused in a variety of applications where it is necessary todetect light levels.

38

Fig .4.14 symbol of LDR

Fig 4.15:A light dependent resistor

39

4.8.1How an LDR works


It is relatively easy to understand the basics of how an LDR
into

works

without

delving

complicated explanations. It is first necessary to understand that an electrical current

consists of the movement of electrons within a material. Good conductors have a large number
of free electrons that can drift in a given direction under the action of a potential difference.
Insulators with a high resistance have very few free electrons, and therefore it is hard to make
the them move and hence a current to flow.An LDR or photoresistor is made any
semiconductor material with a high resistance. It has a high resistance because there are very
few electrons that are free and able to move - the vast majority of the electrons are
locked into the crystal lattice and unable to move.Therefore in this state there is a high
LDR resistance.
As light falls on the semiconductor, the light photons are absorbed by the semiconductor lattice
and some of their energy is transferred to the electrons. This gives some of Them sufficient
energy to break free from the crystal lattice so that they can then conduct electricity.
This results in a lowering of the resistance of the semiconductor and hence the overall LDR
resistance.The process is progressive, and as more light shines on the LDR semiconductor, so
more electrons are released to conduct electricity and the resistance falls further.
LDRs are very useful components that can be used for a variety of light sensing
applications. As the LDR resistance varies over such a wide range, they are particularly
useful, and there are many LDR circuitsavailable beyond any shown here. In order to
utilize these components, it is necessary to know something of how an LDR works, which has
been explained above.

40

CHAPTER
5
SOFTWARE DESIGN

41

The softwares used in the project are

Proteus VSM

Keil Vision3

uc-flash

5.1 Proteus VSM:


ISIS provides the development environment for PROTEUS VSM. This product combines
mixed mode circuit simulation, micro-processor models and interactive component models to
allow the simulation of complete micro-controller based designs.
ISIS provides the means to enter the design in the first place, the architecture for real time
interactive simulation and a system for managing the source and object code associated with
each project. In addition, a number of graph objects can be placed on the schematic to enable
conventional time, frequency and swept variable simulation to be performed.
Proteus VSM combines a superb mixed mode circuit simulator based on the industry standard
SPICE3F5 with animated component models. And it provides an architecture in which additional
animated models may be created by anyone, including end users. Indeed, many types of
animated model can be produced without resort to coding. It created a range of simulator
models for popular micro-controllers and a set of animated models for related peripheral
devices such as LED and LCD displays, keypads, an RS232 terminal and more. It is possible to
simulate complete micro-controller systems and thus to develop the software for them without
access to a physical prototype.
5.1.1 Major Features Of PROTEUS VSM Include

True Mixed Mode simulation based on Berkeley SPICE3F5 with extensions for digital
simulation and true mixed mode operation.

Support for both interactive and graph based simulation.

CPU Models available for popular microcontrollers such as the PIC and 8051 series.

Interactive peripheral models include LED and LCD displays, a universal matrix keypad,
an RS232 terminal and a whole library of switches, pots, lamps, LEDs etc.

Virtual Instruments include voltmeters, ammeters, a dual beam oscilloscope and a 24


channel logic analyzer

42

Graph Based Analysis types include transient, frequency, noise, distortion, AC and DC
sweeps and fourier transform. An Audio graph allows playback of simulated waveforms.

5.2 STEPS TO DRAW SCHEMATIC DIAGRAM

To start the ISIS program, click on the Start button and select Programs, Proteus 7
Professional and then the ISIS 7 Professional option. The ISIS schematic editor will then
load and run. Along the top of the screen is the menu bar.

Pick the components you want to use from the device libraries by selecting the
component icon and then using the P button on the Device Selector. You can use any
component with a simulation model and these parts are indicated at the top right of the
schematic preview before the device is select.

Left Click to enter placement mode, move the mouse to the point you want to deposit the
component and click left again to commit.

43

Edit them - double click on the object or right click and select Edit Properties from the
resulting context menu - in order to assign appropriate values and properties.

Wire the circuit up by clicking on the pins.

Delete components by right clicking on the component and selecting Delete from the
resulting context menu.

44

Move components by clicking left to select and then dragging with the left button.

Having selected the parts we need the next thing is to actually place them on the drawing
area the Editing Window and wire them together.
The Animation Control Panel:
Interactive simulations are controlled from a simple VCR like panel that behaves just like
a normal remote control. This control is situated at the bottom right of the screen.
Press the PLAY button to run the simulation.

 The PLAY button is used to start the simulator.


 The STEP button allows you to step through the animation at a defined rate. If the button
is pressed and released then the simulation advances by one time step; if the button is
held down then the animation advances continuously until the button is released.
 The The STOP button tells PROSPICE to stop doing a real time simulation. All
animation is stopped and the simulator is unloaded from memory.PAUSE button
suspends the animation which can then be resumed either by clicking the PAUSE button.
Micro-processor source code can be brought under the control of PROTEUS VSM using the
commands on the Source menu or imported via an object file from favourite compiler to assign
the object code (COF, ELF, HEX etc.) to the micro-processor component on the schematic.

45

Fig 5.1 Hex File

5.3 Keil Vision3:


The Vision3 IDE is a Windows-based software development platform that
combines a robust editor, project manager, and makes facility. Vision3 integrates all
tools including the C compiler, macro assembler, linker/locator, and HEX file generator.
Vision3 helps expedite the development process of your embedded applications by
providing the following:


Full-featured source code editor,

Device database for configuring the development tool setting,

Project manager for creating and maintaining your projects,

Integrated make facility for assembling, compiling, and linking your embedded applications,

Dialogs for all development tool settings,

True integrated source-level Debugger with high-speed CPU and peripheral simulator,

Advanced GDI interface for software debugging in the target hardware and for connection to
Keil ULINK,

Flash programming utility for downloading the application program into Flash ROM,

Links to development tools manuals, device datasheets & users guides.


The Vision3 IDE offers numerous features and advantages that help quickly and successfully
develop embedded applications.

46

A program has been developed according to the connections given by the micro controller and
required operation of the system is converted to assembly language from embedded C language
using Keil Vision3.

5.3.1 Steps To Generate Hex File From .C File


 Create Project File Folder and Specify Project Name:
To create a new project file select from the Vision3 menu Project New Vision Project.
This opens a standard Windows dialog that asks you for the new project file name. You should
you use a separate folder for each project.

 Select Microcontroller from Device Database:


When you create a new project Vision3 asks you to select a CPU for your project. The
Select Device dialog box shows the Vision3 device database. Just select the
microcontroller you use.

 Create New Source Files:


47

You may create a new source file with the menu option File New. This opens an empty
editor window where you can enter your source code. Vision3 enables the C color
syntax highlighting when you save your file with the dialog File Save As under a
filename with the extension *.C. We are saving our example file under the name cage.c.

 Add Source Files to Project:


Once you have created your source file you can add this file to your project.

 Build Project:

You may translate all source files and link the application with a click on the Build
Target toolbar icon. When you build an application with syntax errors, Vision3 will
display errors and warning messages in the Output Window Build page. A double
click on a message line opens the source file on the correct location in a Vision3 editor
window.

48

 Create HEX File:


Once you have successfully generated your application you can start debugging. After
you have tested your application, it is required to create an Intel HEX file to download
the software into an EPROM programmer or simulator. Vision3 creates HEX files with
each build process when Create HEX file under Options for Target Output is enabled.

49

5.4 UCFLASH+
The ucFlash+ Programmer is an affordable, reliable, and fast programmer for
MCS51/AVR Microcontrollers and 24Cxx I2C EEPROMs. The programmer is designed to operate
with the Intel Pentium-based IBM-compatible desktop computers and notebook computers.

Hardware Features:
1. This programmer includes a 40-pin ZIF socket & supports 8-pin to 40-pin DIP package devices.
2. RS232 Serial Port Interface.
3. Programmer firmware update through computer.

Software Features:
1. Works on MS-WINDOWS 98 \ 2000 \ ME \ NT \ XP Operating System.
2. User-friendly interfaces with pull-down menus, pop-up dialogue box and help.
3. Device insertion test.
4. Support all operations, such as program, verify, blank check, read, secure, erase and so on.
5. Easy to use integrated HEX Editor on main software window..
6. Supports Intel (linear & segmented) HEX (INHX8M).
7. Auto Batch Program function for faster programming i.e. Mass Production mode.
8. Automatic device identification before programming.
9. Support for programming only a selected memory in the microcontroller e.g. Data memory or
Fuse Bits

50

5.4.1 Device Programming:


1. Connect the programmer to the computers communication port with the provided
cable. Then connect the AC adapter or power cable to the programmers power jack. And turn
on your programmer. The status LED on the programmer should glow Red now. Run the
software. The LED should now glow Green indicating successful communication between the
software and the programmer.

Fig 5.2 uc flash


2. Insert the chip into the ZIF socket as indicated in the image on main window only after
the software communication check is OK and the LED is glowing Green. Lock the device
in the programmers ZIF by pulling the lever down.

51

3. From the main screen, use the mouse to click on the Function menu, and then click on
the Select Device sub-menu. A window named Select Device will pop out. Select the
type of device and click Select button.

4. The next process is to load the data that you wish to program into the buffer. You may
do this by loading a data file into the buffer, by reading data into the buffer from a master
chip, or by typing the data into the buffer directly.

5. Click on the Function menu from the main screen, and select the Program sub-menu or
click the Program button on the main screen. Your data will then be programmed into the
chip and verified automatically. To double check you can, you can verify it once again by
clicking Verify sub-menu in the Function menu or verify button on the main screen.
6. Similarly you can execute different functions like Blank Check, Erase and Read.
The above steps are used to dump the program into microcontroller using uc flash+.

5.5 89C51 PROJECT DEVELOPMENT CYCLE


These are the steps to develop 8051 project using keil Create source files in C or assembly

Compile or assemble source files.

Correct errors in source files.

Link object files from compiler and assembler.

Test linked application. Now let us start how to work with keil.

52

5.6 SOFTWARE CODE FOR EXECUTION


The program code to implement Automatic ligtht Control By A Microcontroller is given in
Appendix-A.

5.7 REQUIRED SPECIFICATION


The following are the steps to create and run the program

 Creating And Saving A Design In Proteus

Fig 5.3 Proteus Circuit


 Writing A Program In Notepad And Saving

53

Fig 5.4 Note Pad


 Dumping Of Program Into Microcontroller Using Keil

54

Fig5.5 Keil

 Running The Program

55

Fig 5.6 Schematic

56

CHAPTER
6
PROTEUS CIRCUIT AND RESULTS

57

Fig .6.1 Schematic of Automatic light control using microcontroller

6.1Circuit Operation :
The above diagram is the schematic of automatic light control using microcontroller ,
The above circuit consists of An ldr with light source, adc0801, micro controller AT89C51,6 relays
With corresponding power required.

A light source and ldr:


The source with ldr is connected to analog to digital converter(ADC 0801).when light falls on ldr
it senses the light intensity and gives the analog out put as input to ADC 0801.

58

ADC :
The micro controller does take the input from ldr since it gives analog output.This analog input
is converted into digital data by means of adc.The adc takes the analog output from ldr as input
and gives the digital data as out put which can read by micro controller.The purpose adc is to
convert analog input to digital since micro controller only reads only digital data .Thus ADC is necessary.
Micro controller:
Micro controller reads data from adc and activates the relays according that when light intensity
detected is more it activates less number of relays, and when light intensity detected is less the micro
controller activates more relays . when light intensity detected is zero the micro controller activates
all the relays.when relays activates corresponding LED glows .thus based on light intensity the leds are
switched on and off.
The light source is near the ldr light intensity is more less relays activates i.e less leds glow, The light
source is far from the ldr light intensity is less more relays activates i.e more number of leds glow
The outputs when zero light,medium ,full intensitys are given below:

Fig6.2: light is very far( zero )light intensity

59

Fig:6.3 less light intensity

Fig:6.4 medium light intensity

60

Fig :6.5more light intensity

Fig :6.6full intensity

61

CHAPTER

SOFTWARE PROGRAMMING

62

SOFTWARE PROGRAMMING
The software program loaded into the micro controller is given as below:#include<reg51.h>
sbit WRITE=P2^5;
sbit READ=P2^6;
sbit INTR=P2^7;
sfr ldata=0x90;
sfr mydata=0xb0;
void delay();void main()
{
char value;ldata=0xFF;
P3=0xff;
INTR=1;
WRITE=1;
READ=1;
while(1)
{
WRITE=0;
//delay();
WRITE=1;
while(INTR==1);
READ=0;
//delay();

63

value=ldata;
if(value<=15&&value>=0)
P3=0x00;
if(value<=20&&value>=15)

P3=0x01;
if(value<=28&&value>=20)
P3=0x03;
if(value<=50&&value>=38)
P3=0x07;
if(value<=90&&value>=50)
P3=0x0f;
if(value<=100&&value>=80)
P3=0x1f;
if(value<=120&&value>=100)
P3=0x3f;
if(value<=200&&value>=168)
P3=0x7f;
if(value<=250&&value>=200)
P3=0xff;
READ=1;
}
}

64

void delay()
{
int i,j;
for(i=0;i<256;i++)
for(j=0;j<256;j++);
}

65

CHAPTER

FUTURE IMPLEMENTATION AND CONCLUSIONS

66

7.1 FUTURE IMPLEMENTATION


It provides useful information to those who wish to carry out automatic light control
system project.
Future implementation of this project is it is used as real time applications by few
modifications.

7.2 CONCLUSIONS
 This project is used in switch on and switch off street lights automatically
Up on sensing the light intensity.
 This circuit has a wide use in many sectors in the day to day world.

67

REFERENCES
[1] Muhammad Ali Mazidi,Janice Gillispie Mazidi & Rolin D.Mcinlay,The 8051
Microcontroller And Embedded Systems Using Assembly And C,2nd edition.
[2] M.H.Rashid,Power Electronics,2nd edition.

Websites
[1] www.wikipedia.com
[2] www.scribd.com
[3] www.globusz.com

68

APPENDIX-A
AT89c51 MICROCONTROLLER DATA SHEET

69

70

71

You might also like