Sie sind auf Seite 1von 65

CHAPTER 1

OVERVIEW

1.1 INTORDUCTION

Temperature is a physical quantity expressing hot and cold. Something that is cold has
less temperature and hot has high temperature. Temperature is measured using
thermometers that may be calibrated in variety of temperature scales.

Temperature control is a process in which change of temperature of a space (and objects


collectively there within), or of a substance, is measured or otherwise detected, and the
passage of heat energy into or out of the space or substance is adjusted to achieve a
desired temperature. A Temperature Controlled System is a type of control system that
automatically controls the temperature of an object or an area.

1.2 AIM OF THE PROJECT

The main aim of this project is to continuously monitor the temperature and control the
temperature automatically according to the temperature detected by using 8051
microcontroller. It also detects fire and it spills water in order to decrease the damage
caused and also can save life of people.

1.3 OBJECTIVES

 To Monitor the temperature by and controlling it with the given cooling system
present In the given Environment.
 To Detect Fire ,Smoke and Spill water if it is Detected.
 To develop the hardware system to monitor the temperature of the environment.

1
1.4 WORKING PRINCIPLE:

The Temperature Monitor and Control system works continuously until it gets power
from the power source. It monitors the surrounding temperature using LM35
temperature Sensor and it sends data to the LCD module. According to the temperature
detected the motor rotates the fan at different speeds automatically by using PWM
technique.

1.5 METHODOLOGY:

Step-1: Setting up the 8051


Step-2: Interfacing temperature sensor, and LCD.

Step-3: Configuring LCD display.


Step-4: Sensing sensor data and LCD.
Step-5: Interfacing Relay and motor.
Step-6: Controlling the Speed of motor.

2
CHAPTER 2
INTRODUCTION TO EMBEDDED SYSTEM

2.1 Introduction:

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


encapsulated by or dedicated to the device or system it controls. Unlike a general-purpose
computer, such as a personal computer, an embedded system performs one or a few predefined
tasks, usually with very specific requirements. Since the system is dedicated to specific tasks,
design engineers can optimize it, reducing the size and cost of the product. Embedded systems
are often mass-produced, benefiting from economies of scale.
Personal digital assistants (PDAs) or handheld computers are generally considered embedded
devices because of the nature of their hardware design, even though they are more expandable
in software terms.

Physically, embedded systems ranges from portable devices such as digital watches and MP3
players, to large stationary installations like traffic lights, factory controllers, or the systems
controlling nuclear power plants. In terms of complexity embedded systems can range from
very simple with a single microcontroller chip, to very complex with multiple units,peripherals
and networks mounted inside a large chassis or enclosure.

Examples of Embedded Systems:


 Avionics, such as inertial guidance systems, flight control hardware/software and
other
 Integrated systems in aircraft and missiles
 Cellular telephones and telephone switches
 Engine controllers and antilock brake controllers for automobiles
 Home automation products, such as thermostats, air conditioners, sprinklers, and
security
 Monitoring systems
 Handheld calculators
 Handheld computers
3
 Household appliances, including microwave ovens, washing machines, television sets,
 DVD players and recorders
 Medical equipment
 Computer peripherals such as routers and printers.
 Industrial controllers for remote machine operation.

2.2 MICROCONTROLLER

Microcontroller, as the name suggests, are small controllers. They are like single chip
computers that are often embedded into other systems to function as processing/controlling
unit. For example, the remote control you are using probably has microcontrollers inside that
do decoding and other controlling functions. They are also used in automobiles, washing
machines, microwave ovens, toys ... etc, where automation is needed.

The key features of microcontrollers include:

 High Integration of Functionality


 Microcontrollers sometimes are called single-chip computers because they have on-
chip memory and I/O circuitry and other circuitries that enable them to function as small
standalone computers without other supporting circuitry.
 Field Programmability, Flexibility
 Microcontrollers often use EEPROM or EPROM as their storage device to allow field
programmability, so they are flexible to use. Once the program is tested to be correct
then large quantities of microcontrollers can be programmed to be used in embedded
systems.
 Easy to Use
 Assembly language is often used in microcontrollers and since they usually follow
RISC architecture, the instruction set is small. The development package of
microcontrollers often includes an assembler, a simulator, a programmer to "burn" the
chip and a demonstration board. Some packages include a high level language compiler
such as a C compiler and more sophisticated libraries.

Most microcontrollers will also combine other devices such as:

4
 A Timer module to allow the microcontroller to perform tasks for certain time periods.
 A serial I/O port to allow data to flow between the microcontroller and other devices
such as a PC or another microcontroller.
 An ADC to allow the microcontroller to accept analogue input data for processing.

Figure 2.1: Showing a typical microcontroller device and its different subunits

The heart of the microcontroller is the CPU core. In the past this has traditionally been based
on an 8-bit microprocessor unit.

Microcontrollers versus Microprocessors

Microcontroller differs from a microprocessor in many ways. First and the most important is
its functionality. In order for a microprocessor to be used, other components such as memory,
or components for receiving and sending data must be added to it. In short that means that
microprocessor is the very heart of the computer. On the other hand, microcontroller is
designed to be all of that in one. No other external components are needed for its application

5
because all necessary peripherals are already built into it. Thus, we save the time and space
needed to construct devices

2.3 HARDWARE OF MICROCONTROLLER:

2.3.1 Memory unit

Memory is part of the microcontroller whose function is to store data.


The easiest way to explain it is to describe it as one big closet with lots of drawers. If we
suppose that we marked the drawers in such a way that they can not be confused, any of their
contents will then be easily accessible. It is enough to know the designation of the drawer and
so its contents will be known to us for sure.

Figure2.2: Simplified model of a memory unit

6
Memory components are exactly like that. For a certain input we get the contents of a certain
addressed memory location and that's all. Two new concepts are brought to us: addressing and
memory location. Memory consists of all memory locations, and addressing is nothing but
selecting one of them. This means that we need to select the desired memory location on one
hand, and on the other hand we need to wait for the contents of that location. Besides reading
from a memory location, memory must also provide for writing onto it. This is done by
supplying an additional line called control line. We will designate this line as R/W (read/write).
Control line is used in the following way: if r/w=1, reading is done, and if opposite is true then
writing is done on the memory location. Memory is the first element, and we need a
few operation of our microcontroller.

The amount of memory contained within a microcontroller varies between different


microcontrollers. Some may not even have any integrated memory (e.g. Hitachi 6503, now
discontinued). However, most modern microcontrollers will have integrated memory. The
memory will be divided up into ROM and RAM, with typically more ROM than RAM.

Typically, the amount of ROM type memory will vary between around 512 bytes and 4096
bytes, although some 16 bit microcontrollers such as the Hitachi H8/3048 can have as much as
128 Kbytes of ROM type memory.

