You are on page 1of 65

A

PROJECT REPORT
ON

“TEMPERATURE SENSOR”
IN CONTEXT WITH “WESTERN MODELS”

BHILAI(C.G)
Submitted in the partial fulfillment for the award of degree

OF

DIPLOMA IN ELECTRICAL

Of
CHATTISGARH SWAMI VIVEKANANDA TECHNICAL UNIVERSITY

Session 2009-2010
Submitted by GUIDED
BY

ABHISHEK KUMAR

6TH SEM

DEPARTMENT OF ELECTRICAL
DURG POLYTECHNIC

1
Declaration
I Abhishek kumar student of sixth semester at
“Govt. polly durg “ her by declare that these
research report under the title is the record of
my original work under the guidance of
These report has never been submitted
anywhere for award of any diploma.

Place:

Date:

Department of electrical engg.


Govt. polytechnic durg

2
Certificate

This is to certify that Abhishek kumar


a student of electrical sixth semester at
our institute under my guidance and
supervision he had carried out the
research project under title

“ measuring temperature using


sensor “

This research report is the original one.


Place:
Date :
Project guide
(lecturer)
3
Department of electrical
engg.
Acknowledgement

Perhaps the most awaited moment of any


endeavor in its successful competition of their
project report cases study having worked on her
project for the whole academic session. I would like
to express my sincere gratitude to all those who
made it possible.

Firstly I am humbly and respectfully to my


guide
Mr. s.k. singh(H.O.D) of the electrical
department under whose able guidance. I had the
privilege to work and who guided at every stage.

I take this opportunity to express my sincere


gratitude to our principle for being guide of
philosopher throughout diploma program.
4
I shall be failing in my duty if I don’t express
my deep sense of gratitude to all my friends and
the relatives who have share their valuable time
and helped me directly or indirectly in the
preparation of their project .

At the end last but not the least, I would like to


thanks the other staff and non staff member of this
college.

Index
Page no

5
Chapte Introduction 7-8
r -1 Temperature
Chapte sensor
r -2 Software
Chapte aspects
r -3 HD44780U
Chapte (LCD)
r -4 8-bit Micro
Chapte controller
r -5 AD Converter
Chapte Coding
r -6
Conclusion
Chapte
Bibliography
r -7
Chapte
r- 8
Chapte
6
r -9

7
Introduction
 How to select a controller?
The following items should be considered when
selecting a controller:

8
– Type of input sensor (thermocouple, RTD) and
temperature range
– Type of output required (electromechanical relay
or analog output)
– Control algorithm needed (on/off, proportional,
PID)
– Number and type of outputs (heat, cool, alarm,
limit)

 Different types of controllers:


• On/Off controller
• Proportional controller
• PID controller

9
Topics of Discussion

 Introduction
 Temperature sensors
 Software aspects
 HD44780U (LCD-II)
 8-bit Microcontroller

 A/D Converters

 Coding

10
11
Temperature
sensors
 Temperature Sensors are the devices which are used
to measure the temperature of an object.

 These sensors sense the temperature and generate


output signals in one of the two forms: change in
voltage or change in resistance.

 In order to select a sensor for a particular application


- accuracy, range of temperature, response time and
environment are considered.

Types of temperature sensors


 Temperature sensors are categorized into two types:
– Contact type sensors
– Non-Contact type sensors

 Contact type sensors:


These measure their own temperature i.e., they are
in contact with the metal and will be in thermal
equilibrium.

 Non-Contact type:
These infer temperature by measuring the thermal
radiations emitted by the material.
12
 Contact type sensors:

 RTD (Resistance Temperature Detector)

 Thermocouple

 Non-Contact type sensors:

 IR thermometers
-These measure the temperature by detecting the
infrared energy emitted by the material.
-This consists of a lens which senses the IR signal and
converts it into electrical signal which is displayed in
temperature units.
-These are applied when the object is moving,
surrounded by EM field or when a fast response is
required.

