of 44
8/8/2019 Analog Sensor
1/44
SUMMER TRAINING PROJECT REPORT
ON
INTERFACING OF ANALOG SENSORWITH AN 8051 MICROCONTROLLER
TO
NORTHERN INDIA ENGINEERING COLLEGE,
NEW DELHI
For the degree
OfBachelor in Technology
In
Electronics & Communication
NORTHERN INDIA ENGINEERING COLLEGE,
FC-26, SHASTRI PARK, NEW DELHI-53MAY 2010
SUBMITTED BY:
Ravinder Singh 0171562808 (ECE-S3)
Swati Varun 0001562808 (ECE-S3)
Gautam Panwar 0211562808 (ECE-S3)
Navendu Pratap Sagar - 0221562808(ECE-S3)
1
8/8/2019 Analog Sensor
2/44
CERTIFICATE
This is to certify that Project Report titled INTERFACING OF ANALOGSENSOR WITH AN 8051 MICROCONTROLLER, which is submitted
by following students of Bachelors in Technology in Electronics and
Communication Engg. Of NORTHERN INDIA ENGINEERING
COLLEGE, NEW DELHI, under my supervision.
Projectee:
Ravinder Singh 0171562808
Swati Varun 0001562808
Gautam Panwar 0211562808
Navendu Pratap Sagar - 0221562808
Head of the department Supervisor/Guide
2
8/8/2019 Analog Sensor
3/44
ACKNOWLEDGEMENT
We feel highly privileged to express our deep sense of gratitude to allthose who helped us during our project work. We would like to express
our grateful thanks for the help and advice given to us by
, HOD ECE Dept., for their valuable guidance in our project.
We express our gratitude and reverence to the preceptor and project
Guide.... for his advice, guidance and support which helped us in
completing our project.
We are also highly thankful to the management of NORTHERN INDIA
ENGINEERING COLLEGE, for providing necessary facilities and
infrastructure.
Date:
APPROVED BY:
3
8/8/2019 Analog Sensor
4/44
CONTENTS
TABLE OF CONTENTS...................................................................4
OVERVIEW...5
CHAPTER1:INTRODUCTION.........................................................6
REQUIREMENTS...........................................................................7
CHAPTER 2: ANALOG SENSOR
2.1 Introduction.........................................................................8
2.2 Analog to digital converter .................................................8
2.3 Types of A/D converter102.4 Useful Analog sensors.......................................................12
CHAPTER 3: MICROCONTROLLER
3.1 Introduction...14
3.2 P89V51RD2FN Microcontroller............................................15
3.3 Pin Diagram..........................................................................16
3.4 Pin Descriptions...17
3.5 Data table..20
CHAPTER 4: ICs
4.1 MAX232.....27
4.2 ULN280330
4.3 PCF859133
CHAPTER 5: OVER ALL SYSTEM
5.1 Block Diagram.........................................................................36
5.2 Hardware..375.3 Programme..38
CONCLUSIONS.............................................................................43
TOOLS AND DEVELOPMENT......................................................44
REFERENCES...............................................................................44
4
8/8/2019 Analog Sensor
5/44
OVERVIEW
In our project we have explained how to read value from an analog
sensor (Potentiometer used here) and send it to microcontroller via
analog to digital converter. The value read is further displayed by led
array in binary format. The circuit incorporates various IC along with
8051 microcontroller.
5
8/8/2019 Analog Sensor
6/44
PART 1
INTRODUCTION
A sensor is a device which measures or detects a physical quantity. Whereas an
actuator is a device which converts a signal, usually electrical, into some action i.e.
mechanical.
Transducer is a device which can convert one form of energy to other.So,sensor as
well as actuator is a transducer.
Among the different types of energy which can be sensed are those classed as
radiant,mechanical,gravitational,electrical
, thermal and magnetic.All the value sensed are usually analog in nature. As these values involve
computational work, so these value must be converted into digital format as
computers cant accept analog signal.
Analog signals are those signals which can take any possible values between two
points whereas digital signals can take only certain discrete values between two
points.
6
8/8/2019 Analog Sensor
7/44
REQUIREMENTS
Computer Interfacing.
Potentiometer(10kohm).
IC MAX232, ULN2803, PCF8591.
P89V51RD2FN microcontroller.
7
8/8/2019 Analog Sensor
8/44
PART 2
ANALOG SENSOR
2.1 INTRODUCTION:
Analog sensors measure continuous information. An example of this kind of a
sensor is a light sensor which monitors the amount of light over time. Analog
sensors are often distinguished from digital sensors which use discrete
(discontinuous) values to represent information for input. Often though either
approach can be used to provide similar types of information. For example, film
cameras are analog devices, while Web cameras are digital devices.
Now,the question arises, how these analog signals are converted into digital
signals.There are several ic available in market which performs the function of a to
d conversion.
We have used PCF8591 IC as a/d converter..
2.2 Analog to Digital Converter:
Microcontrollers almost always deal with discrete values. An important part of
using an Analog Signal is being able to convert it to a Discrete Signal such as a 8-
bit digital value. This allows the Microcontroller to do things like compute values
and perform comparisons. Fortunately, most modern controllers have a resource
called an Analog to Digital converter (A/D converter).
8
8/8/2019 Analog Sensor
9/44
The function of the A/D converter is to convert an Analog signal into a digital
value. It does this with a mapping function that assigns discrete values to the entire
range of voltages. It is typical for the range of an A/D converter to be 0 to +5 volts.
The A/D converter will divide the range of values by the number of discrete
combinations. For example, the table on the right shows 5 samples of an Analog
Signal that have been converted into digital values.
The Chart on the bottom shows the results of the A/D conversions for 14 samples.
The sample numbers are shown along the X axis at the bottom. The left hand Y axis
indicates the voltage of the Analog sample that was fed into the A/D converter. On
the right hand side, the 8-bit value assigned to the conversion is show.
As you can see from the blue line, this was an analog function just like the originalAnalog Signal graph shown above. The A/D converter has mapped a set of discrete
values onto this graph.
9
8/8/2019 Analog Sensor
10/44
Now these digital signals are send to microcontrooler for processing. Afterthat, microcontroller sends value in binary to led array.
2.3 Types of a/d converters:
1. Ladder comparison2. Successive approximation
3. Flash comparison
These three are important converters. Beside these, several other
converters are also available.
1. Ladder comparison
2. Successive approximation10
8/8/2019 Analog Sensor
11/44
3. Flash comparison
If N is the number of bits in the output word,
Then 2^N comparators will be required.
2.4 Useful Analog Sensors:11
8/8/2019 Analog Sensor
12/44
All of the circuits shown in this section are intended to be connected to an A/D
converter port.
CdS cells:
Cadmium sulphide is a unique compound with a property that itsresistance varies with intensity of light. Higher the intensity, lower the
resistance. In the diagram shown in right, p1 is CdS cell whereas r1 is
10k resistance. Using voltage divider equation, we can calculate the
voltage at avg light and accordingly choose our a/d converter.
Potentiometers:
12
8/8/2019 Analog Sensor
13/44
Potentiometer is one of the most extensively used analog sensor.It is
widely used in robotic arm to sense the angle in a range of 0 to 270
degree.it is basically a resistive sensor.its schematic is similar to the
schematic of CdS cell sensor mentioned above.Value read by a/d
converter changes with contact position on r2.As the contact positionchanges ,different values of voltage occurs at i/p of a to d converter
according to voltage divider rule.
PART 3
MICROCONTROLLER13
8/8/2019 Analog Sensor
14/44
3.1 INTRODUCTION:Microcontrollers are "special purpose computers." Microcontrollers do one thing
well. There are a number of other common characteristics that define
microcontrollers. If a computer matches a majority of these characteristics, then you
can call it a "microcontroller":
Microcontrollers are "embedded" inside some other device (often a
consumer product) so that they can control the features or actions of the product.
Another name for a microcontroller, therefore, is "embedded controller."
Microcontrollers are dedicated to one task and run one specific program.
The program is stored in (read-only memory) and generally does not change.Microcontrollers are often low-power devices. A desktop computer is
almost always plugged into a wall socket and might consume 50 watts of
electricity. A battery-operated microcontroller might consume 50 milliwatts.
A microcontroller has a dedicated input device and often (but not always)
has a small LED or LCD display for output. A microcontroller also takes input
from the device it is controlling and controls the device by sending signals to
different components in the device.
In our project we are using P89C51RD2 MICROCONTROLLER.
3.2 P89V51RD2FN MICROCONTROLLER
The P89C51RD2 is a low-power, high-performance CMOS 8-bit
microcontroller with 8K bytes of Flash programmable and erasable read only
memory (PEROM). The device is manufactured using Philips high-density
14
8/8/2019 Analog Sensor
15/44
nonvolatile memory technology and is compatible with the industry-standard MCS-
51 instruction set and pinout. 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 Philips
P89V51RD2FN is a powerful microcomputer which provides a highly-flexible andcost-effective solution to many embedded control applications.
The P89V51RD2FN provides the following standard features: 64 kB flash
microcontroller with 1024 byte RAM; Clock type: 12-clk (6-clk opt.) ; External
interrupt: 2; I/O pins: 32 ; Memory type: FLASH ; Number of pins: 40 ; Operating
frequency: 0~20/40 (6clk/12clk) MHz; Operating temperature: -40~85 Cel; Power
supply: 4.5~5.5V ; Program security: yes; Serial interface: UART ; Series: 80C51
family
3.3 PIN DIAGRAM
15
8/8/2019 Analog Sensor
16/44
3.4 PIN DESCRIPTION
VCC:
16
8/8/2019 Analog Sensor
17/44
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
pull ups.
Port 0 also receives the code bytes during Flash programming, and outputs the code
bytes during program verification. External pull ups are required during program
verification.
Port 1:
Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 pins are
pulled high by the internal pull-ups when 1s are written to them and can be used
as inputs in this state. As inputs, Port 1 pins that are externally pulled LOW will
source current (IIL) because of the internal pull-ups. P1.5, P1.6, P1.7 have high
current drive of 16 mA. Port 1 also receives the low-order address bytes during the
external host mode programming and verification.
Port 2:
Port 2 is an 8-bit bi-directional I/O port with internal pull ups. 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 pull ups 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
pull ups. Port 2 emits the high-order address byte during fetches from external
program memory and during accesses to external data memory that use 16-bit
addresses. In this application, it uses strong internal pull ups when emitting 1s.
During accesses to external data memory that use 8-bit addresses (MOVX @ RI),
Port 2 emits the contents of the P2 Special Function Register. Port 2 also receivesthe 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
17
8/8/2019 Analog Sensor
18/44
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:
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 duringaccesses 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
microcontroller 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:18
8/8/2019 Analog Sensor
19/44
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 alsoreceives the 12-volt programming enable voltage(VPP) during Flash programming,
for parts that require12-volt VPP.
XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
XTAL2:
Output from the inverting oscillator amplifier.
DATA TABLE:
BLOCK DIAGRAM OF IC:
19
8/8/2019 Analog Sensor
20/44
RECOMMENDED OPERATING CONDITIONS:
OPERATING RANGE:
20
8/8/2019 Analog Sensor
21/44
RELIABILITY CHARACTERISTICS:
POWER-UP TIMING:
21
8/8/2019 Analog Sensor
22/44
PIN IMPEDANCE:
STATIC CHARACTERISTICS:
22
8/8/2019 Analog Sensor
23/44
SPECIAL FUNCTION REGISTERS:
23
8/8/2019 Analog Sensor
24/44
24
8/8/2019 Analog Sensor
25/44
25
8/8/2019 Analog Sensor
26/44
26
8/8/2019 Analog Sensor
27/44
PART 4
ICs
4.1 MAX 232
INTRODUCTION:
The MAX232 is a dual driver/receiver that includes a capacitive voltage generator
to supply TIA/EIA-232-F
Voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-Finputs to 5-V TTL/CMOS levels.
These receivers have a typical threshold of 1.3 V, a typical hysteresis of 0.5 V, and
can accept 30-V inputs.
Each driver converts TTL/CMOS input levels into TIA/EIA-232-F levels.
They are
supplied in 16 pin plastic DIP
packages with a
copper lead
frame to reduce
thermal
resistance.
PIN CONNECTION:
27
8/8/2019 Analog Sensor
28/44
FUNCTION TABLE:
28
8/8/2019 Analog Sensor
29/44
4.2 ULN 2803
29
8/8/2019 Analog Sensor
30/44
INTRODUCTION:
The ULN2803APG / AFWG Series are high voltage, high current Darlington
drivers comprised of eight NPN Darlington pairs.All units feature integral clamp diodes for switching inductive loads.
Applications include relay, hammer, lamp and display (LED) drivers.
FEATURES:
Output current (single output) 500 mA (Max.)
High sustaining voltage output 50 V (Min.)
Output clamp diodes
Inputs compatible with various types of logic.
Package TypeAPG : DIP18pin
Package TypeAFWG : SOL18pin
PIN CONNECTION:
30
8/8/2019 Analog Sensor
31/44
31
8/8/2019 Analog Sensor
32/44
4.3 PCF8591
32
8/8/2019 Analog Sensor
33/44
INTRODUCTION
The PCF8591 is a single-chip, single-supply low power 8-bit CMOS data
acquisition device with four analog inputs, one analog output and a serial I2C-businterface. Three address pins A0, A1 and A2 are used for programming the
hardware address, allowing the use of up to eight devices connected to the I2C-bus
without additional hardware. Address, control and data to and from
the device are transferred serially via the two-line bidirectional I2C-bus.
The functions of the device include analog input multiplexing, on-chip track and
hold function, 8-bit analog-to-digital conversion and an 8-bit digital-to-analog
conversion. The maximum conversion rate is given by the maximum speed of the
I2C-bus
FEATURES
Single power supply
Operating supply voltage 2.5 V to 6 V
Low standby current
Serial input/output via I2C-bus
Address by 3 hardware address pins
Sampling rate given by I2C-bus speed
4 analog inputs programmable as single-ended or differential inputs Auto-incremented channel selection
Analog voltage range from VSS to VDD
On-chip track and hold circuit
8-bit successive approximation A/D conversion
Multiplying DAC with one analog output
APPLICATIONS
Closed loop control systems
33
8/8/2019 Analog Sensor
34/44
Low power converter for remote data acquisition
Battery operated equipment
Acquisition of analog values in automotive, audio and TV applications.
PIN CONNECTION:
Block Diagram:
34
8/8/2019 Analog Sensor
35/44
PART 5
35
8/8/2019 Analog Sensor
36/44
OVER ALL SYSTEM
5 .1 BLOCK DIAGRAM
5.2 HARDWARE
36
8/8/2019 Analog Sensor
37/44
Interfacing
Interfacing is an important task to be accomplished in almost all
automation applications. The digital signals are to be generated to make the
hardware run as per the instructions of program.In the present application, the programming is done in .C. programming
language. .C. is chosen for its simplicity and ruggedness. It offers simple methods
to interact with the serial port through which the interfacing is done.
PROGRAMME
37
8/8/2019 Analog Sensor
38/44
#ifndef __I2C_H
#define __I2C_H
#include
#include
//-------------------------------------------
#define NOP _nop_()
//-------------------------------------------
void I2C_START();
void I2C_STOP();
void I2C_SEND(unsigned char );unsigned char I2C_REC(void);
void I2C_ACK();
void I2C_NACK();
//--------------------------------------------
sbit SCL=P1^6;
sbit SDA=P1^7;
bit FLAG;
//--------------------------------------------
#endif
void I2C_START()
{
SDA=1;
SCL=1;NOP;
SDA=0;
NOP;
SCL=0;
}
38
8/8/2019 Analog Sensor
39/44
//---------------------------------------------
void I2C_STOP()
{
SDA=0;SCL=1;
NOP;
SDA=1;
NOP;
SCL=0;
}
//----------------------------------------------
void I2C_SEND(unsigned char VALUE){
unsigned char i;
for(i=0;i
8/8/2019 Analog Sensor
40/44
unsigned char I2C_REC(void)
{
unsigned char i,VALUE;
VALUE=0;SDA=1;
for(i=0;i
8/8/2019 Analog Sensor
41/44
NOP;
NOP;
SCL=0;
}
//------------------------------------------------
void I2C_NACK()
{
SDA=1;
SCL=1;
NOP;
NOP;
SCL=0;
}unsigned char read_adc(unsigned char channel)
{
unsigned char value;
I2C_START();
I2C_SEND(0X90);
I2C_SEND(channel);
I2C_START();
I2C_SEND(0X91);
value=I2C_REC();I2C_ACK();
value=I2C_REC();
I2C_NACK();
I2C_STOP();
return value;
}
//-------------------------
void init_uart()
{
SCON=0X50;TMOD=0X20;
TH1=TL1=0XFD;
TR1=1;
}
//-----------------------
void tx(unsigned char value)
41
8/8/2019 Analog Sensor
42/44
{
SBUF=value;
while(!TI);
TI=0;
}//--------------------------
main()
{
while(1)
{
P0=read_adc(0);
}
}
CONCLUSION
42
8/8/2019 Analog Sensor
43/44
The project was successfully completed after a lot of efforts and work hours. This
project underwent compiling, debugging, removing errors, make it bug free, adding
more facilities & interactivity, make it more reliable and user friendly.
Guidance was taken from faculty; help from the friend were accepted at the variousproject development phases. Many books related to controlling of microcontroller were
referred to get the desired results.
TOOLS AND DEVELOPMENT
43
8/8/2019 Analog Sensor
44/44
Hardware:The hardware used to develop our project includes:
1. pot ( potentiometer, 10kohm)
2. IC MAX232, ULN2803, PCF8591
3. A P89V51RD2FN microcontroller.
Software: C language, KEIL Compiler, flash magic
REFERENCES
SITES:
http://www.google.com
http://www.wikipedia.com
BOOKS:
The 8051 microcontroller & Embedded system-Muhammad Ali Mazidi
http://www.google.com/http://www.wikipedia.com/http://www.google.com/http://www.wikipedia.com/