Вы находитесь на странице: 1из 71




An Embedded System is a combination of computer hardware and software,

and perhaps additional mechanical or other parts, designed to perform a specific
function. An embedded system is a microcontroller-based, software driven, reliable,
real-time control system, autonomous, or human or network interactive, operating on
diverse physical variables and in diverse environments and sold into a competitive
and cost conscious market.

An embedded system is not a computer system that is used primarily for

processing, not a software system on PC or UNIX, not a traditional business or
scientific application. High-end embedded & lower end embedded systems. High-end
embedded system - Generally 32, 64 Bit Controllers used with OS. Examples
Personal Digital Assistant and Mobile phones etc. Lower end embedded systems -
Generally 8, 16 Bit Controllers used with a minimal operating systems and hardware
layout designed for the specific purpose.

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

completely encapsulated by or dedicated to the device or system it controls. Unlike a
general-purpose computer, such as a personal computer, an embedded system
performs one or a few pre-defined tasks, usually with very specific requirements.
Since the system is dedicated to specific tasks, design engineers can optimize it,
reducing the size and cost of the product. Embedded systems are often mass-
produced, benefiting from economies of scale.

Personal digital assistants (PDAs) or handheld computers are generally

considered embedded devices because of the nature of their hardware design, even
though they are more expandable in software terms. This line of definition continues
to blur as devices expand.

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.

In terms of complexity embedded systems can range from very simple with a
single microcontroller chip, to very complex with multiple units, peripherals and
networks mounted inside a large chassis or enclosure.

System Design Calls:

Digital Operating Integrated circuit

Electronic design Systems design

Analog Build
Electronic design Download
Embedded Tools
Sensors and
Measurements Computer

Electric motors
and actuators Software
Control Data Engineering
Engineering Communication

Embedded system design calls on many disciplines

Fig.1.1 Embedded system design calls

Embedded System Design Cycle:


Rapid Hardware -
Prototyping in-the-Loop


Fig.1.2 Embedded system design cycle

Characteristics of Embedded System:

1. An embedded system is any computer system hidden inside a product other than a
2. They will encounter a number of difficulties when writing embedded system software
in addition to those we encounter when we write applications.

a. Throughput Our system may need to handle a lot of data in a short

period of time.
b. ResponseOur system may need to react to events quickly.
c. TestabilitySetting up equipment to test embedded software can be
d. DebugabilityWithout a screen or a keyboard, finding out what the
software is doing wrong (other than not working) is a troublesome
e. Reliability embedded systems must be able to handle any situation
without human intervention.

f. Memory space Memory is limited on embedded systems, and you
must make the software and the data fit into whatever memory exists.
g. Program installation you will need special tools to get your software
into embedded systems.
h. Power consumption Portable systems must run on battery power, and
the software in these systems must conserve power.
i. Processor hogs computing that requires large amounts of CPU time
can complicate the response problem.
j. Cost Reducing the cost of the hardware is a concern in many
embedded system projects; software often operates on hardware that is
barely adequate for the job.
3. Embedded systems have a microprocessor/ microcontroller and a memory.
Some have a serial port or a network connection. They usually do not have
keyboards, screens or disk drives.


1. Military and aerospace embedded software applications

2. Communication Applications
3. Industrial automation and process control software
4. Mastering the complexity of applications.
5. Reduction of product design time.
6. Real time processing of ever increasing amounts of data.
7. Intelligent, autonomous sensors.


1. Real Time Systems.

2. RTS is one which has to respond to events within a specified deadline.
3. A right answer after the dead line is a wrong answer.

RTS Classification

1. Hard Real Time Systems
2. Soft Real Time System
Hard Real Time System
1. "Hard" real-time systems have very narrow response time.
2. Example: Nuclear power system, Cardiac pacemaker.
Soft Real Time System
1. "Soft" real-time systems have reduced constrains on "lateness" but still must
operate very quickly and repeatable.
2. Example: Railway reservation system takes a few extra seconds the data
remains valid.

Examples of Embedded Systems:

1. Automatic teller machines (ATMs)
2. Avionics, such as inertial guidance systems, flight control hardware/software
and other integrated systems in aircraft and missiles

3. Cellular telephones and telephone switches

4. engine controllers and antilock brake controllers for automobiles

5. Home automation products, such as thermostats, air conditioners, sprinklers,

and security monitoring systems

6. Handheld calculators

7. Handheld computers

8. Household appliances, including microwave ovens, washing machines,

television sets, DVD players and recorders

9. Medical equipment

10. Personal digital assistant

11. Videogame consoles

12. Computer peripherals such as routers and printers

13. Industrial controllers for remote machine operation.


In the earliest years of computers in the 1940s, computers were sometimes

dedicated to a single task, but were too large to be considered "embedded". Over time
however, the concept of programmable controllers developed from a mix of computer
technology, solid state devices, and traditional electromechanical sequences.

The first recognizably modern embedded system was the Apollo Guidance
Computer, developed by Charles Stark Draper at the MIT Instrumentation Laboratory.
At the project's inception, the Apollo guidance computer was considered the riskiest
item in the Apollo project. The use of the then new monolithic integrated circuits, to
reduce the size and weight, increased this risk.

The first mass-produced embedded system was the Autonetics D-17 guidance
computer for the Minuteman (missile), released in 1961. It was built from transistor
logic and had a hard disk for main memory. When the Minuteman II went into
production in 1966, the D-17 was replaced with a new computer that was the first
high-volume use of integrated circuits. This program alone reduced prices on quad
nand gate ICs from $1000/each to $3/each, permitting their use in commercial

Since these early applications in the 1960s, embedded systems have come
down in price. There has also been an enormous rise in processing power and
functionality. For example the first microprocessor was the Intel 4004, which found
its way into calculators and other small systems, but required external memory and
support chips.

In 1978 National Engineering Manufacturers Association released the standard

for a programmable microcontroller. The definition was an almost any computer-
based controller. They included single board computers, numerical controllers, and
sequential controllers in order to perform event-based instructions.

By the mid-1980s, many of the previously external system components had
been integrated into the same chip as the processor, resulting in integrated circuits
called microcontrollers, and widespread use of embedded systems became feasible.

As the cost of a microcontroller fell below $1, it became feasible to replace

expensive knob-based analog components such as potentiometers and variable
capacitors with digital electronics controlled by a small microcontroller with up/down
buttons or knobs. By the end of the 80s, embedded systems were the norm rather than
the exception for almost all electronics devices, a trend which has continued since.


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 reason such as safety and usability; others may have
low or no performance requirements, allowing the system hardware to be simplified
to reduce costs.

User Interfaces

Embedded systems range from no user interface at all - dedicated only to one
task - to full user interfaces similar to desktop operating systems in devices such as

Simple Systems

Simple embedded devices use buttons, LEDs, and small character- or digit-
only displays, often with a simple menu system.

In More Complex Systems

A full graphical screen, with touch sensing or screen-edge buttons provides

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.

The rise of the World Wide Web has given embedded designers another quite different
option: providing a web page interface over a network connection.

This avoids the cost of a sophisticated display, yet provides complex input and
display capabilities when needed, on another computer. This is successful for remote,
permanently installed equipment. In particular, routers take advantage of this ability.

CPU Platform
Embedded processors can be broken into two distinct categories:
microprocessors (p) and microcontrollers (c). Micro controllers have built-in
peripherals on the chip, reducing size of the system.
There are many different CPU architectures used in embedded designs such as
ARM, MIPS, Cold fire/68k, PowerPC, x86, PIC, 8051, Atmel AVR, Renesas H8, SH,
V850, FR-V, M32R, Z80, Z8, etc. This in contrast to the desktop computer market,
which is currently limited to just a few competing architectures.

PC/104 and PC/104+ are a typical base for small, low-volume embedded and
rugged system design. These often use DOS, Linux, Net BSD, or an embedded real-
time operating system such as QNX or Vx Works. A common configuration for very-
high-volume embedded systems is the system on a chip (SoC), an application-specific
integrated circuit (ASIC), for which the CPU core was purchased and added as part of
the chip design. A related scheme is to use a field-programmable gate array (FPGA),
and program it with all the logic, including the CPU.


