You are on page 1of 36

CHAPTER-1

INTRODUCTION

1.1 Introduction to Embedded Systems:

An embedded system is a combination of software and hardware to perform a


dedicated task. Some of the main devices used in embedded products are
Microprocessors and Microcontrollers. Microprocessors are commonly referred to as
general purpose processors as they simply accept the inputs, process it and give the
output.

In contrast, a microcontroller not only accepts the data as inputs but also
manipulates it, interfaces the data with various devices, controls the data and thus
finally gives the result. As everyone in this competitive world prefers to make the
things easy and simple to handle, this project sets an example to some extent.

An embedded system can be defined as a computing device that does a


specific focused job. Appliances such as the air-conditioner, VCD player, DVD
player, printer, fax machine, mobile phone etc. are examples of embedded systems.
The embedded software is also called “firm ware”. The desktop/laptop computer is a
general purpose computer. You can use it for a variety of applications such as playing
games, word processing, accounting, software development and so on. In contrast, the
software in the embedded systems is always fixed listed below:

Embedded systems do a very specific task; they cannot be programmed to do


different things. Embedded systems have very limited resources, particularly the
memory. Generally, they do not have secondary storage devices such as the CDROM
or the floppy disk. Embedded systems have to work against some deadlines. A
specific job has to be completed within a specific time. In some embedded systems,
called real-time systems, the deadlines are stringent. Missing a deadline may cause a
catastrophe-loss of life or damage to property. Embedded systems are constrained for
power. As many embedded systems operate through a battery, the power consumption
has to be very low.

1
Application Areas:

Nearly 99 per cent of the processors manufactured end up in embedded


systems. The embedded system market is one of the highest growth areas as these
systems are used in very market segment- consumer electronics, office automation,
industrial automation, biomedical engineering, wireless communication data
communication, telecommunications, and transportation, military and so on.

Industrial automation:

Today a lot of industries use embedded systems for process control. These
include pharmaceutical, cement, sugar, oil exploration, nuclear energy, electricity
generation and transmission. The embedded systems for industrial use are designed to
carry out specific tasks such as monitoring the temperature, pressure, humidity,
voltage, current etc., and then take appropriate action based on the monitored levels to
control other devices or to send information to a centralized monitoring station. In
hazardous industrial environment, where human presence has to be avoided, robots
are used, which are programmed to do specific jobs. The robots are now becoming
very powerful and carry out many interesting and complicated tasks such as hardware
assembly.

Security:

Security of persons and information has always been a major issue. We need
to protect our homes and offices; and also the information we transmit and store.
Developing embedded systems for security applications is one of the most lucrative
businesses nowadays. Security devices at homes, offices, airports etc. for
authentication and verification are embedded systems. Encryption devices are nearly
99 per cent of the processors that are manufactured end up in~ embedded systems.
Embedded systems find applications in. every industrial segment - consumer
electronics, transportation, avionics, biomedical engineering, manufacturing, process
control and industrial automation, data communication, telecommunication, defense,
security etc.

2
1.2 BLOCK DESCRIPTION

FIG 1.2: BLOCK DIAGRAM

The surrounding temperature is sensed by the temperature controller


which is in analog form but the input to the microcontroller is digital signal.
So, we use ADC converter whose digital output is given to the
microcontroller.LCD is interfaced to the microcontroller so the temperature will
be displayed on the LCD. Based on the program dumped in the microcontroller
if the temperature of the surroundings exceeds a pre-defined value then the
driver circuit will be enabled which based on the switching action of relay
will switch ON the appliance connected to it.

1.2.1 Power Supply:

The input to the circuit is applied from the regulated power supply. The a.c.
input i.e., 230V from the mains supply is step down by the transformer to 12V and is

3
fed to a rectifier. The output obtained from the rectifier is a pulsating d.c voltage. So
in order to get a pure d.c voltage, the output voltage from the rectifier his fed to a
filter to remove any a.c components present even after rectification. Now, this voltage
is given to a voltage regulator to obtain a pure constant dc voltage

Fig 1.2.1: Power supply

Transformer:

Usually, DC voltages are required to operate various electronic equipment and


these voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly.

