Professional Documents
Culture Documents
ACKNOWLEDGEMENT
CERTIFICATE
EMBEDDED SYSTEMS
8051 MICROCONTROLLER
INTRODUCTION TO LIGHT SENSING ROBOT
COMPONENTS USED
P89V51RD2 (8052 DERIVATIVE)
IC MAX 232
REGULATOR 7805
LIGHT EMITTING DIODE (LED)
RESISTORS
CAPACITORS
DC MOTORS
MOTOR DRIVING IC L293D
PROGRAM OF MOTOR WITH IC
LIGHT DEPENDENT RESISTORS (LDR)
IC PCF8591P(ANALOG TO DIGITAL CONVERTER)
INTER INTEGRATED CIRCUIT(I2C) PROTOCOL
PROGRAM OF ADC USING I2C PROTOCOL
Embedded systems are controlled by a main processing core that is typically either a
microcontroller or a digital signal processor (DSP)
Since the embedded system is dedicated to specific tasks, design engineers can optimize it,
reducing the size and cost of the product, or increasing the reliability and performance. Some
embedded systems are mass-produced, benefiting from economies of scale.
Physically, embedded systems range 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. Complexity varies from low, with a single microcontroller
chip, to very high with multiple units, peripherals and networks mounted inside a large chassis or
enclosure.
In general, "embedded system" is not an exactly defined term, as many systems have some
element of programmability. For example, Handheld computers share some elements with
embedded systems — such as the operating systems and microprocessors which power them —
but are not truly embedded systems, because they allow different applications to be loaded and
peripherals to be connected.
CHARACTERISTICS
1. Embedded systems are designed to do some specific task, rather than be a general-
purpose computer for multiple tasks. Some also have real-time performance constraints
that must be met, for reasons such as safety and usability; others may have low or no
performance requirements, allowing the system hardware to be simplified to reduce costs.
2. Embedded systems are not always standalone devices. Many embedded systems consist
of small, computerized parts within a larger device that serves a more general purpose.
For example, the Gibson Robot Guitar features an embedded system for tuning the
strings, but the overall purpose of the Robot Guitar is, of course, to play music. [5]
Similarly, an embedded system in an automobile provides a specific function as a
subsystem of the car itself.
3. The program instructions written for embedded systems are referred to as firmware, and
are stored in read-only memory or Flash memory chips. They run with limited computer
hardware resources: little memory, small or non-existent keyboard and/or screen.
USER INTERFACE
Embedded systems range from no user interface at all — dedicated only to one task — to
complex graphical user interfaces that resemble modern computer desktop operating systems.
A more sophisticated devices use graphical screen with touch sensing or screen-edge buttons
provide flexibility while minimizing space used: the meaning of the buttons can change with the
screen, and selection involves the natural behavior of pointing at what's desired. Handheld
systems often have a screen with a "joystick button" for a pointing device.
Some systems provide user interface remotely with the help of serial (e.g. RS-232, USB) or
network (e.g. Ethernet) connection. In spite of installed client software and cables are needed this
approach usually gives a lot of advantages: extends the capabilities of embedded system, avoids
the cost of a display, simplifies BSP, allows to build reach user interface on PC. One of the well
established model in this direction is the combination of embedded web server running on
embedded device and user interface in web browser on PC
Embedded systems span all aspects of modern life and there are many examples of their
use.Telecommunications systems employ numerous embedded systems from telephone switches
for the network to mobile phones at the end-user. Computer networking uses dedicated routers
and network bridges to route data.
Consumer electronics include personal digital assistants (PDAs), mp3 players, mobile phones,
videogame consoles, digital cameras, DVD players, GPS receivers, and printers. Many
household appliances, such as microwave ovens, washing machines and dishwashers, are
including embedded systems to provide flexibility, efficiency and features. Advanced HVAC
systems use networked thermostats to more accurately and efficiently control temperature that
can change by time of day and season. Home automation uses wired- and wireless-networking
that can be used to control lights, climate, security, audio/visual, surveillance, etc., all of which
use embedded devices for sensing and controlling.
Transportation systems from flight to automobiles increasingly use embedded systems. New
airplanes contain advanced avionics such as inertial guidance systems and GPS receivers that
also have considerable safety requirements. Various electric motors — brushless DC motors,
induction motors and DC motors — are using electric/electronic motor controllers. Automobiles,
electric vehicles, and hybrid vehicles are increasingly using embedded systems to maximize
efficiency and reduce pollution. Other automotive safety systems such as anti-lock braking
system (ABS), Electronic Stability Control (ESC/ESP), traction control (TCS) and automatic
four-wheel drive.
In addition to commonly described embedded systems based on small computers, a new class of
miniature wireless devices called motes are quickly gaining popularity as the field of wireless
sensor networking rises. Wireless sensor networking, WSN, makes use of miniaturization made
possible by advanced IC design to couple full wireless subsystems to sophisticated sensor,
enabling people and companies to measure a myriad of things in the physical world and act on
this information through IT monitoring and control systems. These motes are completely self
contained, and will typically run off a battery source for many years before the batteries need to
be changed or charged.
MICROCONTROLLER 8051
A particularly useful feature of the 8051 core is the inclusion of a boolean processing engine
which allowsbit-level boolean logic operations to be carried out directly and efficiently on
internal registers and RAM. This feature helped to cement the 8051's popularity in industrial
control applications. Another valued feature is that it has four separate register sets, which can be
used to greatly reduce interrupt latency compared to the more common method of storing
interrupt context on a stack.
The 8051 UARTs make it simple to use the chip as a serial communications interface. External
pins can be configured to connect to internal shift registers in a variety of ways, and the internal
timers can also be used, allowing serial communications in a number of modes, both
synchronous and asynchronous. Some modes allow communications with no external
components. A mode compatible with an RS-485 multi-point communications environment is
achievable, but the 8051's real strength is fitting in with existing ad-hoc protocols (e.g., when
controlling serial-controlled devices).
Once a UART, and a timer if necessary, have been configured, the programmer needs only to
write a simple interrupt routine to refill the sendshift register whenever the last bit is shifted out
by the UART and/or empty the full receive shift register (copy the data somewhere else). The
main program then performs serial reads and writes simply by reading and writing 8-bit data to
stacks.
8051 based microcontrollers typically include one or two UARTs, two or three timers, 128 or
256 bytes of internal data RAM (16 bytes of which are bit-addressable), up to 128 bytes of I/O,
512 bytes to 64 kB of internal program memory, and sometimes a quantity of extended data
RAM (ERAM) located in the external data space. The original 8051 core ran at 12 clock cycles
per machine cycle, with most instructions executing in one or two machine cycles. With a
12 MHz clock frequency, the 8051 could thus execute 1 million one-cycle instructions per
second or 500,000 two-cycle instructions per second. Enhanced 8051 cores are now commonly
used which run at six, four, two, or even one clock per machine cycle, and have clock
frequencies of up to 100 MHz, and are thus capable of an even greater number of instructions per
second. All SILabs, some Dallas and a few Atmel devices have single cycle cores.
Even higher speed single cycle 8051 cores, in the range 130 MHz to 150 MHz, are now available
in internet downloadable form for use inprogrammable logic devices such as FPGAs, and at
many hundreds of MHz in ASICs, for example the netlist from www.e8051.com. Top clock
speed 8051 cores reach over 200 MHz in today's FPGA technologies - as an
example www.dcd.pl.
Common features included in modern 8051 based microcontrollers include built-in reset timers
with brown-out detection, on-chip oscillators, self-programmable Flash ROM program memory,
bootloader code in ROM, EEPROM non-volatile data storage, I²C, SPI, and USB host
interfaces, CAN or LIN bus, PWM generators, analog
comparators, A/D and D/A converters, RTCs, extra counters and timers, in-circuit debugging
facilities, more interrupt sources, and extra power saving modes.
PROGRAMMING
There are various high level language compilers for 8051. Several C compilers are available for
the 8051, most of which feature extensions that allow the programmer to specify where each
variable should be stored in its six types of memory, and provide access to 8051 specific
hardware features such as the multiple register banks and bit manipulation instructions. There are
many commercial C compilers. SDCC is a popular open source C compiler. Other high level
languages such as Forth, BASIC, Pascal/Object Pascal, PL/M and Modula 2 are available for the
8051, but they are less widely used than C and assembly.
INTRODUCTION TO LIGHT SENSING
ROBOT
Light Sensing Robot is an electronic device that can sense and follow light. It moves in the
direction where the intensity of light sensed is greater. A user can shine a flashlight at its front
and Light Sensing Robot will respond by following the light source. Its speed is dependent upon
the intensity of the light detected. Light Sensing Robot uses a microcontroller for processing the
sensor readings and responds by controlling the motors.
Light Sensing Robot has two major modes of operation: calibration, and follow. These modes are
controlled by the main state machine. This organization, combined with the need for timed
motor, sensor, and LED control naturally lead to a timed based scheduler program. Only one ISR
was necessary-Timer0 Clear on Compare Match, which interrupts every 1 ms and updates the
timers used in the program.
The basic component which controls the device movements and calculations is the 8051
microcontroller. 8051 microcontroller is a 40 pin IC including pins for +5 volt supply, reset,
crystal oscillator and four ports of eight pins each. These port pins are connected to various
components which are to be controlled by the microcontroller.
Next is used 8 pin IC named MAX232 which is very useful as a translator. It converts the logic 0
& 1 of microcontroller to logic 0 & 1 of CPU so that the programming done according to logic 0
& 1 of microcontroller can be understood by CPU.
Regulator 7805 is also required to convert the incoming voltage of 12V to 5volts. This is
required because 8051 works on +5 volt supply. Hence after converting it to 5 volt, it is send to
1st pin of microcontroller.
D.C. motors are used as the wheels of light sensor robot. These are also connected indirectly to
8051 because they will move either clockwise or anticlockwise depending on the intensity of
light which will be calculated by 8051 only. But one more IC is required to operate them, this is
IC L293D, which is also an 8 pin IC and helps connecting motors to microcontroller.
These were the basic components required. Other small components are also used like
capacitors, resistors, LED, reset button and so on.
In addition to these, various software’s are also used. These are keil uvision2 required for the
programming of the device in embedded C language. Another is flash magic used for
downloading the hex file of the written program to the device with help of data cable and com
port.
The specifications, description and respective programs of some of the major components used
are described hereafter.
MAX232
Description
voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-F inputs 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. The driver, receiver,
and
voltage-generator functions are available as cells in the Texas Instruments LinASIC library.
FEATURES
Meets or Exceeds TIA/EIA-232-F and ITU
Operates From a Single 5-V Power Supply
With 1.0-_F Charge-Pump Capacitors
Operates Up To 120 kbit/s
Two Drivers and Two Receivers
±30-V Input Levels
Low Supply Current . . . 8 mA Typical
ESD Protection Exceeds JESD 22
2000-V Human-Body Model (A114-A)
Upgrade With Improved ESD (15-kV HBM)
and 0.1-_F Charge-Pump Capacitors is
REGULATOR 7805
Description
The MC78XX/LM78XX/MC78XXA series of three terminal positive regulators are available in
the TO-220/D-PAK package and with several fixed output voltages, making them useful in a
wide range of
applications. Each type employs internal current limiting, thermal shut down and safe operating
area protection, making it essentially indestructible. If adequate heat sinking is provided, they
can deliver over 1A output current.
Although designed primarily as fixed voltage regulators,
these devices can be used with external components to
obtain adjustable voltages and currents.
Features
• Output Current up to 1A
Circuit symbol:
CONNECTING AND SOLDERING
LEDs must be connected the correct way round, the diagram may be labelled
a or + for anode and k or - for cathode (yes, it really is k, not c, for cathode!).
The cathode is the short lead and there may be a slight flat on the body of
round LEDs. If you can see inside the LED the cathode is the larger electrode
(but this is not an official identification method).
LEDs can be damaged by heat when soldering, but the risk is small unless you are very slow. No
special precautions are needed for soldering most LEDs.
TESTING AN LED
Never connect an LED directly to a battery or power supply!
It will be destroyed almost instantly because too much current will pass through and burn it out.
LEDs must have a resistor in series to limit the current to a safe value,
for quick testing purposes a 1k resistor is suitable for most LEDs if
your supply voltage is 12V or less. Remember to connect the LED the
correct way round.
COLOURS OF LEDS
LEDs are available in red, orange, amber, yellow,
green, blue and white. Blue and white LEDs are
much more expensive than the other colours.
V = IR
Resistors are elements of electrical networks and electronic circuits and are ubiquitous in most
electronic equipment. Practical resistors can be made of various compounds and films, as well
as resistance wire (wire made of a high-resistivity alloy, such as nickel/chrome).
The primary characteristics of a resistor are the resistance, the tolerance, maximum working
voltage and the power rating. Other characteristics include temperature coefficient, noise,
and inductance. Less well-known is critical resistance, the value below which power dissipation
limits the maximum permitted current flow, and above which the limit is applied voltage. Critical
resistance depends upon the materials constituting the resistor as well as its physical dimensions;
it's determined by design.
A DC motor is designed to run on DC electric power. A simple 2-pole DC electric motor (here
red represents a magnet or winding with a "North" polarization, while green represents a magnet
or winding with a "South" polarization).
Every DC motor has six basic parts -- axle, rotor (a.k.a., armature), stator, commutator, field
magnet(s), and brushes. In most common DC motors (and all that BEAMers will see), the
external magnetic field is produced by high-strength permanent magnets1. The stator is the
stationary part of the motor -- this includes the motor casing, as well as two or more permanent
magnet pole pieces. The rotor (together with the axle and attached commutator) rotate with
respect to the stator. The rotor consists of windings (generally on a core), the windings being
electrically connected to the commutator. The above diagram shows a common motor layout --
with the rotor inside the stator (field) magnets.
By far the most common DC motor types are the brushed and brushless types, which use internal
and external commutation respectively to create an oscillating AC current from the DC source—
so they are not purely DC machines in a strict sense.
BRUSHED DC MOTORS
The classic DC motor design generates an oscillating current in a wound rotor, or armature, with
a split ring commutator, and either a wound or permanent magnet stator. A rotor consists of one
or more coils of wire wound around a core on a shaft; an electrical power source is connected to
the rotor coil through the commutator and its brushes, causing current to flow in it, producing
electromagnetism. The commutator causes the current in the coils to be switched as the rotor
turns, keeping the magnetic poles of the rotor from ever fully aligning with the magnetic poles of
the stator field, so that the rotor never stops (like a compass needle does) but rather keeps
rotating indefinitely (as long as power is applied and is sufficient for the motor to overcome the
shaft torque load and internal losses due to friction, etc.)
Many of the limitations of the classic commutator DC motor are due to the need for brushes to
press against the commutator. This creates friction. At higher speeds, brushes have increasing
difficulty in maintaining contact. Brushes may bounce off the irregularities in the commutator
surface, creating sparks. (Sparks are also created inevitably by the brushes making and breaking
circuits through the rotor coils as the brushes cross the insulating gaps between commutator
sections. Depending on the commutator design, this may include the brushes shorting together
adjacent sections—and hence coil ends—momentarily while crossing the gaps. Furthermore,
the inductance of the rotor coils causes the voltage across each to rise when its circuit is opened,
increasing the sparking of the brushes.) This sparking limits the maximum speed of the machine,
as too-rapid sparking will overheat, erode, or even melt the commutator. The current density per
unit area of the brushes, in combination with their resistivity, limits the output of the motor. The
making and breaking of electric contact also causeselectrical noise, and the sparks additionally
cause RFI. Brushes eventually wear out and require replacement, and the commutator itself is
subject to wear and maintenance (on larger motors) or replacement (on small motors). The
commutator assembly on a large machine is a costly element, requiring precision assembly of
many parts. On small motors, the commutator is usually permanently integrated into the rotor, so
replacing it usually requires replacing the whole rotor.
Large brushes are desired for a larger brush contact area to maximize motor output, but small
brushes are desired for low mass to maximize the speed at which the motor can run without the
brushes excessively bouncing and sparking (comparable to the problem of "valve float" in
internal combustion engines). (Small brushes are also desirable for lower cost.) Stiffer brush
springs can also be used to make brushes of a given mass work at a higher speed, but at the cost
of greater friction losses (lower efficiency) and accelerated brush and commutator wear.
Therefore, DC motor brush design entails a trade-off between output power, speed, and
efficiency/wear.
BRUSHLESS DC MOTORS
Some of the problems of the brushed DC motor are eliminated in the brushless design. In this
motor, the mechanical "rotating switch" or commutator/brushgear assembly is replaced by an
external electronic switch synchronised to the rotor's position. Brushless motors are typically 85-
90% efficient or more (higher efficiency for a brushless electric motor of up to 96.5% were
reported by researchers at the Tokai University in Japan in 2009[16]), whereas DC motors with
brushgear are typically 75-80% efficient.
Brushless DC motors are commonly used where precise speed control is necessary, as in
computer disk drives or in video cassette recorders, the spindles within CD, CD-ROM (etc.)
drives, and mechanisms within office products such as fans, laser printers and photocopiers.
L293D Motor Driver IC
The L293D is a quadruple push-pull 4 channel driver capable of delivering 600 mA (1.2
A peak surge) per channel. The L293D is ideal for controlling the
forward/reverse/brake motions of small DC motors controlled by a microcontroller such
as a PIC or BASIC Stamp.
The L293D is a high voltage, high current four channel driver designed to accept
standard TTL logic levels and drive inductive loads (such as relays solenoids, DC and
stepping motors) and switching power transistors. The L293D is suitable for use in
switching applications at frequencies up to 5 KHz.
FEATURES INCLUDE :
Pin diagram :
CIRCUIT FOR CONTROLLING DC MOTOR USING IC L293D
This is a very basic circuit.It describes the pin connections of IC L293D i.e. a push pull four
channel driver with diodes. L293D is a monolithic integrated high voltage, high current
four channel driver designed to accept standard DTL or TTL logic levels and drive
inductive loads and switching power transistors.It has 600mA output current capability
per channel and 1.2A peak output current per channel (non repetitive).
Sample Programs:-
#include <REG51F.H>
sbit en12=P1^0;
sbit ip1=P1^1;
sbit ip2=P1^2;
void rx();
void tx();
void timer1();
void main()
{ en12=1;
timer1();
while(1)
{ rx();
tx();
if(ch=='A')
{ en12=1;
ip1=1;
ip2=0;
if(ch=='B')
{ en12=0;
ip1=0;
ip2=0;
}
void rx()
{ while(!RI);
ch=SBUF;
RI=0;
void tx()
{ while(!TI);
SBUF=ch;
TI=0;
void timer1()
{ TMOD=0x20;
TH1=0xfd;
TR1=1;
SCON=0x52;
#include <REG51F.H>
sbit ip1=P1^1;
sbit ip2=P1^2;
void main()
{ ton=0x10;
toff=0x54;
while(1)
{ if(ton==0)
{ if (toff==0)
{ ton=0x10;
toff=0x54;
else
{ en12=0;
toff--;
else
{ en12=1;
ton--;
ip1=1;
ip2=0;
}
LIGHT DEPENDENT RESISTOR (LDR)
A photoresistor or light dependent resistor is a component that is sensitive to light. When light
falls upon it then the resistance changes. Values of the resistance of the LDR may change over
many orders of magnitude the value of the resistance falling as the level of light increases.
LDRs are made from semiconductor materials to enable them to have their light sensitive
properties. Many materials can be used, but one popular material for these photoresistors is
cadmium sulphide (CdS).
It is relatively easy to understand the basics of how an LDR works without delving into
complicated explanations. It is first necessary to understand that an electrical current consists of
the movement of electrons within a material. Good conductors have a large number of free
electrons that can drift in a given direction under the action of a potential difference. Insulators
with a high resistance have very few free electrons, and therefore it is hard to make the them
move and hence a current to flow.
An LDR or photoresistor is made any semiconductor material with a high resistance. It has a
high resistance because there are very few electrons that are free and able to move - the vast
majority of the electrons are locked into the crystal lattice and unable to move. Therefore in this
state there is a high LDR resistance.
As light falls on the semiconductor, the light photons are absorbed by the semiconductor lattice
and some of their energy is transferred to the electrons. This gives some of them sufficient
energy to break free from the crystal lattice so that they can then conduct electricity. This results
in a lowering of the resistance of the semiconductor and hence the overall LDR resistance.
The process is progressive, and as more light shines on the LDR semiconductor, so more
electrons are released to conduct electricity and the resistance falls further.
FEATURES
Case Style:Radial
Dark Resistance:20Mohm
Rating Voltage:200V dc
Resistor Element Type:Light Dependent
Body Diameter:5.1mm
External Length / Height:2.3mm
External Width:4.3mm
Lead Diameter:0.48mm
Lead Length:30mm
Max Operating Temperature:30°C
Max Resistance @ Lux A:100kohm
Max Resistance @ Lux B:2000kohm
Min Resistance @ Lux A:20kohm
Min Resistance @ Lux B:500kohm
Peak Spectral Response Wavelength:550nm
Power Dissipation:60mW
Resistance @ Lux A:100kohm
Voltage Rating AC:200V
Voltage Rating DC:200V
ANALOG TO DIGITAL CONVERTER
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-bus interface. 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.
PIN DIAGRAM:-
ADDRESSING
Each PCF8591 device in an I2C-bus system is activated by sending a valid address to the device.
The address consists of a fixed part and a programmable part. The programmable part must be
set according to the address pins A0, A1 and A2. The address always has to be sent as the first
byte after the start condition in the I2C-bus protocol. The last bit of the address byte is the
read/write-bit which sets the direction of the following data transfer.
The second byte sent to a PCF8591 device will be stored in its control register and is required to
control the device function. The upper nibble of the control register is used for enabling the
analog output, and for programming the analog inputs as single-ended or differential inputs. The
lower nibble selects one of the analog input channels defined by the upper nibble (see Fig.4). If
the auto-increment flag is set the channel number is incremented automatically after each A/D
conversion. If the auto-increment mode is desired in applications where the internal oscillator is
used, the analog output enable flag in the control byte (bit 6) should be set. This allows the
internal oscillator to run continuously, thereby preventing conversion errors resulting from
oscillator start-up delay. The analog output enable flag may be reset at other times to reduce
quiescent power consumption. The selection of a non-existing input channel results in the highest
available channel number being allocated. Therefore, if the auto-increment flag is set, the next
selected channel will be always channel 0. The most significant bits of both nibbles are reserved
for future functions and have to be set to 0. After a Power-on reset condition all bits of the
control register are reset to 0. The D/A converter and the oscillator are disabled for power saving.
The analog output is switched to a high-impedance state.
CONNECTIONS OF ADC WITH MICROCONTROLLER
INTER INTEGRATED CIRCUIT (I2C)
I2C bus often used to communicate across circuit-board distances. I2C bus provides good
support for communication with various slow,on-board peripheral devices that are access
intermittently. It is a simple, low bandwidth, short-distance protocol. I2C is easy to use to link
multiple devices together since it has a built-in addressing scheme.
I2C PINS
• SCL = Serial Clock – This signal will always be driven by the 8051in our example (8051
is always the master).
• SDA = Serial Data – This signal is driven by either the micro or the I2C peripheral chip.
• Both SCL and SDA are open-drain when output on the micro and on all I2C peripheral
chips.
TRANSFERRING OF BITS
One data bit is transferred during each clock pulse. The data on the SDA line must remain stable
during the HIGH period of the clock pulse as changes in the data line at this time will be
interpreted as a control signal.
A/D CONVERSION
The A/D converter makes use of the successive approximation conversion technique. The on-
chip D/A converter and a high-gain comparator are used temporarily during an A/D conversion
cycle.An A/D conversion cycle is always started after sending a valid read mode address to a
PCF8591 device. The A/D conversion cycle is triggered at the trailing edge of the acknowledge
clock pulse and is executed while transmitting the result of the previous conversion. Once a
conversion cycle is triggered an input voltage sample of the selected channel is stored on the chip
and is converted to the corresponding 8-bit binary code. The conversion result is stored in the
ADC data register and awaits transmission. If the auto-increment flag is set the next channel is
selected. The first byte transmitted in a read cycle contains the conversion result code of the
previous read cycle. After a Power-on reset condition the first byte read is a hexadecimal 80. The
maximum A/D conversion rate is given by the actual speed of the I2C-bus.
I2C-BUS PROTOCOL
After a start condition a valid hardware address has to be sent to a PCF8591 device. The
read/write bit defines the direction of the following single or multiple byte data transfer. For the
format and the timing of the start condition (S), the stop condition (P) and the acknowledge bit
(A) refer to the I2C-bus characteristics. In the write mode a data transfer is terminated by
sending either a stop condition or the start condition of the next data transfer.
CONDITIONS
ACKNOWLEDGE (ACK)-: NO ACKNOWLEDGE (NAK)-:
RET
RET
START CONDITION-: STOP CONDITION-:
YES
#include <REG51F.H>
#include<intrins.h>
void start();
void stop();
void ack();
void nak();
void m_d();
int shin();
void read_byte_adc();
bit flag = 0;
void main()
{ while(1)
{ read_byte_adc();
m_d();
void m_d()
{ en2=1;
en1=1;
dc1=dc3=1;
dc2=dc4=0;
else
{ en2=1;
en1=1;
dc1=dc3=0;
dc2=dc4=1;
void read_byte_adc()
{ start();
shout(0x90);
if (flag)
P0=0xf3;
else
{ shout(0x04);
if (flag)
P0=0xf1;
else
{ start();
shout(0x91);
if (flag)
P0=0xf2;
else
{ shin();
ack();
value=shin();
ack();
value1=shin();
// ack();
// value2=shin();
nak();
stop();
stop();
void start()
{ sda=1;
_nop_();
scl=1;
_nop_();
_nop_();
sda=0;
_nop_();
_nop_();
scl=0;
void stop()
{ sda=0;
scl=1;
_nop_();
_nop_();
sda=1;
_nop_();
_nop_();
scl=0;
for(k=0;k<8;k++)
j = j>>1;
scl = 1;
_nop_();
_nop_();
_nop_();
_nop_();
scl = 0;
sda = 1;
scl = 1;
_nop_();
_nop_();
flag = sda;
_nop_();
_nop_();
scl = 0;
int shin()
sda=1;
for(i=0;i<8;i++)
{ scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
flag = sda;
if(flag)
q = (q|c);
c = c>>1;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
return q;
void ack()
{ sda=0;
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0; }
void nak()
{ sda=1;
scl=1;
_nop_();
_nop_();
_nop_();
_nop_();
scl=0;
}
PROJECT APPLICATIONS
TINY LIGHT SENSOR WITH LOGIC OUTPUT DRAWS LESS THAN 10ΜA
A light-sensing circuit that consumes very little power can serve as an automatic Backlight
sensor in portable instruments. This function is easily implemented with a logic gate or Schmitt-
trigger inverter, but those approaches draw a considerable amount of supply current.This light
sensor provides a low-to-high output transition at a light level determined by the value of R1.
Because the lighting required to enable either LED is controlled by individual potentiometers,
they can be set such that either, neither, or both LEDs turn on. That is, the red LED doesn't have
to turn on simply because the green LED turned off.