Thermocouple Temperature
Measurement Sensors
 Principle of operation:
Thermocouples work on the principle of
Seebeck effect.
 They are available in bead type or probe type
construction.
 They consist of two junctions: cold junction and
hot junction.
13
 The voltage developed between two junctions
is called Seebeck voltage.
 Voltage is in the order of mill volts.
They generate energy in the order of microwatts-
mill watt

14
Thermocouples
Theory of operation:
– Figure 1 shows the typical Type-J
thermocouple.
– The emf shown in the figure is the Seebeck
voltage which is developed because of the
temperature difference.
– Figure 2 shows the cold junction
compensation (CJC).

15
Calculations:
The voltage generated by the thermocouple is
given by the equation:
V= S* ΔT
Where, V= voltage measured (V)
S= Seebeck coefficient (V/°C)
ΔT= difference in temperature between
two junctions
Hence the unknown temperature can be calculated
using the equation,
T= Tref + V/S in °C

16
17
 Resistance Temperature Detectors
(RTDs)

 They work on the principle of positive


temperature coefficient.
 RTDs are used to measure the temperatures
ranging from -196 to 482 deg C or (-320 to 900
deg Fahrenheit)
 Common Resistance Materials for RTDs:
• Platinum (most popular and accurate)
• Nickel
• Copper
• Balco (rare)
18
• Tungsten (rare)
Advantages:
• Stable output for a long period of time
• Ease of recalibration
• Accurate readings over narrow
temperature range
• Linear output

Disadvantages:
• Smaller temperature range when
compared to thermocouples
• High initial cost and less rugged to
environmental vibrations
• Not self-powered
• Self heating
Applications:
• They are used for precision process
temperature control.
• Widely used in industrial applications.

19
• Directly used in recorders, temperature
controllers, transmitters and digital
ohmmeters

Thermistors
 These are similar to RTDs.

 These work on negative temperature


coefficient.
 These are made up of semiconductor devices.

 Variation is non-linear.
 Thermistors are used to measure the
temperatures ranging from -45 to 260 deg C or
(-50 to 500 deg Fahrenheit).

20
Advantages:
• High output
• Fast response
• Two wire ohms measurement

Disadvantages:
• Non-linear
• Limited temperature range
• Not self-powered
Self heating

Applications:
• Can be used as a liquid level indicator or as a
liquid level controller
• To measure temperature in Medical Applications

21
• Temperature Control

22
Software aspect

(Thermistor and RTD application)

• Application of RTD for detecting the


environment temperature.
• This uses the microcontroller board which
has an inbuilt Thermistor which is used to
compare the readings of both sensors.
• The environmental temperature is
measured and displayed on the LCD
screen of the microcontroller and updated
every 1 second.

RTD is connected to one of the ADCs of the


microcontroller and this value is also
displayed on the LCD and updated for every 1
second
23
On-Off controller:
• This is a simple mechanism for temperature
control device, whenever temperature crosses
the set point, controller switches the output.
• It is a cyclic process.
• In order to prevent the continual operation, a
differential or hysteresis is used.
• It is used in slow temperature change
applications.
E.g.: Temperature alarm system.

Proportional controller:
• It eliminates the cyclic problem of on-off
controller.
• This slows down the time at which heater
approaches the set point by decreasing the
average power supplied.
• This time proportioning phenomenon controls
the ON time and OFF time of the controller.

24
• Proportioning action occurs within a
proportional band.
• Output is ON within the band (below set point)
and OFF outside the band (above the set
point).