Thus the a.c input available at the mains supply i.e., 230V is to be brought down to
the required voltage level. This is done by a transformer. Thus, a step down
transformer is employed to decrease the voltage to a required level.

Rectifier:

The output from the transformer is fed to the rectifier. It converts A.C. into
pulsating D.C. The rectifier may be a half wave or a full wave rectifier. In this project,
a bridge rectifier is used because of its merits like good stability and full wave
rectification.

Filter:

Capacitive filter is used in this project. It removes the ripples from the output
of rectifier and smoothens the D.C. Output received from this filter is constant until

4
the mains voltage and load is maintained constant. However, if either of the two is
varied, D.C. voltage received at this point changes. Therefore a regulator is applied at
the output stage

Voltage regulator:
As the name itself implies, it regulates the input applied to it. A voltage
regulator is an electrical regulator designed to automatically maintain a constant
voltage level. In this project, power supply of 5V and 12V are required. In order to
obtain these voltage levels, 7805 and 7812 voltage regulators are to be used. The first
number 78 represents positive supply and the numbers 05, 12 represent the required
output voltage levels.

5
CHAPTER-2

INTRODUCTION

2.1 Introduction To Microcontrollers:

Microprocessors and microcontrollers are widely used in embedded systems


products. Microcontroller is a programmable device. A microcontroller has a CPU in
addition to a fixed amount of RAM, ROM, I/O ports and a timer embedded all on a
single chip. The fixed amount of on-chip ROM, RAM and number of I/O ports in
microcontrollers makes them ideal for many applications in which cost and space are
critical.

The Intel 8051 is Harvard architecture, single chip microcontroller (µC) which
was developed by Intel in 1980 for use in embedded systems. It was popular in the
1980s and early 1990s, but today it has largely been superseded by a vast range of
enhanced devices with 8051-compatible processor cores that are manufactured by
more than 20 independent manufacturers including Atmel, Infineon Technologies and
Maxim Integrated Products.

8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of
data at a time. Data larger than 8 bits has to be broken into 8-bit pieces to be
processed by the CPU. 8051 is available in different memory types such as UV-
EPROM, Flash and NV-RAM.

The present project is implemented on Keil Uvision. In order to program the device,
proload tool has been used to burn the program onto the microcontroller.

The features, pin description of the microcontroller and the software tools used
are discussed in the following sections.

6
2.2 FEATURES OF AT89S52:

 8K Bytes of FLASH memory

 128 Bytes of internal RAM

 4.5V to 5.5V Operating Range

 32 Programmable I/O Lines

 Three 16-bit Timer/Counter

 Full Duplex Serial UART Channel

 Interrupt recovery for Power-down Mode

 Flexible and cost effective

7
Fig 2.2 Block diagram AT89S52

DESCRIPTION:

The AT89S52 is a low-voltage, high-performance CMOS 8-bit microcomputer


with 8K bytes of Flash memory. The device is manufactured using Atmel’s high-
density nonvolatile memory technology and is compatible with the industry-standard
MCS-51 instruction set. By combining a versatile 8-bit CPU with Flash on a
monolithic chip, the Atmel AT89S52 is a powerful microcomputer, which provides a
highly flexible and cost-effective solution to many embedded control applications.

In addition, the AT89S52 is designed with static logic for operation down to
zero frequency and supports two software selectable power saving modes. The Idle
Mode stops the CPU while allowing the RAM, timer/counters, serial port and
interrupt system to continue functioning. The power-down mode saves the RAM
contents but freezes the oscillator disabling all other chip functions until the next
hardware reset.

2.3 PIN DESCRIPTION:

Fig 2.3 Pin Diagram of AT89S52

8
Vcc: Pin 40 provides supply voltage to the chip. The voltage source is +5V.

GND: Pin 20 is the ground.

XTAL1 and XTAL2:

XTAL1 and XTAL2 are the input and output, respectively, of an inverting
amplifier that can be configured for use as an on-chip oscillator, as shown in Figure
11. Either a quartz crystal or ceramic resonator may be used. To drive the device from
an external clock source, XTAL2 should be left unconnected while XTAL1 is driven,
as shown in the below figure. There are no requirements on the duty cycle of the
external clock signal, since the input to the internal clocking circuitry is through a
divide-by-two flip-flop, but minimum and maximum voltage high and low time
specifications must be observed.