Embedded Systems talk with the outside world via peripherals, such as:

1. Serial Communication Interfaces (SCI): RS-232, RS-422, RS-485 etc.,

2. Synchronous Serial Communication Interface: I2C, JTAG, SPI, SSC and ESSI

3. Universal Serial Bus (USB)

4. Networks: Controller Area Network, Lon Works, etc.,

5. Timers: PLL(s), Capture/Compare and Time Processing Units

6. Discrete IO: aka General Purpose Input Output (GPIO).


As for other software, embedded system designers use compilers, assemblers, and
debuggers to develop embedded system software. However, they may also use some
more specific tools:

1. An in-circuit emulator (ICE) is a hardware device that replaces or plugs into

the microprocessor, and provides facilities to quickly load and debug
experimental code in the system.
2. Utilities to add a checksum or CRC to a program, so the embedded system can
check if the program is valid.

3. For systems using digital signal processing, developers may use a math
workbench such as Mathcad or Mathematic to simulate the mathematics.

4. Custom compilers and linkers may be used to improve optimization for the
particular hardware.


Embedded Debugging may be performed at different levels, depending on the

facilities available, ranging from assembly- or source-level debugging with an in-
circuit emulator or in-circuit debugger, to output from serial debug ports or
JTAG/Nexus interfaces, to an emulated environment running on a personal computer.
As the complexity of embedded systems grows, higher level tools and operating
systems are migrating into machinery where it makes sense. For example, cell phones,
personal digital assistants and other consumer computers often need significant
software that is purchased or provided by a person other than the manufacturer of the
electronics. In these systems, an open programming environment such as Linux, Net
BSD, OSGi or Embedded Java is required so that the third-party software provider
can sell to a large market.


Embedded systems often reside in machines that are expected to run

continuously for years without errors, and in some cases recover by themselves if an
error occurs.

Therefore the software is usually developed and tested more carefully than
that for personal computers, and unreliable mechanical moving parts such as disk
drives, switches or buttons are avoided. Recovery from errors may be achieved with
techniques such as a watchdog timer that resets the computer unless the software
periodically notifies the watchdog.

Specific Reliability Issues May Include

1. The system cannot safely be shut down for repair, or it is too inaccessible to
repair. Solutions may involve subsystems with redundant spares that can be
switched over to, or software "limp modes" that provide partial function.
Examples include space systems, undersea cables, navigational beacons, bore-
hole systems, and automobiles.
2. The system must be kept running for safety reasons. "Limp modes" are less
tolerable. Often backups are selected by an operator. Examples include aircraft
navigation, reactor control systems, safety-critical chemical factory controls,
train signals, engines on single-engine aircraft.

3. The system will lose large amounts of money when shut down: Telephone
switches, factory controls, bridge and elevator controls, funds transfer and
market making, automated sales and service.

High vs. Low Volume

For high volume systems such as portable music players or mobile phones,
minimizing cost is usually the primary design consideration. Engineers typically select
hardware that is just good enough to implement the necessary functions. For low-volume or
prototype embedded systems, general purpose computers may be adapted by limiting the
programs or by replacing the operating system with a real-time operating system.

Embedded Software Architectures

There are several different types of software architecture in common use.
Simple control loop. In this design, the software simply has a loop. The loop calls
subroutines, each of which manages a part of the hardware or software.

Interrupt Controlled System

Some embedded systems are predominantly interrupt controlled. This means

that tasks performed by the system are triggered by different kinds of events. An
interrupt could be generated for example by a timer in a predefined frequency, or by a
serial port controller receiving a byte. These kinds of systems are used if event
handlers need low latency and the event handlers are short and simple.

Usually these kinds of systems run a simple task in a main loop also, but this
task is not very sensitive to unexpected delays. The tasks performed in the interrupt
handlers should be kept short to keep the interrupt latency to a minimum.
Some times longer tasks are added to a queue structure in the interrupt
handler to be processed in the main loop later. This method brings the system close to
a multitasking kernel with discrete processes.

Cooperative Multitasking

A no preemptive multitasking system is very similar to the simple control loop

scheme, except that the loop is hidden in an API. The programmer defines a series of
tasks, and each task gets its own environment to "run" in. Then, when a task is idle, it
calls an idle routine (usually called "pause", "wait", "yield", etc.).

The advantages and disadvantages are very similar to the control loop, except
that adding new software is easier, by simply writing a new task, or adding to the

Preemptive Multitasking

In this type of system, a low-level piece of code switches between tasks based
on a timer. This is the level at which the system is generally considered to have an

"operating system", and introduces all the complexities of managing multiple tasks
running seemingly at the same time.

Because of these complexities, it is common for organizations to buy a real-

time operating system, allowing the application programmers to concentrate on device
functionality rather than operating system services.

Embedded Applications

1. Navigation system using a GPS receiver;

2. Communications systems for protocol conversion and VoIP;
3. Mobile data applications using BREWMP3 player and salary survey;
4. Real-time systems using RT Linuxprinting, messaging and more;
5. Windows CE database applications salary survey and energy meter reading;
6. Networked information appliances using the HP Chai Appliance Platform
CRM, location-based services and more;
7. Mobile Java applianceselectronic city guide, Jini appliance control, AC
Remote application;
8. Windows XP embedded applications air conditioner remote control, audio
player remote control, typing speed indicator, database application, electronic





Micro Relay Device1



Transistor Device2

Fig. 2.1 Transmitter section

2.2.1 Introduction

The AT89S52 is a low-power, high-performance CMOS 8-bit micro controller

with 8Kbytes of in-system programmable Flash memory. The device is manufactured
using Atmels high-density nonvolatile memory technology and is compatible with the
industry-standard 80C51 micro controller. 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 in-system programmable flash
one monolithic chip; the Atmel AT89S52 is a powerful micro controller, which
provides a highly flexible and cost-effective solution to many embedded control

Fig.2.3 Pin configuration

2.2.2 Pin Description

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 1sare written to port 0 pins, the pins
can be used as high impedance inputs. Port 0 can 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 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. In
addition, 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, as
shown in the following table. Port 1 also receives the low-order address bytes
during Flash programming and verification.

Table 2.1 Port 1 pin description

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. 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
(MOVX @DPTR). In this application, Port 2 uses strong internal pull-ups when
emitting 1s. During accesses to external data memory that use 8-bit addresses
(MOVX @ RI), Port 2emits 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 writt 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 AT89S52, as shown in the following table. Port 3 also
receives some control signals for Flash programming and verification.

Table 2.2 Pin description

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 (ALE) 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 of1/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.

PSEN: Program Store Enable (PSEN) is the read strobe to external program
memory. When the AT89S52 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. A should be strapped to VCC for internal
program executions. This pin also receives the 12-voltProgramming enables
voltage (VPP) during Flash programming.

XTAL1: Input to the inverting oscillator amplifier and input to the internal clock
operating circuit.

XTAL2: Output from the inverting oscillator amplifier.

Oscillator Characteristics

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
Figure1. 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 Figure 2.

Fig 2.4 Oscillator Connections

2.2.3 Architecture of the Microcontroller:

Fig.2.5 Architecture Of Micro Controller

2.2.4 Special Function Register (SFR) Memory

Special Function Registers (SFR s) are areas of memory that control

specific functionality of the 8051 processor. For example, four SFRs permit
access to the 8051s 32 input/output lines. Another SFR allows the user to set the
serial baud rate, control and access timers, and configure the 8051s interrupt


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

The R Registers:

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

The B Registers:

The B register is very similar to the accumulator in the sense that it

may hold an 8-bit (1-byte) value. Two only uses the B register 8051
instructions: MUL AB and DIV AB.

The Data Pointer:

The Data pointer (DPTR) is the 8051s only user accessible 16-bit
(2Bytes) register. The accumulator, R registers are all 1-Byte values. DPTR, as
the name suggests, is used to point to data. It is used by a number of commands,
which allow the 8051 to access external memory.