ROM type memory, as has already been mentioned, is used to store the program code. ROM
memory can be ROM (as in One Time Programmable memory), EPROM, or EEPROM.

The amount of RAM memory is usually somewhat smaller, typically ranging between 25 bytes
to 4 Kbytes.

RAM is used for data storage and stack management tasks. It is also used for register stacks
(as in the microchip PIC range of microcontrollers).

2.3.2 Central Processing Unit

Let add 3 more memory locations to a specific block that will have a built in capability to
multiply, divide, subtract, and move its contents from one memory location onto another. The

7
part we just added in is called "central processing unit" (CPU). Its memory locations are called
registers.

Figure2.3: Simplified central processing unit with three registers

Registers are therefore memory locations whose role is to help with performing various
mathematical operations or any other operations with data wherever data can be found. Look
at the current situation. We have two independent entities (memory and CPU) which are
interconnected, and thus any exchange of data is hindered, as well as its functionality. If, for
example, we wish to add the contents of two memory locations and return the result again back
to memory, we would need a connection between memory and CPU. Simply stated, we must
have some "way" through data goes from one block to another.

2.3.3 Bus

That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires.
There are two types of buses: address and data bus. The first one consists of as many lines as
the amount of memory we wish to address and the other one is as wide as data, in our case 8
bits or the connection line. First one serves to transmit address from CPU memory, and the
second to connect all blocks inside the microcontroller.

8
Figure2.4: Showing connection between memory and central unit using buses

As far as functionality, the situation has improved, but a new problem has also appeared: we
have a unit that's capable of working by itself, but which does not have any contact with the
outside world, or with us! In order to remove this deficiency, let's add a block which contains
several memory locations whose one end is connected to the data bus, and the other has
connection with the output lines on the microcontroller which can be seen as pins on the
electronic component.

2.3.4 Input-output unit

Those locations we've just added are called "ports". There are several types of ports: input,
output or bidirectional ports. When working with ports, first of all it is necessary to choose
which port we need to work with, and then to send data to, or take it from the port.

9
Figure2.5: Simplified input-output unit communicating with external world

When working with it the port acts like a memory location. Something is simply being written
into or read from it, and it could be noticed on the pins of the microcontroller.

2.3.5 Serial communication

Beside stated above we've added to the already existing unit the possibility of communication
with an outside world. However, this way of communicating has its drawbacks. One of the
basic drawbacks is the number of lines which need to be used in order to transfer data. What if
it is being transferred to a distance of several kilometers? The number of lines times’ number
of kilometers doesn't promise the economy of the project. It leaves us having to reduce the
number of lines in such a way that we don't lessen its functionality. Suppose we are working
with three lines only, and that one line is used for sending data, other for receiving, and the
third one is used as a reference line for both the input and the output side. In order for this to
work, we need to set the rules of exchange of data. These rules are called protocol. Protocol is
therefore defined in advance so there wouldn't be any misunderstanding between the sides that
are communicating with each other. For example, if one man is speaking in French, and the
other in English, it is highly unlikely that they will quickly and effectively understand each
other. Let's suppose we have the following protocol. The logical unit "1" is set up on the
transmitting line until transfer begins. Once the transfer starts, we lower the transmission line
to logical "0" for a period of time (which we will designate as T), so the receiving side will

10
know that it is receiving data, and so it will activate its mechanism for reception. Let's go back
now to the transmission side and start putting logic zeros and ones onto the transmitter line in
the order from a bit of the lowest value to a bit of the highest value. Let each bit stay on line
for a time period which is equal to T, and in the end, or after the 8th bit, let us bring the logical
unit "1" back on the line which will mark the end of the transmission of one data. The protocol
we've just described is called in professional literature NRZ (Non-Return to Zero).

Figure2.6: Serial unit sending data through three lines only

As we have separate lines for receiving and sending, it is possible to receive and send data
(info.) at the same time. So called full-duplex mode block which enables this way of
communication is called a serial communication block. Unlike the parallel transmission, data
moves here bit by bit, or in a series of bits what defines the term serial communication comes
from. After the reception of data we need to read it from the receiving location and store it in
memory as opposed to sending where the process is reversed. Data goes from memory through
the bus to the sending location, and then to the receiving unit according to the protocol.

11
2.3.6 Timer unit

Since we have the serial communication explained, we can receive, send and process data.

Figure2.7: Timer unit generating signals in regular time intervals

However, in order to utilize it in industry we need a few additionally blocks. One of those is
the timer block which is significant to us because it can give us information about time,
duration, protocol etc. The basic unit of the timer is a free-run counter which is in fact a register
whose numeric value increments by one in even intervals, so that by taking its value during
periods T1 and T2 and on the basis of their difference we can determine how much time has
elapsed. This is a very important part of the microcontroller whose understanding requires most
of our time.

2.3.7 Watchdog

One more thing is requiring our attention is a flawless functioning of the microcontroller
during its run-time. Suppose that as a result of some interference (which often does occur in
industry) our microcontroller stops executing the program, or worse, it starts working
incorrectly.

Figure2.8: Watchdog

12
Of course, when this happens with a computer, we simply reset it and it will keep working.
However, there is no reset button we can push on the microcontroller and thus solve our
problem. To overcome this obstacle, we need to introduce one more block called watchdog.
This block is in fact another free-run counter where our program needs to write a zero in every
time it executes correctly. In case that program gets "stuck", zero will not be written in, and
counter alone will reset the microcontroller upon achieving its maximum value. This will result
in executing the program again, and correctly this time around. That is an important element
of every program to be reliable without man's supervision.

2.3.8 Analog to Digital Converter

As the peripheral signals usually are substantially different from the ones that microcontroller
can understand (zero and one), they have to be converted into a pattern which can be
comprehended by a microcontroller. This task is performed by a block for analog to digital
conversion or by an ADC. This block is responsible for converting an information about some
analog value to a binary number and for follow it through to a CPU block so that CPU block
can further process it.

Figure2.9: Block for converting an analog input to digital output

Finally, the microcontroller is now completed, and all we need to do now is to assemble it into
an electronic component where it will access inner blocks through the outside pins. The picture
below shows what a microcontroller looks like inside.

13
Figure2.10: Microcontroller outline with basic elements and internal connections

14
2.4 8051 MICROCONTROLLER

The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4 Kbytes


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: 4 Kbytes 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, and 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.

15
2.5 PIN DIAGRAM OF 8051:

Figure2.11 Pin configuration of Microcontroller

ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address
during accesses to external memory. ALE is emitted at a constant rate of 1/6 of the oscillator
frequency, for external timing or clocking purposes, even when there are no accesses to
external memory. (However, one ALE pulse is skipped during each access to external Data
Memory.) This pin is also the program pulse input (PROG) during EPROM programming.