Fig 2.3 Oscillator Connections


C1, C2 = 30 pF ± 10 pF for Crystals
= 40 pF ± 10 pF for Ceramic Resonators

Fig 2.3.1 External Clock Drive Configuration

9
RESET:

Pin9 is the reset pin. It is an input and is active high. Upon applying a high
pulse to this pin, the microcontroller will reset and terminate all the activities. This is
often referred to as a power-on reset.

EA (External access):

Pin 31 is EA. It is an active low signal. It is an input pin and must be


connected to either Vcc or GND but it cannot be left unconnected.

The 8051 family members all come with on-chip ROM to store programs. In
such cases, the EA pin is connected to Vcc.

2.4 Machine cycle for the 8051:

The CPU takes a certain number of clock cycles to execute an instruction. In


the 8051 family, these clock cycles are referred to as machine cycles. The length of
the machine cycle depends on the frequency of the crystal oscillator. The crystal
oscillator, along with on-chip circuitry, provides the clock source for the 8051 CPU.

The frequency can vary from 4 MHz to 30 MHz, depending upon the chip
rating and manufacturer. But the exact frequency of 11.0592 MHz crystal oscillator is
used to make the 8051 based system compatible with the serial port of the IBM PC.

In the original version of 8051, one machine cycle lasts 12 oscillator periods.
Therefore, to calculate the machine cycle for the 8051, the calculation is made as 1/12
of the crystal frequency and its inverse is taken.

The assembly language program is written and this program has to be dumped
into the microcontroller for the hardware kit to function according to the software.
The program dumped in the microcontroller is stored in the Flash memory in the
microcontroller. Before that, this Flash memory has to be programmed and is
discussed in the next section.

10
ALE/PROG:

Address Latch Enable is an output pulse for latching the low byte of the
address during accesses to external memory. This pin is also the program pulse input
(PROG) during Flash programming. In normal operation, ALE is emitted at a
constant rate of 1/6 the oscillator frequency and may be used for external timing or
clocking purposes. If desired, ALE operation can be disabled by setting bit 0 of SFR
location 8EH. With the bit set, ALE is active only during a MOVX or MOVC
instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has
no effect if the microcontroller is in external execution mode.

PSEN (Program Store Enable):

It is the read strobe to external program memory. When the AT89S8252 is


executing code from external program memory, PSEN is activated twice each
machine cycle, except that two PSEN activations are skipped during each access to
external data memory.

EA/VPP (External Access Enable):

EA must be strapped to GND in order to enable the device to fetch code from
external program memory locations starting at 0000H up to FFFFH. Note, however,
that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be
strapped to VCC for internal program executions. This pin also receives the 12-volt
programming enable voltage (VPP) during Flash programming when 12-volt
programming is selected.

Ports 0, 1, 2 and 3:

The four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports.
All the ports upon RESET are configured as input, since P0-P3 have value FFH on
them.

Port 0(P0):

Port 0 is also designated as AD0-AD7, allowing it to be used for both address


and data. ALE indicates if P0 has address or data. When ALE=0, it provides data D0-

11
D7, but when ALE=1, it has address A0-A7. Therefore, ALE is used for
demultiplexing address and data with the help of an internal latch.

When there is no external memory connection, the pins of P0 must be


connected to a 10K-ohm pull-up resistor. This is due to the fact that P0 is an open
drain. With external pull-up resistors connected to P0, it can be used as a simple I/O,
just like P1 and P2. But the ports P1, P2 and P3 do not need any pull-up resistors
since they already have pull-up resistors internally. Upon reset, ports P1, P2 and P3
are configured as input ports.

Port 1:

Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1
output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins,
they are pulled high by the internal pull-ups and 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.

Some Port 1 pins provide additional functions. P1.0 and P1.1 can be
configured to be the timer/counter 2 external count input (P1.0/T2) and the
timer/counter 2 trigger input (P1.1/T2EX), respectively. Furthermore, P1.4, P1.5,
P1.6, and P1.7 can be configured as the SPI slave port select, data input/output and
shift clock input/output pins