The Program Counter And Stack Pointer:

The program counter (PC) is a 2-byte address, which tells the 8051 where
the next instruction to execute is found in memory. The stack pointer like all
registers except DPTR and PC may hold an 8-bit (1-Byte) value

2.2.5 Addressing Modes

An addressing mode refers that you are addressing a given memory

location. In summary, the addressing modes are as follows

Immediate Addressing MOV A, #20 H

Direct Addressing MOV A, 30

Indirect Addressing MOV A, @RO

Indexed Addressing

a. External Direct MOVX A, @DPTR

b.Code In direct MOVC A, @A+DPTR

Immediate Addressing:

Immediate addressing is so named because the value to be stored in

memory immediately follows the operation code in memory. That is to say, the
instruction itself dictates what value will be stored in memory. For example, the

MOV A, #20H;

This instruction uses immediate Addressing because the accumulator will

be loaded with the value that immediately follows in this case 20(hexadecimal).
Immediate addressing is very fast since the value to be loaded is included in the
instruction. However, since the value to be loaded is fixed at compile-time it is
not very flexible.

Direct Addressing:

Direct addressing is so named because the value to be stored in memory

is obtained by directly retrieving it from another memory location.

MOV A, 30h;

This instruction will read the data out of internal RAM address
30(hexadecimal) and store it in the Accumulator. Direct addressing is generally
fast since, although the value to be loaded isnt included in the instruction, it is
quickly accessible since it is stored in the 8051s internal RAM. It is also much
more flexible than Immediate Addressing since the value to be loaded is whatever
is found at the given address which may variable.

Also it is important to note that when using direct addressing any

instruction that refers to an address between 00h and 7Fh is referring to the SFR
control registers that control the 8051 micro controller itself.

Indirect Addressing:

Indirect addressing is a very powerful addressing mode, which in many
cases provides an exceptional level of flexibility. Indirect addressing is also the
only way to access the extra 128 bytes of internal RAM found on the 8052.
Indirect addressing appears as follows:

MOV A, @R0H;

This instruction causes the 8051 to analyze Special Function Register

(SFR) Memory:

Special Function Registers (SFRs) are areas of memory that control

specific functionality of the 8051 processor. For example, four SFRs permit
access to the 8051s 32 input/output lines. Another SFR allows the user to set the
serial baud rate, control and access timers, and configure the 8051s interrupt

2.2.6 Timers and Counters:

Timer 2 Registers:

Control and status bits are contained in registers T2CON and

T2MOD for Timer 2. The register pair (RCAP2H , RCAP2L) are the
Capture / Reload registers for Timer 2 in 16-bit capture mode or 16-bit
auto-reload mode.

Interrupt Registers:

The individual interrupt enable bits are in the IE register .

Table 2.3 Timer and interrupt

Timer 2:

Timer 2 is a 16-bit Timer / Counter that can operate as either a timer

or an event counter. The type of operation is selected by bit C/T2 in the SFR
T2CON. Timer 2 has three operating Modes : capture , auto-reload ( up or down
Counting ) , and baud rate generator . The modes are selected by bits in T2CON.
Timer 2 consists of two

8-bit registers, TH2 and TL2. In the Timer function, the TL2 register is
incremented every machine cycle. Since a machine cycle consists of 12
oscillator periods, the count rate is 1/12 of the oscillator frequency. In the
Counter function , the register is incremented in response to a 1-to-0
transition at its corresponding external input pin , T2 .When the samples show a
high in one cycle and a low in the next cycle, the count is incremented .

Since two machine cycles (24 Oscillator periods ) are required to

recognize 1-to-0 transition , the maximum count rate is 1 / 24 of the oscillator
frequency .

To ensure that a given level is sampled at least once before it
changes , the level should be held for at least one full machine cycle .

Capture Mode:

In the capture mode , two options are selected by bit EXEN2 in

T2CON . If EXEN2 = 0, Timer 2 is a 16-bit timer or counter which upon
overflow sets bit TF2 in T2CON . This bit can then be used to generate an
interrupt. If EXEN2 = 1 , Timer 2 performs the same operation , but a 1-to-0
transition at external input T2EX also causes the current value in TH2 and
TL2 to be captured into RCAP2H and RCAP2L , respectively

Auto-reload (Up or Down Counter):

Timer 2 can be programmed to count up or down when configured in

its 16-bit auto-reload mode. This feature is invoked by the DCEN (Down
Counter Enable) bit located in the SFR T2MOD Upon reset , the DCEN bit is
set to 0 so that timer 2 will default to count up. When DCEN is set , Timer 2
can count up or down , depending on the value of the T2EX pin . In this
mode , two options are selected by bit EXEN2 in T2CON . If EXEN2 = 0 ,
Timer 2 counts up to 0FFFFH and then sets the TF2 bit upon overflow . If
EXEN2 = 1 , a 16-bit reload can be triggered either by an overflow or by a
1-to-0 transition at external input T2EX.

Baud Rate Generator:

Baud Rate Generator is selected as the baud rate generator by setting

TCLK and/or RCLK in T2CON. Note that the baud rates for transmit and
receive can be different if Timer 2 is used for the receiver or transmitter and
Timer 1 is used for the other function .The baud rates in Modes 1 and 3 are
determined by Timer 2s overflow rate according to the following equation

Modes 1 and 3 Baud Rates =Timer 2 Overflow Rate


The timer operation is different for Timer 2 when it is used as a baud
rate generator .Normally ,as a timer , it increments every machine cycle (at 1/12
the oscillator frequency).As a baud rate generator , however, it increments every
state time ( at 1/2 the oscillator frequency ) .

Timer 0:

Timer 0 functions as either a timer or event counter in four modes of

operation . Timer 0 is controlled by the four lower bits of the TMOD register
and bits 0, 1, 4 and 5 of the TCON register.

Mode 0 (13-bit Timer):

Mode 0 configures timer 0 as a 13-bit timer which is set up as an

8-bit timer (TH0 register) with a modulo 32 prescaler implemented with the
lower five bits of the TL0 register . The upper three bits of TL0 register are
indeterminate and should be ignored. Prescaler overflow increments the
TH0 register.

Mode 1 (16-bit Timer):

Mode 1 is the same as Mode 0, except that the Timer register is

being run with all 16 bits. Mode 1 configures timer 0 as a 16-bit timer with
the TH0 and TL0 registers connected in cascade. The selected input
increments the TL0 register.

Mode 2 (8-bit Timer with Auto-Reload):

Mode 2 configures timer 0 as an 8-bit timer (TL0 register) that

automatically reloads from the TH0 register. TL0 overflow sets TF0 flag in
the TCON register and reloads TL0 with the contents of TH0, which is
preset by software.

Mode 3 (Two 8-bit Timers):

Mode 3 configures timer 0 so that registers TL0 and TH0 operate as

separate 8-bit timers. This mode is provided for applications requiring an
additional 8-bit timer or counter.

Timer 1:

Timer 1 is identical to timer 0 , except for mode 3 , which is a

hold-count mode .

Mode 3 (Halt):

Placing Timer 1 in mode 3 causes it to halt and hold its count. This
can be used to halt Timer 1 when TR1 run control bit is not available i.e.,
when Timer 0 is in mode 3.

Baud Rates:

The baud rate in Mode 0 is fixed. The baud rate in Mode 2

depends on the value of bit SMOD in Special Function Register PCON. If
SMOD = 0 (which is its value on reset), the baud rate is 1/64 the oscillator
frequency. If SMOD = 1, the baud rate is 1/32 the oscillator frequency. In the
89S52, the baud rates in Modes 1 and 3 are determined by the Timer 1
overflow rate. In case of Timer 2 , these baud rates can be determined by
Timer 1 , or by Timer 2 , or by both (one for transmit and the other for receive )

TCON REGISTER: Timer/counter Control Register

Table 2.4 TMOD Registers Timers/counter 0and 1 Modes