PSEN: Program Store Enable is the read strobe to external Program Memory. When the device
is executing out of external Program Memory, PSEN is activated twice each machine cycle
(except that two PSEN activations are skipped during accesses to external Data Memory).
PSEN is not activated when the device is executing out of internal Program Memory.

16
EA/VPP: When EA is held high the CPU executes out of internal Program Memory (unless
the Program Counter exceeds 0FFFH in the 80C51). Holding EA low forces the CPU to execute
out of external memory regardless of the Program Counter value. In the 80C31, EA must be
externally wired low. In the EPROM devices, this pin also receives the programming supply
voltage (VPP) during EPROM programming.

XTAL1: Input to the inverting oscillator amplifier.


XTAL2: Output from the inverting oscillator amplifier.

Port 0: Port 0 is an 8-bit open drain bidirectional port. As an open drain output port, it can sink
eight LS TTL loads. Port 0 pins that have 1s written to them float, and in that state will function
as high impedance inputs. Port 0 is also the multiplexed low-order address and data bus during
accesses to external memory. In this application it uses strong internal pull-ups when emitting
1s. Port 0 emits code bytes during program verification. In this application, external pull-ups
are required.

Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. Port 1 pins that have 1s
written to them are pulled high by the internal pull-ups, and in that state can be used as inputs.
As inputs, port 1 pins that are externally being pulled low will source current because of the
internal pull-ups.

Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. Port 2 emits the high-
order address byte during accesses to external memory that use 16-bit addresses. In this
application, it uses the strong internal pull-ups when emitting 1s.

Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. It also serves the functions
of various special features of the 80C51 Family as follows:
Port Pin Alternate Function
P3.0 RxD (serial input port)
P3.1 TxD (serial output port)
P3.2 INT0 (external interrupt 0)
P3.3 INT1 (external interrupt 1)
P3.4 T0 (timer 0 external input)
P3.5 T1 (timer 1 external input)
17
P3.6 WR (external data memory write strobe)
P3.7 RD (external data memory read strobe)

VCC: Supply voltage


VSS: Circuit ground potential

2.6 RAM ARCHITECTURE:

Figure 2.12 RAM Architecture

The 8051 has a bank of 128 bytes of Internal RAM. This Internal RAM is found on-chip on
the 8051 so it is the fastest RAM available, and it is also the most flexible in terms of
reading, writing, and modifying its contents. Internal RAM is volatile, so when the 8051 is
reset this memory is cleared. The 128 bytes of internal ram is subdivided as shown on the
memory map. The first 8 bytes (00h - 07h) are "register bank 0". These alternative register
banks are located in internal RAM in addresses 08h through 1Fh.Bit memory actually resides
in internal RAM, from addresses 20h through 2Fh. The 80 bytes remaining of Internal RAM,
from addresses 30h through 7Fh, may be used by user variables that need to be accessed

18
frequently or at high-speed. This area is also utilized by the microcontroller as a storage area
for the operating stack.

Register Banks

The 8051 uses 8 "R" registers which are used in many of its instructions. These "R" registers
are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7).These registersare
generally used to assist in manipulating values and moving data from one memory location to
another. The concept of register banks adds a great level of flexibility to the 8051.

Bit Memory

The 8051, being a communication oriented microcontroller, gives the user the ability to access
a number of bit variables. These variables may be either 1 or 0. There are 128 bit variables
available to the user, numbered 00h through 7Fh. The user may make use of these variables
with commands such as SETB and CLR. It is important to note that Bit Memory is really a part
of Internal RAM. In fact, the 128 bit variables occupy the 16 bytes of Internal RAM from 20h
through 2Fh.

Special Function Register (SFR) Memory

Special Function Registers (SFRs) are areas of memory that control specific functionality of
the 8051 processor. For example, four SFRs permit access to the 8051’s 32 input/output lines.
Another SFR allows a program to read or write to the 8051’s serial port .SFR is a part of
Internal Memory. This is not the case. When using this method of memory access (it’s called
direct address), any instruction that has an address of 00h through 7Fh refers to an Internal
RAM memory address; any instruction with an address of 80h through FFh refers to an SFR
control register.

19
Registers

The Accumulator

The Accumulator, as its name suggests, is used as a general register to accumulate the results
of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile
register

The B Register:

The "B" register is very similar to the Accumulator in the sense that it may hold an 8-bit (1-
byte) value. The "B" register is only used implicitly by two 8052 instructions: MUL AB and
DIV AB. Thus, if you want to quickly and easily multiply or divide A by another number, you
may store the other number in "B" and make use of these two instructions.
Aside from the MUL and DIV instructions, the "B" register are often used as yet another
temporary storage register much like a ninth "R" register.

The "R" registers

The "R" registers are a set of eight registers that are named R0, R1, etc. up to and including
R7. These registers are used as auxiliary registers in many operations.

The Program Counter

The Program Counter (PC) is a 2-byte address that tells the 8052 where the next instruction to
execute is found in memory. When the 8052 is initialized PC always starts at 0000h and is
incremented each time an instruction is executed. It is important to note that PC isn't always
incremented by one. Since some instructions are 2 or 3 bytes in length the PC will be
incremented by 2 or 3 in these cases.
The Program Counter is special in that there is no way to directly modify its value. That is to
say, you can't do something like PC=2430h. On the other hand, if you execute LJMP 2430h
you've effectively accomplished the same thing.

20
It is also interesting to note that while you may change the value of PC (by executing a jump
instruction, etc.) there is no way to read the value of PC. That is to say, there is no way to ask
the 8052 "What address are you about to execute?" As it turns out, this is not completely true:
There is one trick that may be used to determine the current value of PC. This trick will be
covered in a later chapter.

The Data Pointer

The Data Pointer (DPTR) is the 8052ís only user-accessible 16-bit (2-byte) register. The
Accumulator, "R" registers, and "B" register are all 1-byte values. The PC just described is a
16-bit value but isn't directly user-accessible as a working register.
DPTR, as the name suggests, is used to point to data. It is used by a number of commands that
allow the 8052 to access external memory. When the 8052 accesses external memory it
accesses the memory at the address indicated by DPTR.
While DPTR is most often used to point to data in external memory or code memory, many
developers take advantage of the fact that it's the only true 16-bit register available. It is often
used to store 2-byte values that have nothing to do with memory locations.

The Stack Pointer

The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value.
The Stack Pointer is used to indicate where the next value to be removed from the stack should
be taken from.
When you push a value onto the stack, the 8052 first increments the value of SP and then stores
the value at the resulting memory location. When you pop a value off the stack, the 8052 returns
the value from the memory location indicated by SP, and then decrements the value of SP.This
order of operation is important. When the 8052 is initialized SP will be initialized to 07h. If
you immediately push a value onto the stack, the value will be stored in Internal RAM address
08h. This makes sense taking into account what was mentioned two paragraphs above: First
the 8051 will increment the value of SP (from 07h to 08h) and then will store the pushed value
at that memory address (08h).