Table 2.4.1 Port1 Alternate functions

12
Programmable Clock Out:

A 50% duty cycle clock can be programmed to come out on P1.0. This pin,
besides being a regular I/0 pin, has two alternate functions. It can be programmed to
input the external clock for Timer/Counter 2 or to output a 50% duty cycle clock
ranging from 61 Hz to 4 MHz (for a 16-MHz operating frequency).

Port 2
With no external memory connection, P2 are used as simple I/O. With external
memory connections, port 2 must be used along with P0 to provide the 16-bit address
for the external memory. Port 2 is designated as A8-A15 indicating its dual function.
While P0 provides the lower 8 bits via A0-A7, it is the job of P2 to provide bits A8-
A15 of the address.

Port 2 also receives the high-order address bits and some control signals
during Flash programming and verification.

Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 3
output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins,
they are pulled high by the internal pull-ups and can be used as inputs. As inputs, Port
3 pins that are externally being pulled low will source current because of the pull-ups.
Port 3 receives some control signals for Flash programming and verification.

Port 3 also serves the functions of various special features of the AT89S8252,
as shown in the following Table 2.4.2 Port 3 Alternate functions

13
2.5 Data Memory – EEPROM and RAM

The AT89S52 implements 8K bytes of on-chip EEPROM for data storage and
256 bytes of RAM. The upper 128 bytes of RAM occupy a parallel space to the
Special Function Registers i.e., the upper 128 bytes have the same addresses as the
SFR space but are physically separate from SFR space.

When an instruction accesses an internal location above address 7FH, the


address mode used in the instruction specifies whether the CPU accesses the upper
128 bytes of RAM or the SFR space.

14
CHAPTER-3

CIRCUIT DIAGRAM

Fig 3: Circuit Diagram

3.1 RELAYS:

A relay is an electrically controllable switch widely used in industrial controls,


automobiles and appliances.

15
The relay allows the isolation of two separate sections of a system with two different
voltage sources i.e., a small amount of voltage/current on one side can handle a large
amount of voltage/current on the other side but there is no chance that these two
voltages mix up.

Inductor

Fig 3.1 Circuit symbol of a relay

3.1.1 Operation:

When a current flow through the coil, a magnetic field is created around the
coil i.e., the coil is energized. This causes the armature to be attracted to the coil. The
armature’s contact acts like a switch and closes or opens the circuit. When the coil is
not energized, a spring pulls the armature to its normal state of open or closed. There
are all types of relays for all kinds of applications. Transistors and ICs must be
protected from the brief high voltage 'spike' produced when the relay coil is switched
off. The above diagram shows how a signal diode (e.g. 1N4148) is connected across
the relay coil to provide this protection the diode is connected 'backwards' so that it
will normally not conduct.

16
Fig 3.1.1 Relay Operation and use of protection diodes

Conduction occurs only when the relay coil is switched off, at this moment the
current tries to flow continuously through the coil and it is safely diverted through the
diode.

In choosing a relay, the following characteristics need to be considered:

1. The contacts can be normally open (NO) or normally closed (NC). In the NC type,
the contacts are closed when the coil is not energized. In the NO type, the contacts are
closed when the coil is energized.

2. There can be one or more contacts. i.e., different types like SPST (single pole
single throw), SPDT (single pole double throw) and DPDT (double pole double
throw) relay.

3. The voltage and current required to energize the coil. The voltage can vary from a
few volts to 50 volts, while the current can be from a few milliamps to 20milliamps.
The relay has a minimum voltage, below which the coil will not be energized. This
minimum voltage is called the “pull-in” voltage.

4. The minimum DC/AC voltage and current that can be handled by the contacts. This
is in the range of a few volts to hundreds of volts, while the current can be from a few
amps to 40A or more, depending on the relay.

17
3.2 TRANSISTOR DRIVER CIRCUIT:

An SPDT relay consists of five pins, two for the magnetic coil, one as the
common terminal and the last pins as normally connected pin and normally closed
pin. When the current flows through this coil, the coil gets energized. Initially when
the coil is not energized, there will be a connection between the common terminal and
normally closed pin. But when the coil is energized, this connection breaks and a new
connection between the common terminal and normally open pin will be established.
Thus when there is an input from the microcontroller to the relay, the relay will be
switched on. Thus when the relay is on, it can drive the loads connected between the
common terminals and normally open pin. Therefore, the relay takes 5V from the
microcontroller and drives the loads which consume high currents. Thus the relay acts
as an isolation device.