25
HD44780U (LCD-II)
(Dot Matrix Liquid Crystal Display Controller/Driver

Description

.
The HD44780U dot-matrix liquid crystal display controller and
driver LSI displays alphanumeric, Japanese kana characters, and
symbols.
It can be configured to drive a dot-matrix liquid crystal display
under the control of a 4- or 8-bit microprocessor. Since all the
functions such as display RAM, character Generator, and liquid
crystal driver, required for driving a dot-matrix liquid crystal
display are internally provided on one chip, a minimal system
can be interfaced with this controller/driver.

A single HD44780U can display up to one 8-character line or


two 8-character lines. The HD44780U has pin function
compatibility with the HD44780S which allows the user to
easily replace an LCD-II with an HD44780U. The HD44780U
character generator ROM is extended to generate 208 5 8 dot
character fonts and 32 5 10 dot character fonts for a total of
240 different character fonts. The low power supply (2.7V to
5.5V) of the HD44780U is suitable for any portable battery-
driven product requiring low power dissipation
26
27
Features

• 5 × 8 and 5 × 10 dot matrix possible

• Low power operation support:


 2.7 to 5.5V

• Wide range of liquid crystal display driver power


 3.0 to 11V

• Liquid crystal drive waveform


 A (One line frequency AC waveform)

• Correspond to high speed MPU bus interface


 2 MHz (when VCC = 5V)

• 4-bit or 8-bit MPU interface enabled

• 80 × 8-bit displays RAM (80 characters max.)

• 9,920-bit character generator ROM for a total of 240


character fonts
 208 character fonts (5 × 8 dot)
 32 character fonts (5 × 10 dot)
64 × 8-bit character generator RAM
 8 character fonts (5 × 8 dot)
 4 character fonts (5 × 10 dot)
28
• 16-common × 40-segment liquid crystal display driver

• Programmable duty cycles


 1/8 for one line of 5 × 8 dots with cursor
 1/11 for one line of 5 × 10 dots with cursor
 1/16 for two lines of 5 × 8 dots with cursor

• Wide range of instruction functions:


 Display clear, cursor home, display on/off, cursor on/off,
display character blink, cursor shift, display shift

• Pin function compatibility with HD44780S

• Automatic reset circuit that initializes the controller/driver


after power on

• Internal oscillator with external resistors

• Low power consumption

29
30
31
8-bit Microcontroller
32
Features

• Compatible with MCS-51™ Products

• 4K Bytes of In-System Reprogrammable Flash Memory

– Endurance: 1,000 Write/Erase Cycles


• Fully Static Operation: 0 Hz to 24 MHz

• Three-level Program Memory Lock

• 128 x 8-bit Internal RAM

• 32 Programmable I/O Lines

• Two 16-bit Timer/Counters

• Six Interrupt Sources

• Programmable Serial Channel

• Low-power Idle and Power-down Modes

• A/D Converters

Description

33
The AT89C51 is a low-power, high-performance CMOS 8-
bit microcomputer with 4k Bytes 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.

34
Pin Functions
35
COM12 to COM16 are non-selection waveforms at 1/11 duty factor. SEG1
to SEG40 40 O LCD Segment signals V1 to V5 5 — Power supply Power
supply for LCD drive VCC –V5 = 11 V (max) VCC, GND 2 — Power supply
VCC: 2.7V to 5.5V, GND: 0V OSC1, OSC2 2 — Oscillation resistor clock
When crystal oscillation is performed, a resistor must be connected
externally. When the pin input is an external clock, it must be input to
OSC1.

Control applications.
36
VCC

Supply voltage.
GND

Ground.
Port 0

Port 0 is an 8-bit open-drain bi-directional I/O port. As an


Output port, each pin can sink eight TTL inputs. When 1s
are written to port 0 pins, the pins can be used as high
impedance Inputs. Port 0 may also be configured to be the
multiplexed low order Address/data bus during accesses
to external program and data memory. In this mode P0
has internal pullups. Port 0 also receives the code bytes
during Flash programming, and outputs the code bytes
during program Verification. External pullups are required
during program verification.

Port 1
Port 1 is an 8-bit bi-directional I/O port with internal
pullups. 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 pullups and can be used as
inputs. As inputs, Port 1 pins that are externally being
pulled low will source current (IIL) because of the internal
pullups. Port 1 also receives the low-order address bytes
during Flash programming and verification.

Port 2
37
Port 2 is an 8-bit bi-directional I/O port with internal
pullups. The Port 2 output buffers can sink/source four
TTL inputs. When 1s are written to Port 2 pins they are
pulled high by the internal pullups and can be used as
inputs. As inputs Port 2 pins that are externally being
pulled low will source current (IIL) because of the internal
pullups. Port 2 emits the high-order address byte during
fetches from external program memory and during
accesses to external data memories that use 16-bit
addresses (MOVX @ DPTR). In this application, it uses
strong internal pullups when emitting 1s. During accesses
to external data memories that use 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special
Function Register.
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 (IIL) because of the pull-ups. Port 3 also
serves the functions of various special features of the
AT89C51 as listed below:

38
Port Pin Alternate Functions
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)
P3.6 WR (external data memory write strobe)
Port 3 also receives some control signals for Flash
programming and verification