21
2.7 Addressing Modes:

The addressing modes in the 80C51 instruction set are as follows:

Direct Addressing:

In direct addressing the operand is specified by an 8-bit address field in the instruction. Only
internal Data RAM and SFRs can be directly addressed.

Indirect Addressing:

In indirect addressing the instruction specifies a register which contains the address of the
operand. Both internal and external RAM can be indirectly addressed. The address register for
8-bit addresses can be R0 or R1 of the selected bank, or the Stack Pointer. The address register
for 16-bit addresses can only be the 16-bit “data pointer” register, DPTR.

Register Instructions

The register banks, containing registers R0 through R7, can be accessed by certain instructions
which carry a 3-bit register specification within the opcode of the instruction. Instructions that
access the registers this way are code efficient, since this mode eliminates an address byte.
When the instruction is executed, one of the eight registers in the selected bank is accessed.
One of four banks is selected at execution time by the two bank select bits in the PSW.

Register-Specific Instructions:

Some instructions are specific to a certain register. For example, some instructions always
operate on the Accumulator, or Data Pointer, etc., so no address byte is needed to point to it.
The opcode itself does that. Instructions that refer to the Accumulator as A assemble as
accumulator specific opcodes.

22
Immediate Constants:

The value of a constant can follow the opcode in Program Memory.


For example,
MOV A, #100
Loads the Accumulator with the decimal number 100. The same number could be specified in
hex digits as 64H.

Indexed Addressing:

Only program Memory can be accessed with indexed addressing, and it can only be read. This
addressing mode is intended for reading look-up tables in Program Memory A 16-bit base
register (either DPTR or the Program Counter) points to the base of the table, and the
Accumulator is set up with the table entry number. The address of the table entry in Program
Memory is formed by adding the Accumulator data to the base pointer. Another type of indexed
addressing is used in the “case jump” instruction. In this case the destination address of a jump

instruction is computed as the sum of the base pointer and the Accumulator data.

Interrupts

An interrupt is a special feature which allows the 8051 to provide the illusion of "multitasking,"
although in reality the 8051 is only doing one thing at a time.

Timers

Timers are one of the categories of hardware time delays. Time delays are used to keep a system
into halting System or sleepy mode. We have two timers-timer0, timer1.Hardware time delays
are used to generate exact time delays.

23
CHAPTER 3
HARDWARE DESCRIPTION

3.1 BLOCK DIAGRAM

LM35 LCD DISPLAY

RELAY 1
8
0
5
1
RELAY 1 MOTOR
POWER SUPPLY

RELAY 1

Figure 3.1 Block Diagram

24
3.2 LIQUID CRYSTAL DISPLAY:

LCD stands for Liquid Crystal Display. LCD is finding wide spread use replacing LEDs (seven
segment LEDs or other multi segment LEDs) because of the following reasons:

1. The declining prices of LCDs.


2. The ability to display numbers, characters and graphics. This is in contrast to LEDs,
which are limited to numbers and a few characters.
3. Incorporation of a refreshing controller into the LCD, thereby relieving the CPU of the
task of refreshing the LCD. In contrast, the LED must be refreshed by the CPU to keep
displaying the data.
4. Ease of programming for characters and graphics.

These components are “specialized” for being used with the microcontrollers, which
means that they cannot be activated by standard IC circuits. They are used for writing
different messages on a miniature LCD.

Figure 3.2: LCD DISPLAY


A model described here is for its low price and great possibilities most frequently used
in practice. It is based on the HD44780 microcontroller (Hitachi) and can display messages in
two lines with 16 characters each . It displays all the alphabets, Greek letters, punctuation
marks, mathematical symbols etc. In addition, it is possible to display symbols that user makes
up on its own. Automatic shifting message on display (shift left and right), appearance of the
pointer, backlight etc. are considered as useful characteristics.

25
3.2.1 PINS FUNCTIONS:

There are pins along one side of the small printed board used for connection to the
microcontroller. There are total of 14 pins marked with numbers (16 in case the background
light is built in). Their function is described in the table below:

Pin Logic
Function Name Description
Number State
Ground 1 Vss - 0V
Power supply 2 Vdd - +5V
Contrast 3 Vee - 0 – Vdd
D0 – D7 are interpreted as
0
4 RS commands
1
D0 – D7 are interpreted as data
Write data (from controller to
0 LCD)
Control of 5 R/W
1 Read data (from LCD to
operating
controller)
0 Access to LCD disabled
1 Normal operating
6 E
From 1 to Data/commands are transferred
0 to LCD
7 D0 0/1 Bit 0 LSB
8 D1 0/1 Bit 1
9 D2 0/1 Bit 2
10 D3 0/1 Bit 3
Data / commands
11 D4 0/1 Bit 4
12 D5 0/1 Bit 5
13 D6 0/1 Bit 6
14 D7 0/1 Bit 7 MSB

Table 3.1 : LCD Pins

26
LCD

SCREEN:

LCD screen consists of two lines with 16 characters each. Each character consists of 5x7 dot
matrix. Contrast on display depends on the power supply voltage and whether messages are
displayed in one or two lines. For that reason, variable voltage 0-Vdd is applied on pin marked
as Vee. Trimmer potentiometer is usually used for that purpose. Some versions of displays
have built in backlight (blue or green diodes). When used during operating, a resistor for current
limitation should be used (like with any LE diode).

Figure 3.3: LCD SCREEN

3.2.2 LCD BASIC COMMANDS:

All data transferred to LCD through outputs D0-D7 will be interpreted as commands or as data,
which depends on logic state on pin RS:
RS = 1 - Bits D0 - D7 are addresses of characters that should be displayed. Built in processor
addresses built in “map of characters” and displays corresponding symbols. Displaying

27
position is determined by DDRAM address. This address is either previously defined or the
address of previously transferred character is automatically incremented.RS = 0 - Bits D0 - D7
are commands which determine display mode. List of commands which LCD recognizes are
given in the table below:
Execution
Command RS RW D7 D6 D5 D4 D3 D2 D1 D0
Time
Clear display 0 0 0 0 0 0 0 0 0 1 1.64mS
Cursor home 0 0 0 0 0 0 0 0 1 x 1.64mS
Entry mode set 0 0 0 0 0 0 0 1 I/D S 40uS
Display on/off control 0 0 0 0 0 0 1 D U B 40uS
Cursor/Display Shift 0 0 0 0 0 1 D/C R/L x x 40uS
Function set 0 0 0 0 1 DL N F x x 40uS
Set CGRAM address 0 0 0 1 CGRAM address 40uS
Set DDRAM address 0 0 1 DDRAM address 40uS
Read “BUSY” flag (BF) 0 1 BF DDRAM address -
Write to CGRAM or
1 0 D7 D6 D5 D4 D3 D2 D1 D0 40uS
DDRAM
Read from CGRAM or
1 1 D7 D6 D5 D4 D3 D2 D1 D0 40uS
DDRAM
I/D 1 = Increment (by 1) R/L 1 = Shift right