Digital systems and microcontroller pins lack sufficient current to drive the
relay. While the relay’s coil needs around 10milli amps to be energized, the
microcontroller’s pin can provide a maximum of 1-2milli amps current. For this
reason, a driver such as a power transistor is placed in between the microcontroller
and the relay.

3.3 RELAY INTERFACING WITH THE MICROCONTROLLER:

DRIVER
AT 89S52 LOAD
RELAY
CIRCUIT

Fig 3.3 Relay interfacing with microcontroller

18
CHAPTER-4

Introduction to LCD

4.1 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.

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.

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).

19
Their function is described in the table 4.1 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

4.2 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

20
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).

Fig 4.2: LCD Screen

4.2.1 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 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:

21
Table 4.2.1LCD Commands

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

I/
Entry mode set 0 0 0 0 0 0 0 1 S 40uS
D

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

22
4.2.2 LCD Initialization:

Once the power supply is turned on, LCD is automatically cleared. This
process lasts for approximately 15mS. After that, display is ready to operate. The
mode of operating is set by default. This means that:

1. Display is cleared

2. Mode
DL = 1 Communication through 8-bit interface
N = 0 Messages are displayed in one line
F = 0 Character font 5 x 8 dots

3. Display/Cursor on/off
D = 0 Display off
U = 0 Cursor off
B = 0 Cursor blink off

4. Character entry
ID = 1 Addresses on display are automatically incremented by 1
S = 0 Display shift off

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
cannot 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.

23
4.3 LCD INTERFACING WITH THE MICROCONTROLLER:

Vcc

P2 4 (RS)
Gn
.0 1
d
P2 5 (R/W)
.1 2 PRESET

P2 6(EN) (CONTRA
.2 3 ST
CONTROL
)

LCD
Vcc
FOR
Gn BACKLIGHT
PURPOSE

Fig4.3: LCD interfacing with Microcontroller

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

24
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
// e.g.
//
// LCD_command(0x01);

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

CODE:

25
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
// e.g.
//
// LCD_senddata('A');

26
Conclusion
This Project proposes the design, development and construction of “AUTOMATIC
TEMPERATURE CONTROLLED SYSTEM” which is widely used for many
domestic applications. It proves to be worthy in many industrial and general purposes.
The project has be carried out carefully and tested to provide required results.

27
Bibliography

Books:

The 8051 microcontroller and embedded system

- M.A.Mazidi & J.G.mazidi


The microcontroller idea book

-John Axelson
Digital design
-Morris Mano

Linear Integrated circuits


-Roy Choudary

Web Links:

www.Electronic projects.com

www.8051.com

www.microcontroller.com

www.embeded systems.com

www.TDG.com

28
APPENDIX

KEIL SOFTWARE:

Keil compiler is software used where the machine language code is written and
compiled. After compilation, the machine source code is converted into hex code
which is to be dumped into the microcontroller for further processing. Keil compiler
also supports C language code.

Steps to write an assembly language program in keil and how to compile it:

1. Install the Keil Software in the PC in any of the drives.

2. After installation, an icon will be created with the name “Keil uVision3”. Just
drag this icon onto the desktop so that it becomes easy whenever you try to
write programs in keil.

3. Double click on this icon to start the keil compiler.

4. A page opens with different options in it showing the project workspace at the
leftmost corner side, output window in the bottom and an ash coloured space
for the program to be written.

5. Now to start using the keil, click on the option “project”.

6. A small window opens showing the options like new project, import project,
open project etc. Click on “New project”.

7. A small window with the title bar “Create new project” opens. The window
asks the user to give the project name with which it should be created and the
destination location. The project can be created in any of the drives available.
You can create a new folder and then a new file or can create directly a new
file.

8. After the file is saved in the given destination location, a window opens where
a list of vendors will be displayed and you have to select the device for the
target you have created.