RST
Reset input. A high on this pin for two machine cycles
while the oscillator is running resets the device.

ALE/PROG
Address Latch Enable 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. Note,
however, that one ALE pulse is skipped during each
access to external Data Memory. 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 is the read strobe to external
program memory. When the AT89C51 is executing code
from external program memory, PSEN is activated twice
39
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, for parts that require 12-
volt VPP.

XTAL1
Input to the inverting oscillator amplifier and input to the
internal clock operating circuit.
XTAL2
Output from the inverting oscillator amplifier.

Programming the Flash

40
The AT89C51 is normally shipped with the on-chip Flash memory array in
the erased state (that is, contents = FFH) and ready to be programmed.
The programming interface accepts either a high-voltage (12-volt) or a low-
voltage (VCC) program enable signal. The low-voltage programming mode
provides a convenient way to program the AT89C51 inside the user’s
system, while the high-voltage programming mode is compatible with
conventional third party Flash or EPROM programmers. The AT89C51 is
shipped with either the high-voltage or low-voltage programming mode
enabled. The respective top-side marking and device signature codes are
listed in the following table.

VPP = 12V VPP = 5V


Top-side Mark AT89C51 AT89C51
41
xxxx xxxx-5
yyww yyww
Signature (030H) = 1EH (030H) = 1EH
(031H) = 51H (031H) = 51H
(032H) =F FH (032H) = 05H

The AT89C51 code memory array is programmed byte-by byte in


either programming mode. To program any nonblank Byte in the
on-chip Flash Memory, the entire memory must be erased using
the Chip Erase Mode.

Programming Algorithm: Before programming the AT89C51,


the address, data and control signals should be set up according
to the Flash programming mode table and Figure 3 and Figure 4.
To program the AT89C51, take the following steps.
1. Input the desired memory location on the address lines.
2. Input the appropriate data byte on the data lines.
3. Activate the correct combination of control signals.
4. Raise EA/VPP to 12V for the high-voltage programming mode.
5. Pulse ALE/PROG once to program a byte in the Flash array or
the lock bits. The byte-write cycle is self-timed and typically takes
no more than 1.5 ms. Repeat steps 1 through 5, changing the
address and data for the entire array or until the end of the object
file is reached.

Data Polling: The AT89C51 features Data Polling to indicate the


end of a write cycle. During a write cycle, an attempted read of
the last byte written will result in the complement of the written
datum on PO.7. Once the write cycle has been completed, true
data are valid on all outputs, and the next cycle may begin. Data
Polling may begin any time after a write cycle has been initiated.
Ready/Busy: The progress of byte programming can also
Be monitored by the RDY/BSY output signal. P3.4 is
pulled low after ALE goes high during programming to
42
indicate BUSY. P3.4 is pulled high again when
programming is done to indicate READY.
Program Verify: If lock bits LB1 and LB2 have not been
programmed, the programmed code data can be read
back via the address and data lines for verification. The
lock bits cannot be verified directly. Verification of the lock
bits is achieved by observing that their features are
enabled.
Chip Erase: The entire Flash array is erased electrically
By using the proper combination of control signals and by
holding ALE/PROG low for 10 Ms. The code array is
written with all “1”s. The chip erase operation must be
executed before the code memory can be re-programmed.
Reading the Signature Bytes: The signature bytes are
read by the same procedure as a normal verification of
locations 030H, 031H, and 032H, except that P3.6 and
P3.7 must be pulled to a logic low. The values returned
are As follows.