0 = Decrement (by 1) 0 = Shift left

S 1 = Display shift on DL 1 = 8-bit interface

0 = Display shift off 0 = 4-bit interface

D 1 = Display on N 1 = Display in two lines

0 = Display off 0 = Display in one line

U 1 = Cursor on F 1 = Character format 5x10 dots

0 = Cursor off 0 = Character format 5x7 dots

B 1 = Cursor blink on D/C 1 = Display shift

0 = Cursor blink off 0 = Cursor shift

28
3.2.3 LCD INITIALIZATION:

Once the power supply is turned on, LCD is automatically cleared. The lcd commands are as
below

Hex Code Command to LCD Instruction Register


0F LCD ON, cursor ON
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to left)
06 Increment cursor (shift cursor to right)
05 Shift display right
07 Shift display left
0E Display ON, cursor blinking
80 Force cursor to beginning of first line
C0 Force cursor to beginning of second line
38 2 lines and 5×7 matrix
83 Cursor line 1 position 3
3C Activate second line
08 Display OFF, cursor OFF
C1 Jump to second line, position 1
OC Display ON, cursor OFF
C1 Jump to second line, position 1
C2 Jump to second line, position 2
Table 3.2: LCD Commands

Automatic reset is mainly performed without any problems. Mainly but not always! If for any
reason power supply voltage does not reach full value in the course of 10mS, display will start
perform completely unpredictably? If voltage supply unit can not meet this condition or if it is
needed to provide completely safe operating, the process of initialization by which a new reset
enabling display to operate normally must be applied.
Algorithm according to the initialization is being performed depends on whether connection to
the microcontroller is through 4- or 8-bit interface. All left over to be done after that is to give
basic commands and of course- to display messages.

29
Figure 3.4: Procedure on 8-bit initialization.

30
3.3 LCD INTERFACING WITH THE MICROCONTROLLER:

Vcc
P2.0 4 (RS) 1
P2.1 5 (R/W) 2
6(EN) 3 Gnd
P2.2

LCD
PRESET
(CONTRA
ST
D0 CONTROL
89S52 P1.0 )
P1.1 D1
P1.2 D2
P1.3 D3
P1.4 D4
P1.5 D5 15 Vcc FOR
P1.6 D6 16 BACKLIGH
Gnd
P1.7 D7 T PURPOSE

Figure 3.5: SENDING COMMANDS TO LCD

To send commands we simply need to select the command register. Everything is same as we
have done in the initialization routine. But we will summarize the common steps and put them
in a single subroutine. Following are the steps:

 Move data to LCD port


 select command register
 select write operation
 send enable signal
 wait for LCD to process the command

31
CODE:

void LCD_command(unsigned char var)

LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots

LCD_rs = 0; //Selected command register

LCD_rw = 0; //We are writing in instruction register

LCD_en = 1; //Enable H->L

LCD_en = 0;

LCD_busy(); //Wait for LCD to process the command

// Using the above function is really simple

// var will carry the command for LCD

SENDING DATA TO LCD

To send data we simply need to select the data register. Everything is same as the command
routine. Following are the steps:

 Move data to LCD port


 select data register
 select write operation
 send enable signal
 wait for LCD to process the data

32
CODE:

void LCD_senddata(unsigned char var)


{
LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots
LCD_rs = 1; //Selected data register
LCD_rw = 0; //We are writing
LCD_en = 1; //Enable H->L
LCD_en = 0;
LCD_busy(); //Wait for LCD to process the command
}
// Using the above function is really simple
// we will pass the character to display as argument to function

3.4 LINEAR MONOLITHIC 35 TEMPERATURE SENSOR

Temperature is one of the most commonly measured parameter in the world. They are used in
your daily household devices from Microwave,fridges, AC to all fields of engineering.
Temperature sensor basically measures the heat/cold generated by an object to which it is
connected. It then provides a proportional resistance, current or voltage output which is then
measured or processed as per our application.

There are four commonly used temperature sensor types:

1.Negative Temperature Coefficient (NTC) thermistor:

A thermistor is a thermally sensitive resistor that exhibits a large, predictable, and precise
change in resistance correlated to variations in temperature. An NTC thermistor provides a
very high resistance at low temperatures. As temperature increases, the resistance drops
quickly. Because an NTC thermistor experiences such a large change in resistance per °C,
small changes in temperature are reflected very fast and with high accuracy (0.05 to 1.5 °C).
Because of its exponential nature, the output of an NTC thermistor requires linearization. The
effective operating range is -50 to 250 °C for glass encapsulated thermistors or 150°C for
standard.

33
2. Resistance Temperature Detector (RTD):

An RTD, also known as a resistance thermometer, measures temperature by correlating the


resistance of the RTD element with temperature. An RTD consists of a film or, for greater
accuracy, a wire wrapped around a ceramic or glass core. The most accurate RTDs are made
using platinum but lower-cost RTDs can be made from nickel or copper. However, nickle and
copper are not as stable or repeatable. Platinum RTDs offer a fairly linear output that is highly
accurate (0.1 to 1 °C) across -200 to 600 °C. While providing the greatest accuracy, RTDs also
tend to be the most expensive of temperature sensors.

3. Thermocouple:

This temperature sensor type consists of two wires of different metals connected at two points.
The varying voltage between these two points reflects proportional changes in
temperature. Thermocouples are nonlinear, requiring conversion when used for temperature
control and compensation, typically accomplished using a lookup table. Accuracy is low, from
0.5 °C to 5 °C. However, they operate across the widest temperature range, from -200 °C to
1750 °C.

5.Semiconductor-based sensors:

A semiconductor-based temperature sensor is placed on integrated circuits (ICs). These


sensors are effectively two identical diodes with temperature-sensitive voltage vs current
characteristics that can be used to monitor changes in temperature. They offer a linear response
but have the lowest accuracy of the basic sensor types at 1 °C to 5 °C. They also have the
slowest responsiveness (5 s to 60 s) across the narrowest temperature range (-70 °C to 150 °C).

34
LM35:

LM35 is a precision IC temperature sensor with its output proportional to the temperature (in
°C).With LM35,the temperature can be measured more accurately than with a thermistor. It
also possess low self heating and does not cause more than 0.1 °C temperature rise in still air.
The operating temperature range is from -55°C to 150°C.The LM35’s low output
impedance,linear output, and precise inherent calibration make interfacing to readout or control
circuitry especially easy.It has find its applications on power supplies,battery
management,appliances,etc.

Figure 3.6 : LM35 Temperature sensor