TMOD REGISTER: Timer/Counter 0 and 1 Modes

Table 2.5 TCON Register


2.3.1 Introduction

There are many types of power supply. Most are designed to convert high
voltage AC mains electricity to a suitable low voltage supply for electronic circuits
and other devices. A power supply can by broken down into a series of blocks, each of
which performs a particular function.

For example a 5V regulated supply:

INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/pwrsupre.gif" \*
"http://www.kpsec.freeuk.com/images/pwrsupre.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/pwrsupre.gif" \*
"http://www.kpsec.freeuk.com/images/pwrsupre.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/pwrsupre.gif" \*
"http://www.kpsec.freeuk.com/images/pwrsupre.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/pwrsupre.gif" \*
"http://www.kpsec.freeuk.com/images/pwrsupre.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/pwrsupre.gif" \*
"http://www.kpsec.freeuk.com/images/pwrsupre.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/pwrsupre.gif" \*

"http://www.kpsec.freeuk.com/images/pwrsupre.gif" \* MERGEFORMATINET

Fig. 2.6 Power supply

2.3.2 Transformer

Input 5v
Transformer Rectifier Smoothing Regulator
230 Ac

Fig. 2.7 Basic transformer

Each of the blocks is described in more detail below:

1. Transformer - steps down high voltage AC mains to low voltage AC.

2. Rectifier - converts AC to DC, but the DC output is varying.

3. Smoothing - smooths the DC from varying greatly to a small ripple.

4. Regulator - eliminates ripple by setting DC output to a fixed voltage.

Power supplies made from these blocks are described below with a circuit diagram
and a graph of their output:

1. Transformer only
2. Transformer + Rectifier

3. Transformer + Rectifier + Smoothing

4. Transformer + Rectifier + Smoothing + Regulator

The low voltage AC output is suitable for lamps, heaters and special AC motors. It
is not suitable for electronic circuits unless they include a rectifier and a smoothing

The regulated DC output is very smooth with no ripple. It is suitable for all
electronic circuits.

2.3.3 Transformer Working

Transformers convert AC electricity from one voltage to another with little

loss of power. Transformers work only with AC and this is one of the reasons why
mains electricity is AC.

Step-up transformers increase voltage, step-down transformers reduce voltage.

Most power supplies use a step-down transformer to reduce the dangerously high
mains voltage (230V in UK) to a safer low voltage.


"http://www.kpsec.freeuk.com/symbols/transfor.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/symbols/transfor.gif" \*
"http://www.kpsec.freeuk.com/symbols/transfor.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/symbols/transfor.gif" \*
"http://www.kpsec.freeuk.com/symbols/transfor.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/symbols/transfor.gif" \*
"http://www.kpsec.freeuk.com/symbols/transfor.gif" \* MERGEFORMATINET

Fig. 2.8 Transformer symbol

The input coil is called the primary and the output coil is called the secondary.
There is no electrical connection between the two coils, instead they are linked by an
alternating magnetic field created in the soft-iron core of the transformer. The two
lines in the middle of the circuit symbol represent the core.

Transformers waste very little power so the power out is (almost) equal to the
power in. Note that as voltage is stepped down current is stepped up.

The ratio of the number of turns on each coil, called the turns ratio,
determines the ratio of the voltages. A step-down transformer has a large number of
turns on its primary (input) coil which is connected to the high voltage mains supply,
and a small number of turns on its secondary (output) coil to give a low output

2.3.4 Rectifier

There are several ways of connecting diodes to make a rectifier to convert AC

to DC. The bridge rectifier is the most important and it produces full-wave varying
DC. A full-wave rectifier can also be made from just two diodes if a center-tap
transformer is used, but this method is rarely used now that diodes are cheaper. A
single diode can be used as a rectifier but it only uses the positive (+) parts of the AC
wave to produce half-wave varying DC

2.3.5 Bridge Rectifier

A bridge rectifier can be made using four individual diodes, but it is also
available in special packages containing the four diodes required. It is called a full-
wave rectifier because it uses all the AC wave (both positive and negative sections).
1.4V is used up in the bridge rectifier because each diode uses 0.7V when conducting
and there are always two diodes conducting, as shown in the diagram below. Bridge
rectifiers are rated by the maximum current they can pass and the maximum reverse
voltage they can withstand (this must be at least three times the supply RMS voltage
so the rectifier can withstand the peak voltages).

Fig. 2.9 Bridge Rectifier

2.3.6 Smoothing

Smoothing is performed by a large value electrolytic capacitor connected

across the DC supply to act as a reservoir, supplying current to the output when the
varying DC voltage from the rectifier is falling. The diagram shows the unsmoothed
varying DC (dotted line) and the smoothed DC (solid line). The capacitor charges
quickly near the peak of the varying DC, and then discharges as it supplies current to
the output.

"http://www.kpsec.freeuk.com/images/smoothng.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/smoothng.gif" \*
"http://www.kpsec.freeuk.com/images/smoothng.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/smoothng.gif" \*
"http://www.kpsec.freeuk.com/images/smoothng.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/smoothng.gif" \*

"http://www.kpsec.freeuk.com/images/smoothng.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/smoothng.gif" \*
"http://www.kpsec.freeuk.com/images/smoothng.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/smoothng.gif" \*
"http://www.kpsec.freeuk.com/images/smoothng.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/smoothng.gif" \*

Fig. 2.10 Smoothing

Note that smoothing significantly increases the average DC voltage to almost

the peak value (1.4 RMS value). For example 6V RMS AC is rectified to full wave
DC of about 4.6V RMS (1.4V is lost in the bridge rectifier), with smoothing this
increases to almost the peak value giving 1.4 4.6 = 6.4V smooth DC.

Smoothing is not perfect due to the capacitor voltage falling a little as it

discharges, giving a small ripple voltage. For many circuits a ripple which is 10% of
the supply voltage is satisfactory and the equation below gives the required value for
the smoothing capacitor. A larger capacitor will give less ripple. The capacitor value
must be doubled when smoothing half-wave DC.

Smoothing capacitor for 10% ripple, C = 5 Io

Vs f

C =smoothing capacitance in farads (F)

Io = output current from the supply in amps (A)
Vs = supply voltage in volts (V), this is the peak value of the unsmoothed DC
f = frequency of the AC supply in hertz (Hz), 50Hz in the UK

2.3.7 Regulator