(030H) = 1EH indicates manufactured by Atmel


(031H) = 51H indicates 89C51
(032H) = FFH indicates 12V programming
(032H) = 05H indicates 5V programming
Programming Interface

Every code byte in the Flash array can be written and the
Entire array can be erased by using the appropriate
43
combination of control signals. The write operation cycle is
self timed and once initiated, will automatically time itself
to Completion. All major programming vendors offer
worldwide support for The Atmel microcontroller series.
Please contact your local Programming vendor for the
appropriate software revision

44
A/D Converters

The ADC080X families are CMOS 8-Bit, successive


approximation A/D converters which use a modified

45
Potentiometric ladder and are designed to operate with
the 8080A control bus via three-state outputs.
These converters
Appear to the processor as memory locations or I/O ports,
and hence no interfacing logic is required. The differential
analog voltage input has good common mode- Rejection
and permits offsetting the analog zero-input voltage Value.
In addition, the voltage reference input can be adjusted to
allow encoding any smaller analog voltage span to the full
8 bits of resolution.

46
47
48
Understanding A/D Error Specs

A perfect A/D transfer characteristic (staircase wave-form)


is shown in Figure 11A. The horizontal scale is analog
input voltage and the particular points labeled are in steps
of 1 LSB (19.53mV with 2.5V tied to the VREF/2 pin). The
digital output codes which correspond to these inputs are
shown as D-1, D, and D+1. For the perfect A/D, not only
will center value (A - 1, A, A + 1, . . .) analog inputs
produce the correct Output digital codes, but also each
riser (the transitions Between adjacent output codes) will
be located } 1/2 LSB Away from each center-value. As
shown, the risers are ideal and have no width. Correct
digital output codes will be provided for a range of analog
input voltages which extend } 1/2 LSB from the ideal
center-values. Each treads (the range Of analog input
voltage which provides the same digital Output code) is
therefore 1 LSB wide. The error curve of Figure 11B
shows the worst case transfer Function for the ADC080X.
Here the specification guarantees that if we apply an
analog input equal to the LSB analog voltage center-
value, the A/D will produce the correct digital code.
Next to each transfer function is shown the corresponding
error plot. Notice that the error includes the quantization
Uncertainty of the A/D. For example, the error at point 1 of
Figure 11A is +1/2 LSB because the digital code appeared
1/2 LSB in advance of the center-value of the tread. The
error plots always have a constant negative slope and the
abrupt upside steps are always 1 LSB in magnitude,
unless the device has missing codes.
49
Detailed Description

The functional diagram of the ADC080X series of A/D


Converters operates on the successive approximation
principle (see Application Notes AN016 and AN020 for a
more detailed description of this principle). Analog
switches Are closed sequentially by successive-
approximation logic until the analog differential input
voltage [VlN (+) - VlN (-)] matches a voltage derived from
a tapped resistor string across the reference voltage. The
most significant bit is tested first and after 8 comparisons
(64 clock cycles), an 8- bit binary code (1111 1111 = full
scale) is transferred to an output latch.
The normal operation proceeds as follows. On the high-to-
low transition of the WR input, the internal SAR latches
and the Shift-register stages are reset, and the INTR
output will be set high. As long as the CS input and WR
input remain low, the A/D will remain in a reset state.
Conversion will start from 1 to 8 clock periods after at least
one of these inputs makes a low to- high transition. After
the requisite number of clock pulses to complete the
conversion; the INTR pin will make a high-to-low
transition. This can be used to interrupt a processor, or
otherwise signal the availability of a new conversion. A RD
operation (with CS low) will clear the INTR line high again.
The device may be operated in the free-running mode by
connecting INTR to the WR input with CS = 0. To ensure
startup under all possible conditions, an external WR
pulse is required during the first power-up cycle.