The sensor circuitry is sealed and not subject to oxidation.The LM35 generates a higher output
voltage than thermocouples and may not require that the output voltage be amplified.The LM35
has an output voltage that is proportional to the Celsius temperature.The scale factor is .01V/°C.

The LM35 does not require any external calibration or trimming and maintains an accuracy of
+/-0.4°C at room temperature and +/-0.8°C over a range of 0°C to +100°C.Another important
characteristic of the LM35 is that it draws only 60 micro amps from its supply and possesses a
low self-heating capability.The LM35 comes in many different packages such as TO-92 plastic
transistor-like package,T0-46 metal can transistor-like package,8-lead surface mount SO-8
small outline package.

35
Lower cost is assured by trimming and calibration at the wafer level. The low-output
impedance, linear output, and precise inherent calibration of the LM35 device makes
interfacing to readout or control circuitry especially easy. The device is used with single power
supplies, or with plus and minus supplies. As the LM35 device draws only 60 µA from the
supply, it has very low self-heating of less than 0.1°C in still air. The LM35 device is rated to
operate over a −55°C to 150°C temperature range, while the LM35C device is rated for a −40°C
to 110°C range (−10° with improved accuracy). The LM35-series devices are available
packaged in hermetic TO transistor packages, while the LM35C, LM35CA, and LM35D
devices are available in the plastic TO-92 transistor package. The LM35D device is available
in an 8-lead surface-mount small-outline package and a plastic TO-220 package. Main
advantage of LM35 is that it is linear i.e. 10mv/°C which means for every degree rise in
temperature the output of LM35 will rise by 10mv. So if the output of LM35 is 220mv/0.22V
the temperature will be 22°C. So if room temperature is 32°C then the output of LM35 will be
320mv i.e. 0.32V

Pin Description of LM35:

Pin
Function Name
No
1 Supply voltage; 5V (+35V to -2V) Vcc
2 Output voltage (+6V to -1V) Output
3 Ground (0V) Ground

Table 3.3 : Pins of LM35

36
3.5 WORKING PRINCIPLE OF LM35:

There are two transistors in the center of the drawing. One has ten times the emitter area of the
other. This means it has one tenth of the current density, since the same current is going through
both transistors. This causes a voltage across the resistor R1 that is proportional to the absolute
temperature, and is almost linear across the range.The "almost" part is taken care of by a special
circuit that straightens out the slightly curved graph of voltage versus temperature.

The amplifier at the top ensures that the voltage at the base of the left transistor (Q1) is
proportional to absolute temperature (PTAT) by comparing the output of the two transistors.

The amplifier at the right converts absolute temperature (measured in Kelvin) into either
Fahrenheit or Celsius, depending on the part (LM34 or LM35).The little circle with the "i" in
it is a constant current source circuit.

Figure 3.7:Working Principal of LM35.

The two resistors are calibrated in the factory to produce a highly accurate temperature
sensor.The integrated circuit has many transistors in it -- two in the middle, some in each
amplifier, some in the constant current source, and some in the curvature compensation circuit.
All of that is fit into the tiny package with three leads.

37
CAPACITIVE LOADS:

Like most micropower circuits, the LM35 has a limited ability to drive heavy capacitive loads.
The LM35 by itself is able to drive 50 pf without special precautions. If heavier loads are
anticipated, it is easy to isolate or decouple the load with a resistor Or you can improve the
tolerance of capacitance with a series R-C damper from output to ground;

When the LM35 is applied with a 200Ω load resistor it is relatively immune to wiring
capacitance because the capacitance forms a by- pass from ground to input, not on the output.
However, as with any linear circuit connected to wires in a hostile envi- ronment, its
performance can be affected adversely by in- tense electromagnetic sources such as relays,
radio trans- mitters, motors with arcing brushes, SCR transients, etc, as its wiring can act as a
receiving antenna and its internal junctions can act as rectifiers. For best results in such cases,
a bypass capacitor from VIN to ground and a series R-C damper such as 75Ω in series with 0.2
or 1 μF from output to ground are often useful.

3.6 FEATURES OF LM 35 TEMPERATURE SENSOR:

1.) Linear at 10.0 mV/°C scale factor


2.) 0.5°C accuracy guarantee-able (at a25°C)
3.) Rated for full -55°C to a 150°C range
4.) Suitable for remote applications
5.) Low cost due to wafer-level trimming
6.) Operates from 4 to 30 volts
7.) Less than 60 mA current drain
8.) Low self-heating, 0.08°C instill air
9.) Non-linearity only 0.25°C typical
10.)Low impedance output, 0.1Ωfor 1 mA load.

38
APPLICATIONS :

The TO-46 metal package can also be soldered to a metal surface or pipe without damage. Of
course, in that case the V− terminal of the circuit will be grounded to that metal. Alternatively,
the LM35 can be mounted inside a sealed-end metal tube, and can then be dipped into a bath
or screwed into a threaded hole in a tank. As with any IC, the LM35 and accompanying wiring
and circuits must be kept insulated and dry, to avoid leakage and corrosion. This is especially
true if the circuit may operate at cold temperatures where condensation can occur. Printed-
circuit coatings and varnishes such as Humiseal and epoxy paints or dips are often used to
insure that moisture cannot corrode the LM35 or its connections.
These devices are sometimes soldered to a small light-weight heat fin, to decrease the thermal
time constant and speed up the response in slowly-moving air. On the other hand, a small
thermal mass may be added to the sensor, to give the steadiest reading despite small deviations
in the air temperature.
The LM35 can be applied easily in the same way as other integrated-circuit temperature
sensors. It can be glued or cemented to a surface and its temperature will be within about 0.01 ̊C
of the surface temperature.
This presumes that the ambient air temperature is almost the same as the surface temperature;
if the air temperature were much higher or lower than the surface temperature, the actual
temperature of the LM35 die would be at an intermediate temperature between the surface
temperature and the air temperature. This is especially true for the TO-92 plastic package,
where the copper leads are the principal thermal path to carry heat into the device, so its
temperature might be closer to the air temperature than to the surface temperature.
To minimize this problem, be sure that the wiring to the LM35, as it leaves the device, is held
at the same tempera- ture as the surface of interest. The easiest way to do this is to cover up
these wires with a bead of epoxy which will insure that the leads and wires are all at the same
temperature as the surface, and that the LM35 die’s temperature will not be affected by the air
temperature.

39
3.7 INTERFACING RELAYS WITH DC MOTOR:

3.7.1 DC MOTOR:

A DC motor is any of a class of rotary electrical machines that converts direct current electrical
energy into mechanical energy. The most common types rely on the forces produced by
magnetic fields. Nearly all types of DC motors have some internal mechanism, either
electromechanical or electronic, to periodically change the direction of current flow in part of
the motor.