Voltage regulator ICs are available with fixed (typically 5, 12 and 15V) or
variable output voltages. They are also rated by the maximum current they can pass.
Negative voltage regulators are available, mainly for use in dual supplies. Most
regulators include some automatic protection from excessive current ('overload
protection') and overheating ('thermal protection').

Many of the fixed voltage regulator ICs have 3 leads and look like power
transistors, such as the 7805 +5V 1A regulator shown on the right. They include a
hole for attaching a heat sink if necessary.

INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/voltreg.gif" \*
"http://www.kpsec.freeuk.com/images/voltreg.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/voltreg.gif" \*
"http://www.kpsec.freeuk.com/images/voltreg.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/voltreg.gif" \*
"http://www.kpsec.freeuk.com/images/voltreg.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/voltreg.gif" \*
"http://www.kpsec.freeuk.com/images/voltreg.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/voltreg.gif" \*
"http://www.kpsec.freeuk.com/images/voltreg.gif" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/images/voltreg.gif" \*

"http://www.kpsec.freeuk.com/images/voltreg.gif" \* MERGEFORMATINET

INCLUDEPICTURE "http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*
"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*
"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*
"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*
"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*
"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*
"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \* MERGEFORMATINET
INCLUDEPICTURE "http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \*

"http://www.kpsec.freeuk.com/photos/rapid/voltreg.jpg" \* MERGEFORMATINET

Fig. 2.11 Regulator

2.4 MAX 232

A standard serial interface for PC, RS232C, requires negative logic, i.e., logic
1 is -3V to -12V and logic 0 is +3V to +12V. To convert TTL logic, say, TxD and RxD
pins of the microcontroller thus need a converter chip. A MAX232 chip has long been
using in many microcontrollers boards. It is a dual RS232 receiver / transmitter that
meets all RS232 specifications while using only +5V power supply. It has two
onboard charge pump voltage converters which generate +10V to -10V power
supplies from a single 5V supply. It has four level translators, two of which are RS232
transmitters that convert TTL/CMOS input levels into +9V RS232 outputs. The other
two level translators are RS232 receivers that convert RS232 input to 5V. Typical
MAX232 circuit is shown below.

Fig. 2.12 Pin diagram of MAX 232

Fig. 2.13 MAX 232

Operates With Single 5-V Power Supply
1. Lin BiCMOS Process Technology
2. Two Drivers and Two Receivers
3. 30-V Input Levels
4. Low Supply Current. 8 MA, typically
5. Meets or Exceeds TIA/EIA-232-F and ITU Recommendation V.28
6. Designed to be Interchangeable With Maximum MAX232
7. Applications
a. TIA/EIA-232-F
b. Battery-Powered Systems
c. Terminals
d. Modems
e. Computers
8. ESD Protection Exceeds 2000 V Per
9. MIL-STD-883, Method 3015
10. Package Options Include Plastic
11. Small-Outline (D, DW) Packages and
12. Standard Plastic (N) DIPs

2.5 ADC

The ADC0808 data acquisition component is a monolithic CMOS device with
an 8-bit analog-to-digital converter, 8-channel multiplexer and microprocessor
compatible control logic. The 8-bit A/D converter uses successive approximation as
the conversion technique. The converter features a high impedance chopper stabilized
comparator, a 256R voltage divider with analog switch tree and a successive
approximation register. The 8-channel multiplexer can directly access any of 8-single-
ended analog signals. The device eliminates the need for external zero and full-scale
adjustments. Easy interfacing to microprocessors is provided by the latched and
decoded multiplexer address inputs and latched TTL tri-state outputs. The design of
the ADC0808 has been optimized by incorporating the most desirable aspects of
several A/D conversion techniques. The ADC0808 offers high speed, high accuracy,
minimal temperature dependence, excellent long-term accuracy and repeatability, and
consumes minimal power. These features make this device ideally suited to
applications from process and machine control to consumer and automotive


1. Easy interface to all microprocessors.

2. Operates ratio metrically or with 5 VDC or analog span.
3. Adjusted voltage reference.
4. No zero or full-scale adjust required.
5. 8-channel multiplexer with address logic.
6. 0V to 5V input range with single 5V power supply.
7. Outputs meet TTL voltage level specifications.
8. Standard hermetic or molded 28-pin DIP package.
9. 28-pin molded chip carrier package.
10. ADC0808 equivalent to MM74C949.

Key Specifications:

1. Resolution 8 Bits.
2. Total Unadjusted Error 1/2 LSB and 1 LSB.
3. Single Supply 5 VDC.
4. Low Power 15 mW.
5. Conversion Time 100 s.

Pin diagram

Fig. 2.14 Pin diagram of ADC

Fig. 2.15 Molded chip carrier package

Types of ADC

1. Digital-Ramp ADC.
2. Successive Approximation ADC.

3. Flash ADC.


AD converters are used virtually everywhere where an analog signal has to be

processed, stored, or transported in digital form. Fast video ADCs are used, for

example, in TV tuner cards. Slow on-chip 8, 10, 12, or 16 bit ADCs are common in
microcontrollers. Very fast ADCs are needed in digital oscilloscopes, and are crucial
for new applications like software defined radio and in music recording. ADC's
dynamic range is also important.

2.6 LCD (Liquid Cristal Display)

A liquid crystal display (LCD) is a thin, flat display device made up of any
number of color or monochrome pixels arrayed in front of a light source or reflector.
Each pixel consists of a column of liquid crystal molecules suspended between two
transparent electrodes, and two polarizing filters, the axes of polarity of which are
perpendicular to each other. Without the liquid crystals between them, light passing
through one would be blocked by the other. The liquid crystal twists the polarization
of light entering one filter to allow it to pass through the other. A program must
interact with the outside world using input and output devices that communicate
directly with a human being. One of the most common devices attached to an
controller is an LCD display. Some of the most common LCDs connected to the
controllers are 16X1, 16x2 and 20x2 displays. This means 16 characters per line by 1
line 16 characters per line by 2 lines and 20 characters per line by 2 lines,
respectively. Many microcontroller devices use 'smart LCD' displays to output visual

LCD displays designed around LCD NT-C1611 module, are inexpensive, easy
to use, and it is even possible to produce a readout using the 5X7 dots plus cursor of
the display. They have a standard ASCII set of characters and mathematical symbols.
For an 8-bit data bus, the display requires a +5V supply plus 10 I/O lines (RS RW D7
D6 D5 D4 D3 D2 D1 D0). For a 4-bit data bus it only requires the supply lines plus
6 extra lines (RS RW D7 D6 D5 D4).


1. Interface with either 4-bit or 8-bit microprocessor.

2. Display data RAM
3. 80x8 bits (80 characters).
4. Character generator ROM
5. 160 different 5 7 dot-matrix character patterns.

6. Character generator RAM
7. 8 different user programmed 5 7 dot-matrix patterns.
8. Display data RAM and character generator RAM may be
9. Accessed by the microprocessor.
10. Numerous instructions
11. Clear Display, Cursor Home, Display ON/OFF, Cursor ON/OFF,
12. Blink Character, Cursor Shift, Display Shift.
13. Built-in reset circuit is triggered at power ON.
14. Built-in oscillator.

Data can be placed at any location on the LCD. For 161 LCD, the address
locations are:

Table 2.6 Address locations for a 1x16 line LCD

Shapes and Sizes

Fig. 2.16 Sizes and shapes of LCD

Even limited to character based modules,there is still a wide variety of shapes

and sizes available. Line lenghs of 8,16,20,24,32 and 40 charecters are all standard, in
one, two and four line versions.

Several different LC technologies exists. super twist types, for example,

offer Improved contrast and viewing angle over the older twisted nematic types.
Some modules are available with back lighting, so so that they can be viewed in
dimly-lit conditions. The back lighting may be either electro-luminescent, requiring
a high voltage inverter circuit, or simple LED illumination.

Power Supply for LCD Driving

Fig. 2.17 Power supply for LCD

Pin Description

Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16
Pins (two pins are extra in both for back-light LED connections).

Fig. 2.18 pin diagram of 1x16 lines lcd

Table 2.7 Functions of LCD

Control Lines

EN: Line is called "Enable." This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should make sure this line is
low (0) and then set the other two control lines and/or put data on the data bus. When
the other lines are completely ready, bring EN high (1) and wait for the minimum

amount of time required by the LCD datasheet (this varies from LCD to LCD), and
end by bringing it low (0) again.

RS: Line is the "Register Select" line. When RS is low (0), the data is to be treated
as a command or special instruction (such as clear screen, position cursor, etc.). When
RS is high (1), the data being sent is text data which should be displayed on the
screen. For example, to display the letter "T" on the screen you would set RS high.

RW: Line is the "Read/Write" control line. When RW is low (0), the information on
the data bus is being written to the LCD. When RW is high (1), the program is
effectively querying (or reading) the LCD. Only one instruction ("Get LCD status") is
a read command. All others are write commands, so RW will almost always be low.

Finally, the data bus consists of 4 or 8 lines (depending on the mode of

operation selected by the user). In the case of an 8-bit data bus, the lines are referred
to as DB0, DB1, DB2, DB3, DB4, DB5, DB6, and DB7.

Logic Status on Control Lines

1. E - 0 Access to LCD disabled.

2. 1 Access to LCD enabled.

3. R/W - 0 Writing data to LCD.

4. 1 Reading data from LCD.
5. RS - 0 Instructions.
6. 1 Character.

Writing Data to the LCD

1. Set R/W bit to low.

2. Set RS bit to logic 0 or 1 (instruction or character).
3. Set data to data lines (if it is writing).
4. Set E line to high.
5. Set E line to low.

Read Data from Data Lines (If It Is Reading) On LCD

1. Set R/W bit to high.
2. Set RS bit to logic 0 or 1 (instruction or character).
3. Set data to data lines (if it is writing).
4. Set E line to high.

5. Set E line to low.

Entering Text
First, a little tip: it is manually a lot easier to enter characters and commands in
hexadecimal rather than binary (although, of course, you will need to translate
commands from binary couple of sub-miniature hexadecimal rotary switches is a
simple matter, although a little bit into hex so that you know which bits you are
setting). Replacing the d.i.l. switch pack with a of re-wiring is necessary.

The switches must be the type where On = 0, so that when they are turned to
the zero position, all four outputs are shorted to the common pin, and in position F,
all four outputs are open circuit.

All the available characters that are built into the module are shown in Table 3.
Studying the table, you will see that codes associated with the characters are quoted in
binary and hexadecimal, most significant bits (left-hand four bits) across the top, and
least significant bits (right-hand four bits) down the left.

Most of the characters conform to the ASCII standard, although the Japanese
and Greek characters (and a few other things) are obvious exceptions. Since these
intelligent modules were designed in the Land of the Rising Sun, it seems only fair
that their Katakana phonetic symbols should also be incorporated. The more extensive
Kanji character set, which the Japanese share with the Chinese, consisting of several
thousand different characters, is not include!

Using the switches, of whatever type, and referring to Table 3, enter a few
characters onto the display, both letters and numbers. The RS switch (S10) must be
up (logic 1) when sending the characters, and switch E (S9) must be pressed for each
of them.
Thus the operational order is: set RS high, enter character, trigger E, leave RS
high, enter another character, trigger E, and so on.

The first 16 codes in Table 3, 00000000 to 00001111, ($00 to $0F) refer to the
CGRAM. This is the Character Generator RAM (random access memory), which can
be used to hold user-defined graphics characters. This is where these modules really
start to show their potential, offering such capabilities as bar graphs, flashing symbols,

even animated characters. Before the user-defined characters are set up, these codes
will just bring up strange looking symbols.

Codes 00010000 to 00011111 ($10 to $1F) are not used and just display blank
characters. ASCII codes proper start at 00100000 ($20) and end with 01111111
($7F). Codes 10000000 to 10011111 ($80 to $9F) are not used, and 10100000 to
11011111 ($A0 to $DF) are the Japanese characters.

Fig. 2.19 Entering text of LCD

Initialization by Instructions

Fig. 2.20 Flow chart

If the power conditions for the normal operation of the internal reset circuit
are not satisfied, then executing a series of instructions must initialize LCD unit. The
procedure for this initialization process is as above shown.




A sensor (also called detectors) is a device that measures a measurable

attribute and converts it into a signal which can be read by an observer or by an
instrument. For example, a mercury-in-glass thermometer converts the measured
temperature into expansion and contraction of a liquid which can be read on
calibrated glass tube. A thermocouple converts temperature to an output voltage
which can be read by a voltmeter.

3.1.1 Temperature Sensor (Lm35)


The LM35 series are precision integrated-circuit temperature sensors, whose

output voltage is linearly proportional to the Celsius (Centigrade) temperature. The
LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as
the user is not required to subtract a large constant voltage from its output to obtain
convenient centigrade scaling. The LM35 does not require any external calibration or
trimming to provide typical accuracies of 1/4C at room temperature and 3/4C
over a full -55 to +150C temperature range. Low cost is assured by trimming and
calibration at the wafer level. The LM35s low output impedance, linear output, and
precise inherent calibration make interfacing to readout or control circuitry especially
easy. It can be used with single power supplies, or with plus and minus supplies. As it
draws only 60 A from its supply, it has very low self-heating, less than 0.1C in still
air. The LM35 is rated to operate over a -55 to +150C temperature range, while the
LM35C is rated for a -40 to +110C range (-10 with improved accuracy). The
LM35 series is available packaged plastic TO-92 transistor package. The LM35D is
also available in an 8-lead surface mount small outline package and a plastic TO-220


1. Calibrated directly in Celsius (Centigrade).

2. Linear + 10.0 mV/C scale factor.
3. 0.5C accuracy guarantee able (at +25C).
4. Rated for full -55 to +150C range.
5. Suitable for remote applications.
6. Low cost due to wafer-level trimming.
7. Operates from 4 to 30 volts.
8. Less than 60 A current drain.
9. Low self-heating, 0.08C in still air.
10. Nonlinearity only 1/4C typical.
11. Low impedance output, 0.1 for 1 mA load.

Pin diagram:

Fig. 3.1Pin
diagram of


The LM35 can be applied easily in the same way as other integrated-circuit
temperature sensors. It can be glued or cemented to a surface and its temperature will
be within about 0.01C of the surface temperature. This presumes that the ambient air
temperature is almost the same as the surface temperature; if the air temperature were
much higher or lower than the surface temperature, the actual temperature of the
LM35 die would be at an intermediate temperature between the surface temperature
and the air temperature.

This is especially true for the TO-92 plastic package, where the copper leads
are the principal thermal path to carry heat into the device, so its temperature might be
closer to the air temperature than to the surface temperature. To minimize this

problem, be sure that the wiring to the LM35, as it leaves the device, is held at the
same temperature as the surface of interest. The easiest way to do this is to cover up
these wires with a bead of epoxy which will insure that the leads and wires are all at
the same temperature as the surface, and that the LM35 dies temperature will not be
affected by the air temperature. The TO-46 metal package can also be soldered to a
metal surface or pipe without damage. Of course, in that case the V- terminal of the
circuit will be grounded to that metal. Alternatively, the LM35 can be mounted inside
a sealed-end metal tube, and can then be dipped into a bath or screwed into a threaded
hole in a tank. As with any IC, the LM35 and accompanying wiring and circuits must
be kept insulated and dry, to avoid leakage and corrosion. This is especially true if the
circuit may operate at cold temperatures where condensation can occur. Printed-
circuit coatings and varnishes such as Humiseal and epoxy paints or dips are often
used to insure that moisture cannot corrode the LM35 or its connections. These
devices are sometimes soldered to a small light-weight heat fin, to decrease the
thermal time constant and speed up the response in slowly-moving air. On the other
hand, a small thermal mass may be added to the sensor, to give the steadiest reading
despite small deviations in the air temperature.

3.1.2 Humidity Sensor

Humidity sensors are gaining more significance in diverse areas of

measurement and Control technology. Manufacturers are not only improving the
accuracy and long-term drift of their sensors, they are improving their durability for
use in different environments, and simultaneously reducing the component size and
the price.

Following this trend, Swiss-based Sensation AG has introduced a new

generation of integrated, digital, and calibrated humidity and temperature sensors
using CMOS "micro-machined" chip technology.

Conventional sensors determine relative air humidity using capacitive

measurement technology. For this principle, the sensor element is built out of a film
capacitor on different substrates (glass, ceramic, etc.).

The dielectric is a polymer which absorbs or releases water proportional to the
relative environmental humidity, and thus changes the capacitance of the capacitor,
which is measured by an onboard electronic circuit.

3.1.3 Gas Sensor

In current technology scenario, monitoring of gases produced is very

important. From home appliances such as air conditioners to electric chimneys and
safety systems at industries monitoring of gases is very crucial.
Gas sensors are available in wide specifications depending on the sensitivity
levels, type of gas to be sensed, physical dimensions and numerous other factors. This
Insight covers a methane gas sensor that can sense gases such as ammonia which
might get produced from methane. When a gas interacts with this sensor, it is first
ionized into its constituents and is then adsorbed by the sensing element. This
adsorption creates a potential difference on the element which is conveyed to the
processor unit through output pins in form of current.

Fig. 3.2 Gas sensor

The gas sensor module consists of a steel exoskeleton under which a sensing
element is housed. This sensing element is subjected to current through connecting
leads. This current is known as heating current through it, the gases coming close to
the sensing element get ionized and are absorbed by the sensing element. This
changes the resistance of the sensing element which alters the value of the current
going out of it.



In earlier days, our telephone systems were operated by manually in a

telephone exchange room. The callers will pick up the phone and giving instruction to
the operator to connect their destination line. The DTMF technology provides
ultimate solutions for the telephone industries which is used to switch two lines
automatically. The DTMF stands for Dual Tone Multi-frequency which is one of the
techniques for converting the analogue signal to digital using DTMF decoder. The
DTMF decoder circuit mostly used in mobile communications system which
recognizes the sequence of DTMF tones from the standard keypad of the mobile

DTMF Decoder Application Circuit and Working Procedure

DTMF keypad is placed out on a 4 cross 4 matrices, in which each row represents low
frequency, each column represents high frequency, with DTMF, each key passed on a
phone generates two tones of the specific frequencies one tone is generated from a
high frequency tones and low frequency tone. These tones are converted to digital
form using DTMF decoder circuit. These codes are the address of the destination

which is read and preceded by the computer that connects the caller to the destination.
The DTMF decoder circuit used in many electronics projects for better connectivity to
control the applications.

DTMF Decoder based Home Automation System and its Working Procedure

In previous days, the home applications are controlled by manually using switches.
Now a day, many technologies are available to control home appliances. This project
mainly discusses DTMF decoder circuit to control the home applications. The
working procedure of this project is just like dialing a customer care number using
DTMF technology by following automatic voice recorded instructions. It will ask to
press 1,2 or any other number when you press number to your mobile one particular
procedure is happening. This is called a DTMF technology. If any button is pressed on
the mobile phone keypad, then it will generate two frequencies. These tones are called
row are column frequencies. Normally row frequencies are low frequencies and
column frequencies are high frequencies. These column frequencies are slightly
louder than the row frequencies to compensate for the high-frequency roll off of voice
audio systems

The main objective of this project is to control the home applications like light,
electric fan or some electronic gadgets by using DTMF techniques. DTMF encoder is

present in mobile and the DTMF decoder circuit is present in the microcontroller. The
mobile is connected at one end of the circuit with the help of the mobile phone jack.
The mobile jack is consisting of two wires. The red wire is connected to the decoder
IC and Black is grounded. When a button is pressed from mobile it generates a tone
which is decoded by the decoder IC and its sent to the micro controller. The
controller checks the inputs and delivers the respective outputs according to the code
written on it.

The decoder IC is an electronics circuit which is consisting of an inbuilt op-amp and

to separate low and high frequencies, the output of an operational amplifier is given to
the pre-filters. And it passed though the code detector and frequency circuits. The tone
which is generated from the mobile is sent through a capacitor and the resistor of the

Pin Architecture and Circuit Explanation of DTMF

Relay Basics:

A relay is an electrical switch that uses an electromagnet to move the switch

from the off to on position instead of a person moving the switch. It takes a relatively
small amount of power to turn on a relay but the relay can control something that
draws much more power. Ex: A relay is used to control the air conditioner in your
home. The AC unit probably runs off of 220VAC at around 30A. That's 6600 Watts!
The coil that controls the relay may only need a few watts to pull the contacts

A relay is an electrical switch that uses an electromagnet to move the switch from the
off to on position instead of a person moving the switch. It takes a relatively small
amount of power to turn on a relay but the relay can control something that draws
much more power. Ex: A relay is used to control the air conditioner in your home. The
AC unit probably runs off of 220VAC at around 30A. That's 6600 Watts! The coil that
controls the relay may only need a few watts to pull the contacts together.

Relay Selection:
Relays (and switches) come in different configurations. T most common are shown to
the right. Single Pole Singl Throw (SPST) is the simplest with only two contacts.
Single Pole Double Throw (SPDT) has three contacts. The contacts are usually
labeled Common (COM), Normally Open (NO), and Normally Closed (NC). The
Normally Closed contact will be connected to the Common contact when no power is
applied to the coil. The Normally Open contact will be open (i.e. not connected) when
no power is applied to the coil. When the coil is energized the Common is connected
to the Normally Open contact and the Normally Closed contact is left floating. The

Double Pole versions are the same as the Single Pole version except there are two
switches that open and close together.
ractical Considerations:
Check the relay datasheet for the expected lifetime (i.e. # of times it can open and
close before failure).
If the relay won't be used much (say to control the headlights on a car) a 20,000 cycle
lifetime would last about 18 years if used three times a day. If the same relay was used
to control a home AC unit which switches on and off much more often it would wear
out in a few years. Some relays have lifetimes of over a million cycles. SPST SPDT

Flyback Diode:

A relay coil is not only an electromagnet but it's also an inductor. When power is
applied to the coil the current in the coil builds up and levels off at its rated current
(depends on the DC resistance of the coil, I = V/R). Some energy is now stored in the
coil's magnetic field (E = 05LI2). When the current in the coil is turned off this stored
energy has to go somewhere. The voltage across the coil quickly increase trying to
keep the current in the coil flowing in the same direction (V = Ldi/dt). This voltage
spike can reach hundreds or thousands of volts and can damage electronic parts.
By adding a flyback diode the current has a path to continue flowing through coil
until the stored energy is used up. The diode also clamps the voltage across the coil to
about 0.7V protecting the electronics. The stored energy dissipates quickly in the
diode (E = V*I*t). The current stops flowing and the relay turns off. The diode should
be able to handle the coil current for a short time and switch relatively fast. Note: A
resistor or zener diode can be placed in series with the diode to use up the stored
energy quicker. This increases the amplitude of the voltage spike above 0.7V but the
energy is used up quicker (i.e. the voltage spike won't last as long). Usually it doesn't
matter if the relay takes 1ms or 100ms to turn off.
The schematic on the left illustrates how current flows in a relay. Fig A shows the
current flow when the transistor is on. Fig B shows the current flow when the
transistor is off. Notice how the diode completes the current loop.

Note: An automotive ignition coil uses the stored energy in an inductor combined
with a step up transformer to power the spark plugs in your car. By quickly collapsing
the magnetic filed over 20,000V can be generated.

Note: If the load is DC and inductive add a flyback diode across the relay contacts (as
shown to the right). The inductive kickback from the load will shorten the
lifetime of the relay contacts if the diode isn't present.


BC547 is an NPN bi-polar junction transistor. A transistor, stands for transfer of

resistance, is commonly used to amplify current. A small current at its base controls a
larger current at collector & emitter terminals.

BC547 is mainly used for amplification and switching purposes. It has a maximum
current gain of 800. Its equivalent transistors are BC548 and BC549.

The transistor terminals require a fixed DC voltage to operate in the desired region of
its characteristic curves. This is known as the biasing. For amplification applications,
the transistor is biased such that it is partly on for all input conditions. The input
signal at base is amplified and taken at the emitter. BC547 is used in common emitter
configuration for amplifiers. The voltage divider is the commonly used biasing mode.
For switching applications, transistor is biased so that it remains fully on if there is a
signal at its base. In the absence of base signal, it gets completely off.

Pin Diagram:


sbit buzzer=P0^0;
unsigned char ch0,ch1,ch2,i1,i2,i3,i4;
void main()
msgdisplay("XBEE BSD HELMENT");
msgdisplay("FOR COAL MINERS");


msgdisplay("HIGH TEMP");
msgdisplay("BUZZER ON");
msgdisplay("SMOKE DETECTED");
msgdisplay("BUZZER ON");

msgdisplay("GAS DETECTED");
msgdisplay("BUZZER ON");
tx("\r\nGAS DETECTED");




Introduction to Keil Micro Vision (IDE)

Keil an ARM Company makes C compilers, macro assemblers, real-time

kernels, debuggers, simulators, integrated environments, evaluation boards, and
emulators for ARM7/ARM9/Cortex-M3, XC16x/C16x/ST10, 251, and 8051 MCU

Keil development tools for the 8051 Microcontroller Architecture support

every level of software developer from the professional applications engineer to the
student just learning about embedded software development. When starting a new
project, simply select the microcontroller you use from the Device Database and the
Vision IDE sets all compiler, assembler, linker, and memory options for you.

Keil is a cross compiler. So first we have to understand the concept of

compilers and cross compilers. After then we shall learn how to work with keil.

Concept of Compiler
Compilers are programs used to convert a High Level Language to object
code. Desktop compilers produce an output object code for the underlying
microprocessor, but not for other microprocessors. I.E the programs written in one of
the HLL like C will compile the code to run on the system for a particular processor
like x86 (underlying microprocessor in the computer). For example compilers for Dos
platform is different from the Compilers for Unix platform So if one wants to define
a compiler then compiler is a program that translates source code into object code.
The compiler derives its name from the way it works, looking at the entire
piece of source code and collecting and reorganizing the instruction. See there is a bit
little difference between compiler and an interpreter.

Interpreter just interprets whole program at a time while compiler analyses and
execute each line of source code in succession, without looking at the entire
The advantage of interpreters is that they can execute a program immediately.
Secondly programs produced by compilers run much faster than the same programs
executed by an interpreter. However compilers require some time before an
executable program emerges. Now as compilers translate source code into object
code, which is unique for each type of computer, many compilers are available for the
same language.
Concept of Cross Compiler
A cross compiler is similar to the compilers but we write a program for the
target processor (like 8051 and its derivatives) on the host processors (like computer
of x86). It means being in one environment you are writing a code for another
environment is called cross development. And the compiler used for cross
development is called cross compiler. So the definition of cross compiler is a compiler
that runs on one computer but produces object code for a different type of computer.
Keil C Cross Compiler
Keil is a German based Software development company. It provides several
development tools like
1. IDE (Integrated Development environment).
2. Project Manager.
3. Simulator.
4. Debugger.
5. C Cross Compiler, Cross Assembler, Locator/Linker.
The Keil ARM tool kit includes three main tools, assembler, compiler and
linker. An assembler is used to assemble the ARM assembly program. A compiler is
used to compile the C source code into an object file. A linker is used to create an
absolute object module suitable for our in-circuit emulator.
Building an Application in Vision2:
To build (compile, assemble, and link) an application in Vision2, you must:
1. Select Project - (for example, 166\EXAMPLES\HELLO\HELLO.UV2).
2. Select Project - Rebuild all target files or Build target.Vision2 compiles,
assembles, and links the files in your project.

Creating Your Own Application in Vision2:
To create a new project in Vision2, you must:
1. Select Project - New Project.
2. Select a directory and enter the name of the project file.
3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device
from the Device Database.
4. Create source files to add to the project.
5. Select Project - Targets, Groups, Files, Add/Files, select Source Group1, and
add the source files to the project.
6. Select Project - Options and set the tool options. Note when you select the
target device from the Device Database all special options are set
automatically. You typically only need to configure the memory map of your
target hardware. Default memory model settings are optimal for most
7. Select Project - Rebuild all target files or Build target.

Debugging an Application in Vision2:

To debug an application created using Vision2, you must:
1. Select Debug - Start/Stop Debug Session.
2. Use the Step toolbar buttons to single-step through your program. You may
enter G, main in the Output Window to execute to the main C function.
3. Open the Serial Window using the Serial #1 button on the toolbar.
4. Debug your program using standard options like Step, Go, Break, and so on.

Starting Vision2 and Creating a Project:

Vision2 is a standard Windows application and started by clicking on the
program icon. To create a new project file select from the Vision2 menu Project
New Project. This opens a standard Windows dialog that asks you for the new
project file name. We suggest that you use a separate folder for each project. You can
simply use the icon Create New Folder in this dialog to get a new empty folder. Then
select this folder and enter the file name for the new project, i.e. Project1. Vision2
creates a new project file with the name PROJECT1.UV2 which contains a default
target and file group name. You can see these names in the Project.
Window Files:
Now use from the menu Project Select Device for Target and select a CPU
for your project. The Select Device dialog box shows the Vision2 device data base.

Just select the microcontroller you use. We are using for our examples the Philips
80C51RD+ CPU. This selection sets necessary tool Options for the 80C51RD+ device
and simplifies in this way the tool Configuration.

Building Projects and Creating a HEX Files:

Typical, the tool settings under Options Target are all you need to start a new
application. You may translate all source files and line the application with a click on
the Build Target toolbar icon. When you build an application with syntax errors,
Vision2 will display errors and warning messages in the Output Window Build
page. A double click on a message line opens the source file on the correct location in
a Vision2 editor window. Once you have successfully generated your application
you can start debugging.
After you have tested your application, it is required to create an Intel HEX
file to download the software into an EPROM programmer or simulator. Vision2
creates HEX files with each build process when Create HEX files under Options for
Target Output is enabled. You may start your PROM programming utility after the
make process when you specify the program under the option Run User Program #1.

CPU Simulation:
Vision2 simulates up to 16 Mbytes of memory from which areas can be
mapped for read, write, or code execution access. The Vision2 simulator traps and
reports illegal memory accesses. In addition to memory mapping, the simulator also
provides support for the integrated peripherals of the various 8051 derivatives. The
on-chip peripherals of the CPU you have selected are configured from the Device.

Database Selection:
You have made when you create your project target. Refer to page 58 for more
Information about selecting a device. You may select and display the on-chip
peripheral components using the Debug menu. You can also change the aspects of
each peripheral using the controls in the dialog boxes.

Start Debugging:
You start the debug mode of Vision2 with the Debug Start/Stop Debug

Session Command. Depending on the Options for Target Debug Configuration,
Vision2 will load the application program and run the startup code Vision2 saves
the editor screen layout and restores the screen layout of the last debug session. If the
program execution stops, Vision2 opens an editor window with the source text or
shows CPU instructions in the disassembly window. The next executable statement is
marked with a yellow arrow. During debugging, most editor features are still
For example, you can use the find command or correct program errors.
Program source text of your application is shown in the same windows. The Vision2
debug mode differs from the edit mode in the following aspects:
The Debug Menu and Debug Commands described on page 28 are available. The
additional debug windows are discussed in the following.
The project structure or tool parameters cannot be modified. All build commands are

Disassembly Window:
The Disassembly window shows your target program as mixed source and
assembly program or just assembly code. A trace history of previously executed
instructions may be displayed with Debug View Trace Records. To enable the trace
history, set Debug Enable/Disable Trace Recording.
If you select the Disassembly Window as the active window all program step
commands work on CPU instruction level rather than program source lines. You can
select a text line and set or modify code breakpoints using toolbar buttons or the
context menu commands.
You may use the dialog Debug Inline Assembly to modify the CPU
instructions. That allows you to correct mistakes or to make temporary changes to the
target program you are debugging. Numerous example programs are included to help
you get started with the most popular embedded 8051 devices.
The Keil Vision Debugger accurately simulates on-chip peripherals (IC,
CAN, UART, SPI, Interrupts, I/O Ports, A/D Converter, D/A Converter, and PWM
Modules) of your 8051 device.
Simulation helps you understand hardware configurations and avoids time
wasted on setup problems. Additionally, with simulation, you can write and test
applications before target hardware is available.

Embedded C:
Use of embedded processors in passenger cars, mobile phones, medical
equipment, aerospace systems and defense systems is widespread, and even everyday
domestic appliances such as dish washers, televisions, washing machines and video
recorders now include at least one such device.
Because most embedded projects have severe cost constraints, they tend to
use low-cost processors like the 8051 family of devices considered in this book. As a
result, developing embedded software presents significant new challenges, even for
experienced desktop programmers. If you have some programming experience - in C,
C++ or Java - then this book and its accompanying CD will help make your move to
the embedded world as quick and painless as possible.



This project helps us to control all the electrical appliances using mobile
phones. This reduces the effort of switching off and on the devices. This could be
operated from a minimum range so that it is easy to monitor electrical devices which
in turn we can reduce power bills of the devices.


1. The 8051 micro controller and embedded systems by Mazidi.

2. www.wikipedia.org
3. www.atmel.com
4. www.8051projects.com
5. Embedded systems with 8051 by kenith jayala