Digital Operation
50
The converter is started by having CS and WR
simultaneously Low. This sets the start flip-flop (F/F) and
the resulting “1” level Resets the 8-bit shift register, resets
the Interrupt (INTR) F/F and inputs a “1” to the D flip-flop,
DFF1, which is at the input end of the 8-bit shift register.
Internal clock signals then transfer this “1” to the Q output
of DFF1. The AND gate, G1, combines this “1” output with
a clock signal to provide a reset signal to the start F/F. If
the set signal is no longer present (either WR or CS is a
“1”), the start F/F is reset and the 8-bit shift register then
can have the “1” clocked in, which starts the conversion
process. If the set signal were to still be present, this reset
pulse would have no effect (both outputs of the start F/F
would be at a “1” level) and the 8-bit shift register would
continue to be held in the reset mode. This allows for
Asynchronous or wide CS and WR signals. After the “1” is
clocked through the 8-bit shift register (which Completes
the SAR operation) it appears as the input to DFF2. As
soon as this “1” is output from the shift register, the AND
gate, G2, causes the new digital word to transfer to the
Three-State output latches. When DFF2 is subsequently
clocked, the Q output makes a high-to-low transition which
causes the INTR F/F to set. An inverting buffer then
supplies the INTR output signal. When data is to be read,
the combination of both CS and RD being low will cause
the INTR F/F to be reset and the three state output latches
will be enabled to provide the 8-bit digital outputs.

Digital Control Inputs


51
The digital control inputs (CS, RD, and WR) meet
standard TTL logic voltage levels. These signals are
essentially equivalent to the standard A/D Start and
Output Enable control signals, and are active low to allow
an easy interface to microprocessor control busses. For
non-microprocessor based applications, the CS input (pin
1) can be grounded and the standard A/D Start function
obtained by an active low pulse at the WR input (pin 3).
The Output Enable function is achieved by an active low
pulse at the RD input (pin 2).

Analog Operation

The analog comparisons are performed by a capacitive


charge summing circuit. Three capacitors (with precise
ratioed Values) share a common node with the input to an
auto zeroed Comparator. The input capacitor is switched
between VlN (+) and VlN (-), while two ratioed reference
capacitors are switched between taps on the reference
voltage divider string. The net charge corresponds to the
weighted difference between the input and the current
total value set by the successive approximation register. A
correction is made to Offset the comparison by 1/2 LSB

52
Coding

For LCD
53
//#include<reg51.h>

#define toAscii(x) (x + 0x30)

#ifndef LCD_PORT_DEF

#define LCD_DATA_PORT P3

#endif

//Defines

#define MAX_LCD_COL 16

#define MAX_LCD_ROW 2

#define LCD_CMD_CLS 0x01

#define LCD_CMD_DISP_RET_HOME 0x2

#define LCD_CMD_DISP_ON_CURSOR_OFF_BLINK_OFF 0x0C

#define LCD_CMD_DISP_ON_CURSOR_OFF_BLINK_ON 0x0D

#define LCD_CMD_DISP_ON_CURSOR_ON_BLINK_OFF 0x0E

#define LCD_CMD_DISP_ON_CURSOR_ON_BLINK_ON 0x0F

#define LCD_CMD_DISP_OFF_CURSOR_OFF 0x08

#define LCD_CMD_DISP_OFF_CURSOR_ON 0x0A

#define LCD_CMD_DL_8_LINES_2_FONT_5X10 0x3C