DC motors were the first form of motor widely used, as they could be powered from existing
direct-current lighting power distribution systems. A DC motor's speed can be controlled over
a wide range, using either a variable supply voltage or by changing the strength of current in
its field windings. Small DC motors are used in tools, toys, and appliances. The universal motor
can operate on direct current but is a lightweight brushed motor used for portable power tools
and appliances. Larger DC motors are currently used in propulsion of electric vehicles, elevator
and hoists, and in drives for steel rolling mills.

3.7.2 Relay

A relay is usually an electromechanical device that is actuated by an electrical current.The


current flowing in one circuit causes the opening or closing of another circuit. Relays are like
remote-control switches and are used in many applications because of their relative simplicity,
long life, and proven high reliability. Relays are used in a wide variety of applications
throughout industry, such as in telephone exchanges, digital computers and automation
systems. Highly sophisticated relays are utilized to protect electric power systems against
trouble and power blackouts as well as to regulate and control the generation and distribution
of power. In the home, relays are used in refrigerators, washing machines and dishwashers, and
heating and air-conditioning controls. Although relays are generally associated with electrical
circuitry, there are many other types, such as pneumatic and hydraulic. Input may be electrical
and output directly mechanical, or vice versa

40
Types of Relays

Latching relay:

A latching relay (also called "impulse", "keep", or "stay" relays) maintains either contact
position indefinitely without power applied to the coil. The advantage is that one coil
consumes power only for an instant while the relay is being switched, and the relay contacts
retain this setting across a power outage. A latching relay allows remote control of building
lighting without the hum that may be produced from a continuously (AC) energized coil.
In one mechanism, two opposing coils with an over-center spring or permanent magnet
hold the contacts in position after the coil is de-energized. A pulse to one coil turns the relay
on and a pulse to the opposite coil turns the relay off. This type is widely used where control
is from simple switches or single-ended outputs of a control system, and such relays are
found inavionics and numerous industrial applications.

Mercury relay

A mercury relay is a relay that uses mercury as the switching element. They are used where
contact erosion would be a problem for conventional relay contacts. Owing to
environmental considerations about significant amount of mercury used and modern
alternatives, they are now comparatively uncommon.

Polarized relay

A polarized relay places the armature between the poles of a permanent magnet to increase
sensitivity. Polarized relays were used in middle 20th Centurytelephone exchanges to
detect faint pulses and correct telegraphic distortion. The poles were on screws, so a
technician could first adjust them for maximum sensitivity and then apply a bias spring to
set the critical current that would operate the relay.

41
Coaxial relay

Where radio transmitters and receivers share one antenna, often a coaxial relay is used as
a TR (transmit-receive) relay, which switches the antenna from the receiver to the
transmitter. This protects the receiver from the high power of the transmitter. Such
relays are often used in transceivers which combine transmitter and receiver in one unit.
The relay contacts are designed not to reflect any radio frequency power back toward the
source, and to provide very high isolation between receiver and transmitter terminals. The
characteristic impedance of the relay is matched to the transmission line impedance of the
system, for example, 50 ohms.[4]

Time Relay

Timing relays are arranged for an intentional delay in operating their contacts. A very
short (a fraction of a second) delay would use a copper disk between the armature and
moving blade assembly. Current flowing in the disk maintains magnetic field for a short
time, lengthening release time. For a slightly longer (up to a minute) delay, a dashpot is
used. A dashpot is a piston filled with fluid that is allowed to escape slowly; both air-filled
and oil-filled dashpots are used. The time period can be varied by increasing or decreasing
the flow rate. For longer time periods, a mechanical clockwork timer is installed. Relays
may be arranged for a fixed timing period, or may be field adjustable, or remotely set from
a control panel. Modern microprocessor-based timing relays provide precision timing over
a great range.

Contactor

A contactor is a heavy-duty relay used for switching electric motors and lighting loads,
but contactors are not generally called relays. Continuous current ratings for common
contactors range from 10 amps to several hundred amps. High-current contacts are made
with alloys containing silver. The unavoidable arcing causes the contacts to oxidize;
however, silver oxide is still a good conductor. Contactors with overload protection
devices are often used to start motors. Contactors can make loud sounds when they
operate, so they may be unfit for use where noise is a chief concern.

42
A contactor is an electrically controlled switch used for switching a power circuit, similar
to a relay except with higher current ratings. A contactor is controlled by a circuit which
has a much lower power level than the switched circuit.

Contactors come in many forms with varying capacities and features. Unlike a circuit breaker,
a contractor is not intended to interrupt a short circuit current. Contactors range from those
having a breaking current of several amperes to thousands of amperes and 24 V DC to many
kilovolts. The physical size of contactors ranges from a device small enough to pick up with
one hand, to large devices approximately a meter (yard) on a side

Solid state contactor relay

A solid state contactor is a heavy-duty solid state relay, including the necessary heat sink,
used where frequent on/off cycles are required, such as with electric heaters, small electric
motors, and lighting loads. There are no moving parts to wear out and there is no contact
bounce due to vibration. They are activated by AC control signals or DC control signals
from Programmable logic controller (PLCs), PCs, Transistor-transistor logic (TTL)
sources, or other microprocessor and microcontroller controls.

Buchholz relay

A Buchholz relay is a safety device sensing the accumulation of gas in large


oil- filled transformers, which will alarm on slow accumulation of gas or shut down the
transformer if gas is produced rapidly in the transformer oil. The contacts are not operated
by an electric current but by the pressure of accumulated gas or oil flow.

43
CHAPTER 4
SOFTWARE DESCRIPTION

4.1 INTRODUCTION TO KEIL SOFTWARE

ABOUT KEIL:

1. Click on the Keil u Vision4 Icon on Desktop


2. .The following fig will appear

3. Click on the Project menu from the title bar


4. Then Click on New Project

44
5. Save the Project by typing suitable project name with no extension in u r own folder
sited in either C:\ or D:\

6. Then Click on Save button above.


7. Select the component for u r project. i.e. Atmel……
8. Click on the + Symbol beside of Atmel

45
9. Select AT89S52 as shown below

10. Then Click on “OK”


11. The Following fig will appear

46
12. Then Click either YES or NO………mostly “NO”
13. Now your project is ready to USE
14. Now double click on the Target1, you would get another option “Source group
1” as shown in next page.

15. Click on the file option from menu bar and select “new”

47
16. The next screen will be as shown in next page, and just maximize it by double
clicking on its blue boarder.

17. Now start writing program in either in “C” or “ASM”


18. For a program written in Assembly, then save it with extension “. asm” and
for “C” based program save it with extension “ .C”

48
19. Now right click on Source group 1 and click on “Add files to Group Source”

20. Now you will get another window, on which by default “C” files will appear.

49
20. Now select as per your file extension given while saving the file
21. Click only one time on option “ADD”

22. Now Press function key F7 to compile. Any error will appear if so happen.

23. If the file contains no error, then press Control+F5 simultaneously.