29
9. The most widely used vendor is Atmel. So click on Atmel and now the family
of microcontrollers manufactured by Atmel opens. You can select any one of
the microcontrollers according to the requirement.

10. When you click on any one of the microcontrollers, the features of that
particular microcontroller will be displayed on the right side of the page. The
most appropriate microcontroller with which most of the projects can be
implemented is the AT89S52. Click on this microcontroller and have a look at
its features. Now click on “OK” to select this microcontroller.

11. A small window opens asking whether to copy the startup code into the file
you have created just now. Just click on “No” to proceed further.

12. Now you can see the TARGET and SOURCE GROUP created in the project
workspace.

13. Now click on “File” and in that “New”. A new page opens and you can start
writing program in it.

14. After the program is completed, save it with any name but with the.asm
extension. Save the program in the file you have created earlier.

15. You can notice that after you save the program, the predefined keywords will
be highlighted in bold letters.

16. Now add this file to the target by giving a right click on the source group. A
list of options open and in that select “Add files to the source group”. Check
for this file where you have saved and add it.

17. Right click on the target and select the first option “Options for target”. A
window opens with different options like device, target, output etc. First click
on “target”.
18. Since the set frequency of the microcontroller is 11.0592 MHz to interface
with the PC, just enter this frequency value in the Xtal (MHz) text area and put
a tick on the Use on-chip ROM. This is because the program what we write
here in the keil will later be dumped into the microcontroller and will be stored
in the inbuilt ROM in the microcontroller.
19. Now click the option “Output” and give any name to the hex file to be created
in the “Name of executable” text area and put a tick to the “Create HEX file”

30
option present in the same window. The hex file can be created in any of the
drives. You can change the folder by clicking on “Select folder for Objects”.

20. Now to check whether the program you have written is errorless or not, click
on the icon exactly below the “Open file” icon which is nothing but Build
Target icon. You can even use the shortcut key F7 to compile the program
written.

21. To check for the output, there are several windows like serial window,
memory window, project window etc. Depending on the program you have
written, select the appropriate window to see the output by entering into debug
mode.
22. The icon with the letter “d” indicates the debug mode.

23. Click on this icon and now click on the option “View” and select the
appropriate window to check for the output.

24. After this is done, click the icon “debug” again to come out of the debug
mode.

25. The hex file created as shown earlier will be dumped into the microcontroller
with the help of software called Proload.

PROLOAD:

Proload is 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.

31
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. 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.

32
CODING:

#include<reg52.h>

#include<Lcd.h>

Sbit E1=p1^0;

Sbit I1=p1^1;

Sbit I2=p1^2;

Sbit INTR=p1^4;

#define ADCDATA p3

Void DispDec_DATA(unsigned char Adc_value);

Void Move_Motor();

Void delay_see();

Void main()

Unsigned char Adc_value;

Unsigned int i;

Lcd_initial();

Lcd_in(0x01,0);

Disp_Message(“Project by”,0x80);

Disp_Message(“SHALINI & SAHITHYA”,0xC0)

for(i=0,i<40,i++)

Lcd_in (0x18,0);

33
Delay_see();

}
Lcd in (0x01,0);

Disp_Message(“Temp value”,0x80);

While(1)

Lcd_in(0xC5,0);

INTR=0

Delay_us(40);

INTR=1

Adc_value=ADCDATA;

DispDEC_DATA(Adc_value);

for(i=0;i<1275;i++);

Void move_motor()

Unsigned char i;

for(i=0;i<50;i++)

E1=1;

I1=1;

I2=0;

34
}

Void DispDEC_Data(unsigned char Adc_value);

Unsigned char b,d,T;

Unsigned char code k[16]={“0123456789ABCDEF”};

b=Adc_value&0*F0;

b=b>>4;

b=b*16;

Adc_value=Adc_value & 0*0F;

b=b+Adc_value;

b=b*2;

T=b;

d=b/100;

Lcd_in(k[d],1);

b=b/100;

Lcd_in(k[b],1);

b=b%100;

d=b/10;

Lcd_in(k[d],1);

b=b%10;

Lcd_in(k[b],1);

if (T>40)

Move_motor();

35
Else

E1=0;

I1=0;

I2=0;

36

You might also like