#define LCD_CMD_DL_8_LINES_2_FONT_5X7 0x38

#define LCD_CMD_ENTRY_MODE_INCREMENT_CURSOR 0x06

#define LCD_CMD_ENTRY_MODE_DECREMENT_CURSOR 0x04

#define LCD_CMD_LINE1 0x80

#define LCD_CMD_LINE2 0xC0

#define LCD_CMD_DISP_SHIFT_RIGHT 0x1C

#define LCD_CMD_DISP_SHIFT_LEFT 0x18

#define LCD_CMD_DISP_NO_SHIFT_CURSOR_RIGHT 0x14

54
#define LCD_CMD_DISP_NO_SHIFT_CURSOR_LEFT 0x10

#define lcd_displayOff lcd_command (LCD_CMD_DISP_OFF_CURSOR_OFF)

#define lcd_displayOn
lcd_command(LCD_CMD_DISP_ON_CURSOR_OFF_BLINK_ON)

#define lcd_cursorOffBlinkOn lcd_command


(LCD_CMD_DISP_ON_CURSOR_OFF_BLINK_ON)

#define lcd_cursorOffBlinkOff lcd_command


(LCD_CMD_DISP_ON_CURSOR_OFF_BLINK_OFF)

#define lcd_cursorOnBlinkOn
lcd_command(LCD_CMD_DISP_ON_CURSOR_ON_BLINK_ON)

#define lcd_cursorOnBlinkOff
lcd_command(LCD_CMD_DISP_ON_CURSOR_ON_BLINK_OFF)

#define lcd_clear lcd_command(LCD_CMD_CLS)

#define lcd_home lcd_command(LCD_CMD_DISP_RET_HOME)

#define lcd_cursorLeft lcd_command(LCD_CMD_DISP_NO_SHIFT_CURSOR_LEFT)

#define lcd_cursorRight
lcd_command(LCD_CMD_DISP_NO_SHIFT_CURSOR_RIGHT)

sbit LCD_EN = P1^0;

sbit LCD_RS = P1^1;

sbit LCD_RWN = P1^2;

sbit LCD_BUSY = LCD_DATA_PORT^7;

//Function Prototypes

/* One milisecond Delay */

void delay_ms ( unsigned char my_time );

void lcd_init ( void );

55
void lcd_command ( unsigned char command );

void lcd_putch ( unsigned char ch );

void lcd_puts ( unsigned char *str );

void lcd_ready ( void );

void lcd_cursorPos ( unsigned char row , unsigned char col );

void lcd_putRow ( unsigned char row , unsigned char *str );

void lcd_putScreen ( unsigned char *str );

/***************************************************************************

* Function: lcd_putUBYTE

* Purpose: Function to display an 8 bit unsigned number on LCD

* Parameters: number

* number should be unsigned

* Range supported 0 to 255

* No Error checking done pass the input correctly

* Returns: None

***************************************************************************/

void lcd_putUBYTE ( unsigned char number );

/***************************************************************************

* Function: lcd_putUPBCD

* Purpose: Function to display an 8 bit unsigned packed BCD on LCD

* Parameters: number

* number should be unsigned

* Range supported 0 to 255

* No Error checking done pass the input correctly

* e.g lcd_putUPBCD(0x59) would seperate out 5 and 9 and display it

56
* on lcd as 59

* Returns: None

***************************************************************************/

void lcd_putUPBCD ( unsigned char number );

/***************************************************************************

* Function: lcd_putUINT16

* Purpose: Function to display an 16 bit unsigned number on LCD

* Parameters: number

* number should be unsigned

* Range supported 0 to 65535

* No Error checking done pass the input correctly

* e.g if number is 0xff it will be displayed as 255 on LCD

* NOTE:!! Leading Zeros will be displayed ... implement other function for disp

* zero as space and a master function that will call either the leading zero or

* the other based on the requirement

* Returns: None

***************************************************************************/