50
24. The new window is as follows

25. Then Click “OK”


26. Now Click on the Peripherals from menu bar, and check your required port as
shown in fig below

27. Drag the port a side and click in the program file.

51
28. Now keep Pressing function key “F11” slowly and observe.
29. You are running your program successfully.

52
4.2 PROLOAD:

Proload is a software which accepts only hex files. Once the machine code is converted
into hex code, that hex code has to be dumped into the microcontroller placed in the
programmer kit and this is done by the Proload. Programmer kit contains a microcontroller on
it other than the one which is to be programmed. This microcontroller has a program in it
written in such a way that it accepts the hex file from the keil compiler and dumps this hex file
into the microcontroller which is to be programmed. As this programmer kit requires power
supply to be operated, this power supply is given from the power supply circuit designed above.
It should be noted that this programmer kit contains a power supply section in the board itself
but in order to switch on that power supply, a source is required. Thus this is accomplished
from the power supply board with an output of 12volts or from an adapter connected to 230 V
AC.

4.2.1 STEPS TO WORK WITH PROLOAD:

1. Install the Proload Software in the PC.


2. Now connect the Programmer kit to the PC (CPU) through serial cable.
3. Power up the programmer kit from the ac supply through adapter.
4. Now place the microcontroller in the GIF socket provided in the programmer kit.
5. Click on the Proload icon in the PC. A window appears providing the information like
Hardware model, com port, device type, Flash size etc. Click on browse option to select
the hex file to be dumped into the microcontroller and then click on “Auto program” to
program the microcontroller with that particular hex file.
6. The status of the microcontroller can be seen in the small status window in the bottom
of the page.
7. After this process is completed, remove the microcontroller from the programmer kit
and place it in your system board. Now the system board behaves according to the
program written in the microcontroller.

53
CHAPTER
RESULTS AND CONCLUSION

54
55
56
CONCLUSION AND FUTURE SCOPE

The temperature is measured and it is controlled by using a dc motor of 5v. It can be directly
connected to the motor of a ceiling fan or an air conditioner fan such that they works
automatically .This project solves day to day usage of fans and A/c as it can control them and
also this project can be used in many places where certain amount of temperature should be
maintained for research purposes and many more. This can be implemented in many areas such
as it can be used in Apartments, Seminar Halls ,Libraries and many other places .In future this
project can be implemented as home automation. A GPS module can be interfaced to this and
the person can control it even by sending an message which helps to save power.

57
APPENDIX

#include<reg51.h>
#define lcd_data P2
sbit lcd_rs = P2^0;
sbit lcd_en = P2^1;
sbit cs=P1^0; //ADC temp
sbit din=P1^1;
sbit dout=P1^2;
sbit clk=P1^3;
sbit relay1 = P1^4;
sbit relay2 = P1^5;
sbit relay3 = P1^6;

unsigned convert(unsigned int);


unsigned convert1(unsigned int);

void delay(unsigned int t)


{
unsigned int i,j;
for(i=0;i<t;i++)
for(j=0;j<200;j++);
}

void lcdcmd(unsigned char value) // LCD COMMAND


{

58
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
}

void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/

lcdcmd(0x0e); //cursor blinking


lcdcmd(0x06); //move the cursor to right side
lcdcmd(0x01); //clear the lcd

void lcddata(unsigned char value)

lcd_data=value&(0xf0); //send msb 4 bits


lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
59
delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
delay(3);
lcd_en=0;

delay(3);
}

void sertx(unsigned char tx)


{

SBUF=tx;
while(TI == 0);
TI=0;

void msgdisplay(unsigned char b[]) // send string to lcd


{
unsigned char s,count=0;
for(s=0;b[s]!='\0';s++)
{
count++;
if(s==16)
lcdcmd(0xc0);
if(s==32)
{
lcdcmd(1);
count=0;
60
}
lcddata(b[s]);
}
}

void serinit()
{
TMOD=0x20;
TH1=0xFD; //9600
SCON=0x50;
TR1=1;
}

void main()
{
unsigned char rtr=0;

P2=0xff;

clk=0;
din=0;
dout=0;
cs=0;

relay1=relay2=relay3=0;

serinit();

lcd_init();
61
msgdisplay(" Welcome ");
delay(100);
lcdcmd(1);
msgdisplay("Temp:"); //0x86

while(1)
{

cs=1;
delay(10);
cs=0;
delay(10);
powerup(0);

temp = ((read_mcp3202()/43) + 3);


temp = (temp+4);
lcdcmd(0x86);
convert(temp);
if(temp < 25)
{
lcdcmd(0xc0);msgdisplay("Level-0");

relay1=1;
relay2=0;
relay3=0;
}

if(temp > 25 && temp < 35)


{
lcdcmd(0xc0);msgdisplay("Level-1");

relay1=1;
relay2=0;
62
relay3=0;
}

if(temp > 35 && temp < 45)


{
lcdcmd(0xc0);msgdisplay("Level-2");

relay1=0;
relay2=1;
relay3=0;
}

if(temp > 45)


{

lcdcmd(0xc0);msgdisplay("Level-3");

relay1=0;
relay2=0;
relay3=1;
}

}
}

unsigned convert1(unsigned int value)


{
unsigned int i,j,x,k,l;
i=value/100;
x=i|0x30;
63
sertx(x); // converts the data to digital as per the address selection

j=value%100;
k=j/10;
x=k|0x30;
sertx(x);

l=j%10;
x=l|0x30;
sertx(x);
return 1;
}

unsigned convert(unsigned int value)


{
unsigned int i,j,x,k,l;
i=value/100;
x=i|0x30;
lcddata(x); // converts the data to digital as per the address selection

j=value%100;
k=j/10;
x=k|0x30;
lcddata(x);

l=j%10;
x=l|0x30;
lcddata(x);
return 1;
}

64
REFERNCES

1) https://ieeexplore.ieee.org/document/7975074
2) The 8051 Microcontroller and Embedded Systems: Using Assembly and C by
Mohammed Ali Mazdi
3) https://www.engineersgarage.com/electronic-components/16x2-lcd-module-datasheet
4) R. Van Nieuwenhove and L. Vermeeren, “Irradiation effects on temperature sensors for
ITER application,” Rev. Sci. Instrum.,
5) Tools for Physiology Labs: An Inexpensive Means of Temperature Control, Jacob
L.Krans and Ronald R.Hoy, the Journal of Undergraduate Neuroscience Education,
fall 2005, 4(1) A22-A26Datasheet:
6) Rose G (1983) A temperature controller for in vitro recording chambers. Brain Res
Bull10:713-714
7) Muhammad Imran and A. Bhattacharyya, “Thermal response of an on-chip assembly
of RTD heaters, sputtered sample and microthermocouples,” Sensors and Actuators

65

Das könnte Ihnen auch gefallen