void lcd_putUINT16 ( unsigned int number );

/***************************************************************************

* Function: lcd_put2udigDecimal

* Purpose: Function to display a 2 digit unsigned decimal number on LCD

* Parameters: number

* number should be unsigned

* Range supported 0 to 99 in decimal

* Error checking done

57
* If number is greater than 99 it is not displayed

* Returns: None

***************************************************************************/

void lcd_put2udigDecimal ( unsigned char number );

//void lcd_displayOff ( void );

//void lcd_displayOn ( void );

//void lcd_clear ( void );

//void lcd_home ( void );

//void lcd_cursorLeft ( void );

//void lcd_cursorRight ( void );

//void lcd_cursorOn ( void );

//void lcd_cursorOff ( void );

//void lcd_wipeOnLR ( void );

//void lcd_wipeOnRL ( void );

//void lcd_wipeOffLR ( void );

//void lcd_wipeOffRR ( void );

//void lcd_putRow ( void );

//void lcd_putScreen ( void );

For display
#include <reg51.h>

#include <lcd.h>

58
#include <delay.h>

#define ADC_CS P0_0

#define ADC_RDBAR P0_1

#define ADC_WRBAR P0_2

#define ADC_INTR P0_3

#define ADC_DATA P2

#define ON 1

#define OFF 0

sbit P0_0 = P0^0;

sbit P0_1 = P0^1;

sbit P0_2 = P0^2;

sbit P0_3 = P0^3;

//FAN CONTROL BIT

sbit FAN = P1^3;

char digitalData=0;

code unsigned char tempC[]= "Temp ";

code unsigned char degC[]= "Deg";

code unsigned char cel[]="C";

void main (void)

59
//Make ADC Intr Input

ADC_INTR = 1;

lcd_init();

lcd_cursorOffBlinkOff;

ADC_CS=0;

ADC_RDBAR=1;

ADC_WRBAR=1;

FAN=OFF;

while(1)

lcd_home;

ADC_WRBAR=0;

ADC_WRBAR=1;

while(ADC_INTR==1);

ADC_RDBAR=0;

DelayUs(10);

digitalData=ADC_DATA;

lcd_puts(&tempC[0]);

lcd_put2udigDecimal(digitalData);

//lcd_putUBYTE(digitalData);

lcd_putch(' ');

lcd_puts(&degC[0]);

lcd_puts(&cel[0]);

ADC_RDBAR=1;

if(digitalData>40)

60
{

FAN=ON;

else

FAN=OFF;

61
Conclusion
The Perfect Temperature Sensor:
62
Has no effect on the medium it
measures
Is precisely accurate
Responds instantly (in most
cases)
Has an easily conditioned output
Temperature sensors are used in embedded systems for
both thermal monitoring and management applications.
We must evaluate the trade-offs of the sensor,
conditioning circuitry and sensor output in order to
maximize the measurement accuracy while easing the
interface to the microcontroller.
The following sensor guidelines can be used as a starting
point to select a temperature sensor. If our application
requires for a high-temperature measurement,
thermocouples are a good choice because of their wide
temperature operating range. Thermocouples are typically
used as remote sensors and, therefore, the circuit must
provide noise immunity by using good grounding and
shielding methods. If our application required precision,
RTDs set the standard with their superior repeatability and
stability characteristics. For applications such as the
temperature measurement on a thermistors or silicon IC
sensors should be considered. Thermistors are available
in more packages, are lower in cost and have a faster
thermal response time than silicon sensors. However,
thermistors require additional signal-conditioning circuitry,
while silicon sensors provide both the sensor and circuitry
on a single IC that can be interfaced directly to the
63
microcontroller. The output of the sensor is selected by
the available microcontroller hardware and software
resources, in addition to the complexity of the sensor
circuit. The sensor output can consist of an analog,
frequency, ramp rate, duty cycle, serial or logic format that
is proportional to temperature.

64
65

You might also like