Sunteți pe pagina 1din 76

ANTI-COLLISION SYSTEM FOR RAILWAYS

PROJECT

ACKNOLEDGEMENT

First we would like to thank the omniscient, omnipotent, omnipresent God


by virtue of whom we are able to complete this project.

We are grateful to Mrs. Anamika Bhatia, our head of department for her
valuable guidance, support and co-operation extend by her. Then we would
like to thank Colonel Rakesh Sharma sir and our project coordinator and co-
coordinator for their kind cooperation, help and never ending support. We
would also like to thank Mr. Sudakar chauhan sir without whom our project
would not have been successful in all means.

We are also thankful to Mr. Kamal Ghanshala (Chairman, GEU Dehradun)


for providing us labs and facilities which proved to be very useful for our
project.

In the end, we convey our sincere thanks to all those people who directly or
indirectly helped us.

Aman Pant
Amit Bharti
Kumar Govind

1
ABSTRACT

In the recent time, we have seen a lot of railway accidents and yet Indian
Railways have not implemented any effective Anti-Collision System which
can avoid such type of accidents.

So, we come up with a project “Anti-Collision System (Railways)” which


can avoid such type of railway accidents.

In this project, we have used Microcontroller, LCD panel, Wireless


TransReceiver Unit (Zigbee), MAX 232, different IC’s and power supply.

Microcontroller is the heart of our project, it acts as an interface among


LCD, Motor, Max 232,Potentiometer,LED’s and Transreceiver (Zigbee).

2
CONTENTS

TABLE OF CONTENTS

1. Introduction

1.1 Introduction of project……….……………………………..….….9

2. Block Diagram……………..…………………………..……………10
2.2.1 Transmitter…………..…………………………………..…..10
2.2.2 Reciever…………………………………………………….. 11

3. Simulation Diagram……………………………………………….13
4. PCB Layout…………………………………..……………..………14
5. Components Description
5.18051 Microcontroller..............................................................16
5.2PIN DIAGRAM……………………………………………...19
5.3Block Diagram……………………………………………….20
5.4PIN Description………………………………………………21
6 TRANSISTOR………………………………………………………….26
7 TRANSRECIEVER…………………………………………………….27
8 LED……………………………………………………………………..30
9 CAPACITOR…………………………………………………………...31
10 DIODE………………………………………………………………….34
11 RESISTOR……………………………………………………………...37
12 MOTOR...………………………………………………………………39
13 LCD……………………………………………………………………..40
14 MAX 232……………………………………………………………….41
15 IC 7805………………………………………………………………….42
16 WORKING……………………………………………………………..43
17 Bibilography and refrence………………………………………………44

3
INTRODUCTION

4
The idea of antiocollision system for railways clicked to our mind,because
we have seen a lot of railway accidents recently in the past,yet railways have
not implemented any such system in their railway network.altough konkan
railway have patented a anticollison system and that is expected to come in
picture in 2014 still that is specifically meant for deccan railways and
doesn’t cater the need of whole Indian railway network.

17 rail accidents was reported in 2010 in which 5 alone takes place in UP


due to dense fog condition,out of which in 19 July 2010 – Sainthia train
collision occurred in Sainthia, West Bengal, India, when the Uttar Banga
Express collided with the Vananchal Express. Casualties stand at 63 people
dead and more than 165 people injured, with many still trapped in wreckage
and 8 May 2010 – West Bengal, the Gyaneshwari Express train collision, a
suspected Naxalite terrorist attack kills at least 170 people, was the
disastrous one.

To prevent such rail accidents and to provide safety to the millions of


passengers who suffer daily from trains we come up with the idea of
anticollision system for railways, it not only warns driver before condition of
collision but also automatically stop the train to prevent such collision.

BLOCK DIAGRAM
L CD MOTOR

BATTERY ATMEL5 MAX 232


POTENTIOMETER
(8µC)
SWITCHES

TRANSCEIVER

TRANSMITTER

TRANSRECEIVER LCD
MOTOR

MAX 232
MAX 232

ATMEL (8 µc )
BATTERY

POTENTIOMETER SWITCHES

6
RECEIVER

COMPONENTS USED

S.No Name Of Component Value/Type Quantity


1. Microcontroller ATMEL 8 2
2. LCD Hitachi HD44780 2
3. Transistor 2N2222A 2
4. Crystal Oscillator 14.7456MHz 2
5. Driver/Receiver MAX-232 2
6. Transreceiver ZigBee 2
7. Voltage Regulator IC 7805 2
8. Potentiometer 100K 2
9. D.C Motor 6-12V 2
10. Electrolytic Capacitor 10µF,1000µF 8,2
11. Ceramic Capacitor 33µF 4
12. LED Red,Blue,Green 2,2,2
13. Diode 1N4007 2
14. Resistor .330K,1K 4,6
15. Switch Button,DPDT 4,2
16. Connector Programmable 1
17. Wires

7
SIMULATION DIAGRAM

PCB LAYOUT(TOP VIEW)

8
PCB LAYOUT(BOTTOM VIEW)

9






 COMPONENTS DESCRIPTION

10
2.1 Introduction

The term microcomputer is used to describe a system that includes at minimum a


microprocessor, program memory, data memory, and an input-output (I/O) device. Some
microcomputer systems include additional components such as timers, counters, and
analog-to-digital converters. Thus, a microcomputer system can be anything from a large
computer having hard disks, floppy disks, and printers to a single-chip embedded
controller.
We are going to consider only the type of microcomputers that consist of a single silicon
chip. Such microcomputer systems are also called microcontrollers, and they are used in
many household goods such as microwave ovens, TV remote control units, cookers, hi-fi
equipment, CD players, personal computers, and refrigerators. Many different
microcontrollers are available on the market. In this book we shall be looking at
programming and system design for the 8051 series of microcontrollers .

2.2 Microcontrollers versus Microprocessors

Microcontroller differs from a microprocessor in many ways. First and the most important is
its functionality. In order for a microprocessor to be used, other components such as memory,
or components for receiving and sending data must be added to it. In short that means that
microprocessor is the very heart of the computer. On the other hand, microcontroller is
designed to be all of that in one. No other external components are needed for its application
because all necessary peripherals are already built into it. Thus, we save the time and space
needed to construct devices.

11
Fig 3.7.1 microprocessor and its component block diagram .

Fig 3.7.2 Microcontroller unit

2.3 Microcontroller System:


In today present a lot of microcontroller manufactures appeared almost every major
electronic company produce their own microcontroller to use into their own devices
each microcontroller type may add or improve existing features but all microcontrollers
share basic features that is microprocessor (CPU), memory and an input-output (I/O)
device.

12
Fig 3.8.1 the basic microcontroller system

 The input components would consist of digital devices such as, switches, push buttons,
pressure mats, float switches, keypads, radio receivers etc. and analogue sensors such as
light dependent resistors, thermistors, gas sensors, pressure sensors, etc.

 The control unit is of course the microcontroller. The microcontroller will monitor the
inputs and as a result the program would turn outputs on and off. The microcontroller
stores the program in its memory, and executes the instructions under the control of the
clock circuit.

 The output devices would be made up from LEDs, buzzers, motors, alpha numeric
displays, radio transmitters, 7 segment displays, heaters, fans etc.

The most obvious choice then for the microcontroller is how many digital inputs, analogue
inputs and outputs does the system require. This would then specify the minimum number of
inputs and outputs (I/O) that the microcontroller must have. If analogue inputs are used then
the microcontroller must have an Analogue to Digital (A/D) module inside.
The next consideration would be what size of program memory storage is required. This
should not be too much of a problem when starting out, as most programs would be relatively
small.
The clock frequency determines the speed at which the instructions are executed. This is
important if any lengthy calculations are being undertaken. The higher the clock frequency
the quicker the micro will finish one task and start another.
Other considerations are the number of interrupts and timer circuits required how much data
EEPROM if any is needed.
Microcontrollers have traditionally been programmed using the assembly language of the
target device. Although the assembly language is fast, it has several disadvantages. An
assembly program makes learning and maintaining a program written using the assembly
language difficult. Also, microcontrollers manufactured by different firms have different

13
assembly languages, so the user must learn a new language with every new microcontroller
he uses.
Microcontrollers can also be programmed using a high-level language, such as BASIC,
PASCAL, or C. High-level languages are much easier to learn than assembly languages. They
also facilitate the development of large and complex programs.
A microcontroller is a very powerful tool that allows a designer to create sophisticated input-
output data manipulation under program control. Microcontrollers are classified by the
number of bits they process. 12
Microcontrollers with 8 bits are the most popular and are used in most microcontroller-based
applications. Microcontrollers with 16 and 32 bits are much more powerful, but are usually
more expensive and not required in most small- or medium-size general purpose applications
that call for microcontrollers.

2.4 Microcontroller basic architecture:


The simplest microcontroller architecture consists of a microprocessor, memory, and
input-output. The microprocessor consists of a central processing unit (CPU) and a
control unit (CU). The CPU is the brain of the microcontroller; this is where all the
arithmetic and logic operations are performed. The CU controls the internal
operations of the microprocessor and sends signals to other parts of the
microcontroller to carry out the required instructions.

2.4.1 Central Processing Unit

As its name indicates, this is a unit which monitors and controls all processes inside the
microcontroller. It consists of several smaller units, of which the most important are:
 Instruction Decoder: is a part of electronics which recognizes program instructions
and runs other circuits on the basis of that. The ―instruction set‖ which is different
for each microcontroller family expresses the abilities of this circuit.

 Arithmetical Logical Unit (ALU): performs all mathematical and logical operations
upon data.

14
 Accumulator: is a SFR closely related to the operation of ALU. It is a kind of
working desk used for storing all data upon which some operation should be
performed (addition, shift/move etc.). It also stores results ready for use in further
processing.

 Status Register (PSW): One of SFRs is close to the accumulator. It shows at any
moment the ―status of a number stored in the accumulator (number is greater or less
than zero etc.)..

Microcontroller central processing unit

2.4.2 Memory unit

Memory, an important part of a microcontroller system, can be classified into two types:
program memory and data memory. Program memory stores the program written by the
programmer and is usually nonvolatile (i.e., data is not lost after the power is turned off).
Data memory stores the temporary data used in a program and is usually volatile (i.e.,
data is lost after the power is turned off).

15
Typical memory unit device

There are basically six types of memories, summarized as follows:

2.4.2.1 RAM

RAM, random access memory, is a general purpose memory that usually stores the user data
in a program. RAM memory is volatile in the sense that it cannot retain data in the absence of
power (i.e., data is lost after the power is turned off). Most microcontrollers have some
amount of internal RAM, 256 bytes being a common amount, although some
microcontrollers have more, some less. The AT89C52 microcontroller, for example, has 256
bytes of RAM. Memory can usually be extended by adding external memory chips.

2.4.2.2 ROM

ROM, read only memory, usually holds program or fixed user data. ROM is nonvolatile. If
power is removed from ROM and then reapplied, the original data will still be there. ROM
memory is programmed during the manufacturing process, and the user cannot change its
contents. ROM memory is only useful if you have developed a program and wish to create
several thousand copies of it.

2.4.2.3 PROM

PROM, programmable read only memory, is a type of ROM that can be programmed in the
field, often by the end user, using a device called a PROM programmer. Once a PROM has
been programmed, its contents cannot be changed. PROMs are usually used in low
production applications where only a few such memories are required.

2.4.2.4 EPROM

16
EPROM, erasable programmable read only memory, is similar to ROM, but EPROM can be
programmed using a suitable programming device. An EPROM memory has a small clear-
glass window on top of the chip where the data can be erased under strong ultraviolet light.
Once the memory is programmed, the window can be covered with dark tape to prevent
accidental erasure of the data. An EPROM memory must be erased before it can be
reprogrammed. Many developmental versions of microcontrollers are manufactured with
EPROM memories where the user program can be stored. These memories are erased and
reprogrammed until the user is satisfied with the program. Some versions of EPROMs,
known as OTP (one time programmable), can be programmed using a suitable programmer
device but cannot be erased. OTP memories cost much less than EPROMs. OTP is useful
after a project has been developed completely and many copies of the program memory must
be made.

2.4.2.5 EEPROM

EEPROM, electrically erasable programmable read only memory, is a nonvolatile memory


that can be erased and reprogrammed using a suitable programming device. EEPROMs are
used to save configuration information, maximum and minimum values, identification data,
etc. Some microcontrollers have built-in EEPROM memories. For instance, the PIC18F452
contains a 256-byte EEPROM memory where each byte can be programmed and erased
directly by applications software. EEPROM memories are usually very slow. An EEPROM
chip is much costlier than an EPROM chip.

2.4.2.6 Flash EEPROM

Flash EEPROM, a version of EEPROM memory, has become popular in microcontroller


applications and is used to store the user program. Flash EEPROM is nonvolatile and usually
very fast. The data can be erased and then reprogrammed using a suitable programming
device. Some microcontrollers have only 1K flash EEPROM while others have 32K or more.
The AT89C52 microcontroller has 1K bytes of flash memory.

17
2.4.3 Input / Output ports

In order that the microcontroller is of any use, it has to be connected to additional electronics,
i. e. peripherals. For that reason, each microcontroller has one or more registers (called "port"
in this case) connected to the microcontroller pins. Why input/output? Because you can
change the pin‘s function as you wish. simply performed by software, which means that pin‘s
function can be changed during operation. One of more important feature of I/O pins is
maximal current they can give/get. For the most microcontrollers, current obtained from one
pin is sufficient to activate a LED or other similar low-current consumer (10-20 mA). If the
microcontroller has many I/O pins, then maximal current of one pin is lower. each I/O port is
under control of another SFR, which means that each bit of that register determines state of
the corresponding microcontroller pin. For example, by writing logic one (1) to one bit of
that control register SFR, the appropriate port pin is automatically configured as input. It
means that voltage brought to that pin can be read as logic 0 or 1. Otherwise, by writing zero
to the SFR, the appropriate port pin is configured as output. Its voltage (0V or 5V)
corresponds to the state of the appropriate bit of the port register.

2.5 Some of Microcontroller Features:

18
2.5.1 Supply Voltage

Most microcontrollers operate with the standard logic voltage of + 5V. Some
microcontrollers can operate at as low as + 2.7V, and some will tolerate + 6V
without any problem. The manufacturer‘s data sheet will have information about the
allowed limits of the power supply voltage. At89c52 microcontrollers can operate
with a power supply of + 2V to 5.5V. Usually, a voltage regulator circuit is used to
obtain the required power supply voltage when the device is operated from a mains
adapter or batteries. For example, a 5V regulator is required if the microcontroller is
operated from a 5V supply using a 9V battery.

2.5.2 The Clock

All microcontrollers require a clock (or an oscillator) to operate, usually provided by


external timing devices connected to the microcontroller. In most cases, these external
timing devices are a crystal plus two small capacitors. In some cases they are resonators
or an external resistor-capacitor pair. Some microcontrollers have built-in timing circuits
and do not require external timing components. If an application is not time-sensitive,
external or internal (if available) resistor-capacitor timing components are the best
option for their simplicity and low cost. An instruction is executed by fetching it from
the memory and then decoding it. This usually takes several clock cycles and is known
as the instruction cycle. Thus the microcontroller operates at a clock rate that is one-
quarter of the actual oscillator frequency. The 8051 series of microcontrollers can
operate with clock frequencies up to 40MHz.

2.5.3 Timers

Timers are important parts of any microcontroller. A timer is basically a counter which
is driven from either an external clock pulse or the microcontroller‘s internal oscillator.
A timer can be 8 bits or 16 bits wide. Data can be loaded into a timer under program
control, and the timer can be stopped or started by program control. Most timers can be

19
configured to generate an interrupt when they reach a certain count (usually when they
overflow). The user program can use an interrupt to carry out accurate timing-related
operations inside the microcontroller. Microcontrollers in the 8051 series have at least
three timers. For example, the AT89C52 microcontroller has three built-in timers. Some
microcontrollers offer capture and compare facilities, where a timer value can be read
when an external event occurs, or the timer value can be compared to a preset value, and
an interrupt is generated when this value is reached.

2.5.4 Reset Input

A reset input is used to reset a microcontroller externally. Resetting puts the


microcontroller into a known state such that the program execution starts from address 0
of the program memory. An external reset action is usually achieved by connecting a
push-button switch to the reset input. When the switch is pressed, the microcontroller is
reset.

2.5.5 Interrupts

Interrupts are an important concept in microcontrollers. An interrupt causes the


microcontroller to respond to external and internal (e.g., a timer) events very quickly. When
an interrupt occurs, the microcontroller leaves its normal flow of program execution and
jumps to a special part of the program known as the interrupt service routine (ISR). The
program code inside the ISR is executed, and upon return from the ISR the program resumes
its normal flow of execution.
The ISR starts from a fixed address of the program memory sometimes known as the
interrupt vector address. Some microcontrollers with multi-interrupt features have just one
interrupt vector address, while others have unique interrupt vector addresses, one for each
interrupt source. Interrupts can be nested such that a new interrupt can suspend the execution
of another interrupt. Another important feature of multi-interrupt capability is that different
interrupt sources can be assigned different levels of priority. The at89c52 microcontroller has
8 interrupts source.

20
2.5.6 Analog-to-Digital Converter

An analog-to-digital converter (A/D) is used to convert an analog signal, such as


voltage, to digital form so a microcontroller can read and process it. Some
microcontrollers have built-in A/D converters. External A/D converter can also be
connected to any type of microcontroller. A/D converters are usually 8 to 10 bits,
having 256 to 1024 quantization levels. Most 8051 microcontrollers with A/D
features have multiplexed A/D converters which provide more than one analog input
channel. The A/D conversion process must be started by the user program and may
take several hundred microseconds to complete. A/D converters usually generate
interrupts when a conversion is complete so the user program can read the converted
data quickly. A/D converters are especially useful in control and monitoring
applications, since most sensors (e.g., temperature sensors, pressure sensors, force
sensors, etc.) produce analog output voltages.

2.5.7 Serial Input-Output

Serial communication (also called RS232 communication) enables a microcontroller


to be connected to another microcontroller or to a PC using a serial cable. Some
microcontrollers have built-in hardware called USART (universal synchronous-
asynchronous receiver-transmitter) to implement a serial communication interface.
The user program can usually select the baud rate and data format. If no serial input-
output hardware is provided, it is easy to develop software to implement serial data
communication using any I/O pin of a microcontroller.

2.6 The 8051 Microcontroller

2.6.1 Architecture:

21
All 8051 microcontrollers are 40 pin devices. The pin configuration of AT89C52 or
AT89S52 (DIP package) is shown in figure.

2.6.2 Block diagram:

22
2.6.3 The Reset:
The reset action put the microcontroller in the unknown state. Resetting a 8051
microcontroller starts execution of the program from address 0000H of the
program memory.

2.6.4 The clock source:

23
The 8051 microcontroller can be operated from an external crystal or ceramic
resonator connected to the microcontroller's XTAL1 and XTAL2 pins.

2.6.5 Input/Output Ports (I/O Ports):


All 8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be
configured as inputs or outputs. Accordingly, in total of 32 input/output pins
enabling the microcontroller to be connected to peripheral devices are available
for use.
Pin configuration, i.e. whether it is to be configured as an input (1) or an output
(0), depends on its logic state, in order to configure a microcontroller pin as an
input, it is necessary to apply a logic one (1) to appropriate port. In this case,
voltage level on appropriate pin will be 5V (as is the case with any TTL input.

Port 0

The P0 port is characterized by two functions. If external memory is used then the lower
address byte (addresses A0-A7) is applied on it. Otherwise, all bits of this port are
configured as inputs/outputs.

The other function is expressed when it is configured as an output. Unlike other ports
consisting of pins with built-in pull-up resistor connected by its end to 5 V power supply,
pins of this port have this resistor left out. This apparently small difference has its
consequences:

24
If any pin of this port is configured as an input then it acts as if it “floats”. Such an input
has unlimited input resistance and in determined potential.

When the pin is configured as an output, it acts as an “open drain”. By applying logic 0 to
a port bit, the appropriate pin will be connected to ground (0V). By applying logic 1, the
external output will keep on “floating”. In order to apply logic 1 (5V) on this output pin,
it is necessary to built in an external pull-up resistor.

Port 1

P1 is a true I/O port, because it doesn't have any alternative functions as is the case with
P0, but can be configured as general I/O only. It has a pull-up resistor built-in and is
completely compatible with TTL circuits.

Port 2

P2 acts similarly to P0 when external memory is used. Pins of this port occupy addresses
intended for external memory chip. This time it is about the higher address byte with

25
addresses A8-A15. When no memory is added, this port can be used as a general
input/output port showing features similar to P1.

Port 3

All port pins can be used as general I/O, but they also have an alternative function. In
order to use these alternative functions, a logic one (1) must be applied to appropriate bit
of the P3 register. In terms of hardware, this port is similar to P0, with the difference that
its pins have a pull-up resistor built-in.

Pin's Current limitations


When configured as outputs (logic zero (0)), single port pins can receive a current of
10mA. If all 8 bits of a port are active, a total current must be limited to 15mA (port P0:
26mA). If all ports (32 bits) are active, total maximum current must be limited to 71mA.
When these pins are configured as inputs (logic 1), built-in pull-up resistors provide very
weak current, but strong enough to activate up to 4 TTL inputs of LS series.

2.6.6 Special Function Registers (SFRs):

Special Function Registers (SFRs) are a sort of control table used for running and
monitoring the operation of the microcontroller. Each of these registers as well as each bit
they include, has its name, address in the scope of RAM and precisely defined purpose
such as timer control, interrupt control, serial communication control etc. Even though
there are 128 memory locations intended to be occupied by them, the basic core, shared
by all types of 8051 microcontrollers, has only 21 such registers. Rest of locations are
intentionally left unoccupied in order to enable the manufacturers to further develop
microcontrollers keeping them compatible with the previous versions. It also enables
programs written a long time ago for microcontrollers which are out of production now to
be used today.

26
A Register (Accumulator)

A register is a general-purpose register used for storing intermediate results obtained


during operation. Prior to executing an instruction upon any number or operand it is
necessary to store it in the accumulator first. All results obtained from arithmetical
operations performed by the ALU are stored in the accumulator. Data to be moved from
one register to another must go through the accumulator. In other words, the A register is
the most commonly used register and it is impossible to imagine a microcontroller
without it. More than half instructions used by the 8051 microcontroller use somehow the
accumulator.

B Register

Multiplication and division can be performed only upon numbers stored in the A and B
registers. All other instructions in the program can use this register as a spare accumulator
(A).

27
R Registers (R0-R7)

This is a common name for 8 general-purpose registers (R0, R1, R2 ...R7). Even though
they are not true SFRs, they deserve to be discussed here because of their purpose. They
occupy 4 banks within RAM. Similar to the accumulator, they are used for temporary
storing variables and intermediate results during operation. Which one of these banks is
to be active depends on two bits of the PSW Register. Active bank is a bank the registers
of which are currently used.

The following example best illustrates the purpose of these registers. Suppose it is
necessary to perform some arithmetical operations upon numbers previously stored in the
R registers: (R1+R2) - (R3+R4). Obviously, a register for temporary storing results of
addition is needed. This is how it looks in the program:

MOV A,R3; Means: move number from R3 into accumulator

28
ADD A,R4; Means: add number from R4 to accumulator (result remains in
accumulator)
MOV R5,A; Means: temporarily move the result from accumulator into R5
MOV A,R1; Means: move number from R1 to accumulator
ADD A,R2; Means: add number from R2 to accumulator
SUBB A,R5; Means: subtract number from R5 (there are R3+R4)

Program Status Word (PSW) Register

PSW register is one of the most important SFRs. It contains several status bits that reflect
the current state of the CPU. Besides, this register contains Carry bit, Auxiliary Carry,
two register bank select bits, Overflow flag, parity bit and user-definable status flag.

P - Parity bit:
If a number stored in the accumulator is even then this bit will be automatically set (1),
otherwise it will be cleared (0). It is mainly used during data transmit and receive via
serial communication.
Bit 1:
This bit is intended to be used in the future versions of microcontrollers.
OV Overflow:
occurs when the result of an arithmetical operation is larger than 255 and cannot be
stored in one register. Overflow condition causes the OV bit to be set (1). Otherwise, it
will be cleared (0).
RS0, RS1 - Register bank select bits:
These two bits are used to select one of four register banks of RAM. By setting and
clearing these bits, registers R0-R7 are stored in one of four banks of RAM.
F0 - Flag 0:
This is a general-purpose bit available for use.
AC - Auxiliary Carry Flag:

29
is used for BCD operations only.
CY - Carry Flag:
is the (ninth) auxiliary bit used for all arithmetical operations and shift instructions.

Data Pointer Register (DPTR)

DPTR register is not a true one because it doesn't physically exist. It consists of two
separate registers: DPH (Data Pointer High) and (Data Pointer Low). For this reason it
may be treated as a 16-bit register or as two independent 8-bit registers. Their 16 bits are
primarily used for external memory addressing. Besides, the DPTR Register is usually
used for storing data and intermediate results.

Stack Pointer (SP) Register

A value stored in the Stack Pointer points to the first free stack address and permits stack
availability. Stack pushes increment the value in the Stack Pointer by 1. Likewise, stack
pops decrement its value by 1. Upon any reset and power-on, the value 7 is stored in the
Stack Pointer, which means that the space of RAM reserved for the stack starts at this

30
location. If another value is written to this register, the entire Stack is moved to the new
memory location.

P0, P1, P2, P3 - Input/Output Registers

If neither external memory nor serial communication system are used then 4 ports with in
total of 32 input/output pins are available for connection to peripheral environment. Each
bit within these ports affects the state and performance of appropriate pin of the
microcontroller. Thus, bit logic state is reflected on appropriate pin as a voltage (0 or 5 V)
and vice versa, voltage on a pin reflects the state of appropriate port bit.

As mentioned, port bit state affects performance of port pins, i.e. whether they will be
configured as inputs or outputs. If a bit is cleared (0), the appropriate pin will be
configured as an output, while if it is set (1), the appropriate pin will be configured as an
input. Upon reset and power-on, all port bits are set (1), which means that all appropriate
pins will be configured as inputs.

2.6.7 Counters and Timers

As you already know, the microcontroller oscillator uses quartz crystal for its operation.
As the frequency of this oscillator is precisely defined and very stable, pulses it generates
are always of the same width, which makes them ideal for time measurement. Such
crystals are also used in quartz watches. In order to measure time between two events it is
sufficient to count up pulses coming from this oscillator. That is exactly what the timer
does. If the timer is properly programmed, the value stored in its register will be
incremented (or decremented) with each coming pulse, i.e. once per each machine cycle.
A single machine-cycle instruction lasts for 12 quartz oscillator periods, which means
that by embedding quartz with oscillator frequency of 12MHz, a number stored in the
timer register will be changed million times per second, i.e. each microsecond.

31
The 8051 microcontroller has 2 timers/counters called T0 and T1. As their names suggest,
their main purpose is to measure time and count external events. Besides, they can be
used for generating clock pulses to be used in serial communication, so called Baud Rate.

Timer T0
As seen in figure below, the timer T0 consists of two registers – TH0 and TL0
representing a low and a high byte of one 16-digit binary number.

Accordingly, if the content of the timer T0 is equal to 0 (T0=0) then both registers it
consists of will contain 0. If the timer contains for example number 1000 (decimal), then
the TH0 register (high byte) will contain the number 3, while the TL0 register (low byte)
will contain decimal number 232.

Formula used to calculate values in these two registers is very simple:


TH0 × 256 + TL0 = T
Matching the previous example it would be as follows:
3 × 256 + 232 = 1000

32
Since the timer T0 is virtually 16-bit register, the largest value it can store is 65 535. In
case of exceeding this value, the timer will be automatically cleared and counting starts
from 0. This condition is called an overflow. Two registers TMOD and TCON are closely
connected to this timer and control its operation.

TMOD Register (Timer Mode)

The TMOD register selects the operational mode of the timers T0 and T1. As seen in
figure below, the low 4 bits (bit0 - bit3) refer to the timer 0, while the high 4 bits (bit4 -
bit7) refer to the timer 1. There are 4 operational modes and each of them is described
herein.

Bits of this register have the following function:

GATE1 :

enables and disables Timer 1 by means of a signal brought to the INT1 pin (P3.3):

1 - Timer 1 operates only if the INT1 bit is set.

0 - Timer 1 operates regardless of the logic state of the INT1 bit.

C/T1 :

selects pulses to be counted up by the timer/counter 1:

1 - Timer counts pulses brought to the T1 pin (P3.5).

0 - Timer counts pulses from internal oscillator.

T1M1,T1M0:

These two bits select the operational mode of the Timer 1.

T1M1 T1M0 MODE DESCRIPTION

33
0 0 0 13-bit timer

0 1 1 16-bit timer

1 0 2 8-bit auto-reload

1 1 3 Split mode

GATE0 enables and disables Timer 1 using a signal brought to the INT0 pin (P3.2):
1 - Timer 0 operates only if the INT0 bit is set.
0 - Timer 0 operates regardless of the logic state of the INT0 bit.
C/T0 selects pulses to be counted up by the timer/counter 0:
1 - Timer counts pulses brought to the T0 pin (P3.4).
0 - Timer counts pulses from internal oscillator.
T0M1,T0M0 These two bits select the operational mode of the Timer 0.

T0M1 T0M0 MODE DESCRIPTION

0 0 0 13-bit timer

0 1 1 16-bit timer

1 0 2 8-bit auto-reload

1 1 3 Split mode

Timer Control (TCON) Register

TCON register is also one of the registers whose bits are directly in control of timer operation.
Only 4 bits of this register are used for this purpose, while rest of them is used for interrupt control
to be discussed later.

 TF1 bit is automatically set on the Timer 1 overflow.


 TR1 bit enables the Timer 1.
o 1 - Timer 1 is enabled.
o 0 - Timer 1 is disabled.
 TF0 bit is automatically set on the Timer 0 overflow.
 TR0 bit enables the timer 0.
o 1 - Timer 0 is enabled.
o 0 - Timer 0 is disabled.

34
How to use the Timer 0 ?

In order to use timer 0, it is first necessary to select it and configure the mode of its operation. Bits
of the TMOD register are in control of it:

Referring to figure above, the timer 0 operates in mode 1 and counts pulses generated by internal
clock the frequency of which is equal to 1/12 the quartz frequency.
Turn on the timer:

35
The TR0 bit is set and the timer starts operation. If the quartz crystal with frequency of 12MHz is
embedded then its contents will be incremented every microsecond. After 65.536 microseconds,
the both registers the timer consists of will be loaded. The microcontroller automatically clears
them and the timer keeps on repeating procedure from the beginning until the TR0 bit value is
logic zero (0).

2.6.8 8051 Microcontroller Interrupts

There are five interrupt sources for the 8051, which means that they can recognize 5 different
events that can interrupt regular program execution. Each interrupt can be enabled or disabled by
setting bits of the IE register. Likewise, the whole interrupt system can be disabled by clearing the
EA bit of the same register. Refer to figure below.

Now, it is necessary to explain a few details referring to external interrupts- INT0 and INT1. If the
IT0 and IT1 bits of the TCON register are set, an interrupt will be generated on high to low
transition, i.e. on the falling pulse edge (only in that moment). If these bits are cleared, an
interrupt will be continuously executed as far as the pins are held low.

36
IE Register (Interrupt
Enable)

 EA - global interrupt enable/disable:


o 0 - disables all interrupt requests.
o 1 - enables all individual interrupt requests.
 ES - enables or disables serial interrupt:
o 0 - UART system cannot generate an interrupt.
o 1 - UART system enables an interrupt.
 ET1 - bit enables or disables Timer 1 interrupt:
o 0 - Timer 1 cannot generate an interrupt.
o 1 - Timer 1 enables an interrupt.

37
 EX1 - bit enables or disables external 1 interrupt:
o 0 - change of the pin INT0 logic state cannot generate an interrupt.
o 1 - enables an external interrupt on the pin INT0 state change.
 ET0 - bit enables or disables timer 0 interrupt:
o 0 - Timer 0 cannot generate an interrupt.
o 1 - enables timer 0 interrupt.
 EX0 - bit enables or disables external 0 interrupt:
o 0 - change of the INT1 pin logic state cannot generate an interrupt.
o 1 - enables an external interrupt on the pin INT1 state change.
Interrupt Priorities

It is not possible to forseen when an interrupt request will arrive. If several interrupts are enabled,
it may happen that while one of them is in progress, another one is requested. In order that the
microcontroller knows whether to continue operation or meet a new interrupt request, there is a
priority list instructing it what to do.

The priority list offers 3 levels of interrupt priority:

1. Reset! The apsolute master. When a reset request arrives, everything is stopped
and the microcontroller restarts.
2. Interrupt priority 1 can be disabled by Reset only.
3. Interrupt priority 0 can be disabled by both Reset and interrupt priority 1.
The IP Register (Interrupt Priority Register) specifies which one of existing interrupt sources have
higher and which one has lower priority. Interrupt priority is usually specified at the beginning of
the program. According to that, there are several possibilities:

 If an interrupt of higher priority arrives while an interrupt is in progress, it will be


immediately stopped and the higher priority interrupt will be executed first.
 If two interrupt requests, at different priority levels, arrive at the same time then
the higher priority interrupt is serviced first.
 If the both interrupt requests, at the same priority level, occur one after another,
the one which came later has to wait until routine being in progress ends.
 If two interrupt requests of equal priority arrive at the same time then the interrupt
to be serviced is selected according to the following priority list:
1. External interrupt INT0
2. Timer 0 interrupt

38
3. External Interrupt INT1
4. Timer 1 interrupt
5. Serial Communication Interrupt
IP Register (Interrupt Priority)

The IP register bits specify the priority level of each interrupt (high or low priority).

 PS - Serial Port Interrupt priority bit


o Priority 0
o Priority 1
 PT1 - Timer 1 interrupt priority
o Priority 0
o Priority 1
 PX1 - External Interrupt INT1 priority
o Priority 0
o Priority 1
 PT0 - Timer 0 Interrupt Priority
o Priority 0
o Priority 1
 PX0 - External Interrupt INT0 Priority
o Priority 0
o Priority 1
Handling Interrupt

When an interrupt request arrives the following occurs:

1. Instruction in progress is ended.


2. The address of the next instruction to execute is pushed on the stack.
3. Depending on which interrupt is requested, one of 5 vectors (addresses) is written
to the program counter in accordance to the table below:
4.
INTERRUPT SOURCE VECTOR (ADDRESS)

39
IE0 3h

TF0 Bh

TF1 1B h

RI, TI 23 h

All addresses are in hexadecimal format

5. These addresses store appropriate subroutines processing interrupts. Instead of


them, there are usually jump instructions specifying locations on which these
subroutines reside.
6. When an interrupt routine is executed, the address of the next instruction to execute
is poped from the stack to the program counter and interrupted program resumes
operation from where it left off.

From the moment an interrupt is enabled, the microcontroller is on alert all the time. When an
interrupt request arrives, the program execution is stopped, electronics recognizes the source
and the program “jumps” to the appropriate address (see the table above). This address usually
stores a jump instruction specifying the start of appropriate subroutine. Upon its execution, the
program resumes operation from where it left off.

2.6.9 Introduction to assembly programming:

The process of writing program for the microcontroller mainly consists of giving instructions
(commands) in the specific order in which they should be executed in order to carry out a specific
task. As electronics cannot “understand” what for example an instruction “if the push button is
pressed- turn the light on” means, then a certain number of simpler and precisely defined orders
that decoder can recognise must be used. All commands are known as INSTRUCTION SET. All
microcontrollers compatibile with the 8051 have in total of 255 instructions, i.e. 255 different
words available for program writing.

At first sight, it is imposing number of odd signs that must be known by heart. However, It is not
so complicated as it looks like. Many instructions are considered to be “different”, even though
they perform the same operation, so there are only 111 truly different commands. For example:
ADD A,R0, ADD A,R1, ... ADD A,R7 are instructions that perform the same operation (additon of
the accumulator and register). Since there are 8 such registers, each instruction is counted
separately. Taking into account that all instructions perform only 53 operations (addition,
subtraction, copy etc.) and most of them are rarely used in practice, there are actually 20-30
abbreviations to be learned, which is acceptable.

40
3.1 Types of instructions

Depending on operation they perform, all instructions are divided in several groups:

 Arithmetic Instructions
 Branch Instructions
 Data Transfer Instructions
 Logic Instructions
 Bit-oriented Instructions
The first part of each instruction, called MNEMONIC refers to the operation an instruction
performs (copy, addition, logic operation etc.). Mnemonics are abbreviations of the name of
operation being executed. For example:

 INC R1 - Means: Increment register R1 (increment register R1);


 LJMP LAB5 - Means: Long Jump LAB5 (long jump to the address marked as
LAB5);
 JNZ LOOP - Means: Jump if Not Zero LOOP (if the number in the accumulator is
not 0, jump to the address marked as LOOP);
The other part of instruction, called OPERAND is separated from mnemonic by at least one
whitespace and defines data being processed by instructions. Some of the instructions have no
operand, while some of them have one, two or three. If there is more than one operand in an
instruction, they are separated by a comma. For example:

 RET - return from a subroutine;


 JZ TEMP - if the number in the accumulator is not 0, jump to the address marked
as TEMP;
 ADD A,R3 - add R3 and accumulator;
 CJNE A,#20,LOOP - compare accumulator with 20. If they are not equal, jump
to the address marked as LOOP;
Arithmetic instructions

Arithmetic instructions perform several basic operations such as addition, subtraction, division,
multiplication etc. After execution, the result is stored in the first operand. For example:

ADD A,R1 - The result of addition (A+R1) will be stored in the accumulator.
ARITHMETIC INSTRUCTIONS

Mnemonic Description Byte Cy

ADD A,Rn Adds the register to the accumulator 1 1

41
ADD A,direct Adds the direct byte to the accumulator 2 2

ADD A,@Ri Adds the indirect RAM to the accumulator 1 2

ADD A,#data Adds the immediate data to the accumulator 2 2

ADDC A,Rn Adds the register to the accumulator with a carry flag 1 1

ADDC A,direct Adds the direct byte to the accumulator with a carry flag 2 2

ADDC A,@Ri Adds the indirect RAM to the accumulator with a carry flag 1 2

ADDC A,#data Adds the immediate data to the accumulator with a carry flag 2 2

SUBB A,Rn Subtracts the register from the accumulator with a borrow 1 1

SUBB A,direct Subtracts the direct byte from the accumulator with a borrow 2 2

SUBB A,@Ri Subtracts the indirect RAM from the accumulator with a borrow 1 2

SUBB A,#data Subtracts the immediate data from the accumulator with a borrow 2 2

INC A Increments the accumulator by 1 1 1

INC Rn Increments the register by 1 1 2

INC Rx Increments the direct byte by 1 2 3

INC @Ri Increments the indirect RAM by 1 1 3

DEC A Decrements the accumulator by 1 1 1

DEC Rn Decrements the register by 1 1 1

DEC Rx Decrements the direct byte by 1 1 2

DEC @Ri Decrements the indirect RAM by 1 2 3

INC DPTR Increments the Data Pointer by 1 1 3

MUL AB Multiplies A and B 1 5

DIV AB Divides A by B 1 5

DA A Decimal adjustment of the accumulator according to BCD code 1 1

Branch Instructions

There are two kinds of branch instructions:

Unconditional jump instructions: upon their execution a jump to a new location from where the
program continues execution is executed.

Conditional jump instructions: a jump to a new program location is executed only if a


specified condition is met. Otherwise, the program normally proceeds with the next
instruction.

BRANCH INSTRUCTIONS

Mnemonic Description Byte C

ACALL addr11 Absolute subroutine call 2 6

LCALL addr16 Long subroutine call 3 6

42
RET Returns from subroutine 1 4

RETI Returns from interrupt subroutine 1 4

AJMP addr11 Absolute jump 2 3

LJMP addr16 Long jump 3 4

SJMP rel Short jump (from –128 to +127 locations relative to the following instruction) 2 3

JC rel Jump if carry flag is set. Short jump. 2 3

JNC rel Jump if carry flag is not set. Short jump. 2 3

JB bit,rel Jump if direct bit is set. Short jump. 3 4

JBC bit,rel Jump if direct bit is set and clears bit. Short jump. 3 4

JMP @A+DPTR Jump indirect relative to the DPTR 1 2

JZ rel Jump if the accumulator is zero. Short jump. 2 3

JNZ rel Jump if the accumulator is not zero. Short jump. 2 3

CJNE A,direct,rel Compares direct byte to the accumulator and jumps if not equal. Short jump. 3 4

CJNE A,#data,rel Compares immediate data to the accumulator and jumps if not equal. Short jump. 3 4

CJNE Rn,#data,rel Compares immediate data to the register and jumps if not equal. Short jump. 3 4

CJNE @Ri,#data,rel Compares immediate data to indirect register and jumps if not equal. Short jump. 3 4

DJNZ Rn,rel Decrements register and jumps if not 0. Short jump. 2 3

DJNZ Rx,rel Decrements direct byte and jump if not 0. Short jump. 3 4

NOP No operation 1 1

Data Transfer Instructions

Data transfer instructions move the content of one register to another. The register the
content of which is moved remains unchanged. If they have the suffix “X” (MOVX), the
data is exchanged with external memory.

D A TA T R A N S F E R I N S T R U C T I O N S

Mnemonic Description Byte C

MOV A,Rn Moves the register to the accumulator 1 1

MOV A,direct Moves the direct byte to the accumulator 2 2

MOV A,@Ri Moves the indirect RAM to the accumulator 1 2

MOV A,#data Moves the immediate data to the accumulator 2 2

MOV Rn,A Moves the accumulator to the register 1 2

MOV Rn,direct Moves the direct byte to the register 2 4

MOV Rn,#data Moves the immediate data to the register 2 2

MOV direct,A Moves the accumulator to the direct byte 2 3

MOV direct,Rn Moves the register to the direct byte 2 3

MOV direct,direct Moves the direct byte to the direct byte 3 4

MOV direct,@Ri Moves the indirect RAM to the direct byte 2 4

43
MOV direct,#data Moves the immediate data to the direct byte 3 3

MOV @Ri,A Moves the accumulator to the indirect RAM 1 3

MOV @Ri,direct Moves the direct byte to the indirect RAM 2 5

MOV @Ri,#data Moves the immediate data to the indirect RAM 2 3

MOV DPTR,#data Moves a 16-bit data to the data pointer 3 3

MOVC A,@A+DPTR Moves the code byte relative to the DPTR to the accumulator (address=A+DPTR) 1 3

MOVC A,@A+PC Moves the code byte relative to the PC to the accumulator (address=A+PC) 1 3

MOVX A,@Ri Moves the external RAM (8-bit address) to the accumulator 1 3

MOVX A,@DPTR Moves the external RAM (16-bit address) to the accumulator 1 3

MOVX @Ri,A Moves the accumulator to the external RAM (8-bit address) 1 4

MOVX @DPTR,A Moves the accumulator to the external RAM (16-bit address) 1 4

PUSH direct Pushes the direct byte onto the stack 2 4

POP direct Pops the direct byte from the stack/td> 2 3

XCH A,Rn Exchanges the register with the accumulator 1 2

XCH A,direct Exchanges the direct byte with the accumulator 2 3

XCH A,@Ri Exchanges the indirect RAM with the accumulator 1 3

XCHD A,@Ri Exchanges the low-order nibble indirect RAM with the accumulator 1 3

Logic Instructions

Logic instructions perform logic operations upon corresponding bits of two registers.
After execution, the result is stored in the first operand.

LOGIC INSTRUCTIONS

Mnemonic Description Byte Cyc

ANL A,Rn AND register to accumulator 1 1

ANL A,direct AND direct byte to accumulator 2 2

ANL A,@Ri AND indirect RAM to accumulator 1 2

ANL A,#data AND immediate data to accumulator 2 2

ANL direct,A AND accumulator to direct byte 2 3

ANL direct,#data AND immediae data to direct register 3 4

ORL A,Rn OR register to accumulator 1 1

ORL A,direct OR direct byte to accumulator 2 2

ORL A,@Ri OR indirect RAM to accumulator 1 2

ORL direct,A OR accumulator to direct byte 2 3

ORL direct,#data OR immediate data to direct byte 3 4

XRL A,Rn Exclusive OR register to accumulator 1 1

XRL A,direct Exclusive OR direct byte to accumulator 2 2

XRL A,@Ri Exclusive OR indirect RAM to accumulator 1 2

44
XRL A,#data Exclusive OR immediate data to accumulator 2 2

XRL direct,A Exclusive OR accumulator to direct byte 2 3

XORL direct,#data Exclusive OR immediate data to direct byte 3 4

CLR A Clears the accumulator 1 1

CPL A Complements the accumulator (1=0, 0=1) 1 1

SWAP A Swaps nibbles within the accumulator 1 1

RL A Rotates bits in the accumulator left 1 1

RLC A Rotates bits in the accumulator left through carry 1 1

RR A Rotates bits in the accumulator right 1 1

RRC A Rotates bits in the accumulator right through carry 1 1

Bit-oriented Instructions

Similar to logic instructions, bit-oriented instructions perform logic operations. The


difference is that these are performed upon single bits.

B I T- O R I E N T E D I N S T R U C T I O N S

Mnemonic Description Byte Cycle

CLR C Clears the carry flag 1 1

CLR bit Clears the direct bit 2 3

SETB C Sets the carry flag 1 1

SETB bit Sets the direct bit 2 3

CPL C Complements the carry flag 1 1

CPL bit Complements the direct bit 2 3

ANL C,bit AND direct bit to the carry flag 2 2

ANL C,/bit AND complements of direct bit to the carry flag 2 2

ORL C,bit OR direct bit to the carry flag 2 2

ORL C,/bit OR complements of direct bit to the carry flag 2 2

MOV C,bit Moves the direct bit to the carry flag 2 2

MOV bit,C Moves the carry flag to the direct bit 2 3

3.2 Description of all 8051 instructions

Here is a list of the operands and their meanings:

 A - accumulator;
Rn - is one of working registers (R0-R7) in the currently active RAM memory
bank;
 Direct - is any 8-bit address register of RAM. It can be any general-purpose
register or a SFR (I/O port, control register etc.);

45
 @Ri - is indirect internal or external RAM location addressed by register R0 or
R1;
 #data - is an 8-bit constant included in instruction (0-255);
 #data16 - is a 16-bit constant included as bytes 2 and 3 in instruction (0-65535);
 addr16 - is a 16-bit address. May be anywhere within 64KB of program memory;
 addr11 - is an 11-bit address. May be within the same 2KB page of program
memory as the first byte of the following instruction;
 rel - is the address of a close memory location (from -128 to +127 relative to the
first byte of the following instruction). On the basis of it, assembler computes the
value to add or subtract from the number currently stored in the program counter;
 bit - is any bit-addressable I/O pin, control or status bit; and
 C - is carry flag of the status register (register PSW).

TRANSISTOR

The transistor’s function is to amplify an electric current. Many different


kinds of transistors are used in analog circuits, for different reasons. This is
not the case of digital circuits. In a digital circuit, only two values matters,
on and off. The amplification ability of transistor is not relevant in digital
circuit. In many cases, a circuit is built with integrated circuits (ICs).
Transistors are often used in digital circuits as buffer to protect ICs. For
example, when powering an electromagnetic switch (called a ‘relay’), or
when controlling a light emitting diode (In any case).

46
Two different symbol are used for the transistor.

PNP Type

NPN Type

The name (standard part number) of the transistor, as well as the type and
the way it is used is shown below.
2SAXXXX PNP type high frequency
2SBXXXX PNP type low frequency

47
2SCXXXX NPN type high frequency
2SDXXXX NPN type low frequency
The direction of the current flow differs between the NPN and PNP type.
When the power supply is the side of positive (plus), the NPN type is easy to
use.

TRANSRECEIVER

Here we are using zigbee transreceiver for wireles communication.


ZigBee is the specification of a low-cost, low-power wireless
communications solution, meant to be integrated as the main building block
of ubiquitous networks. It is maintained by the ZigBee Alliance, which
develops the specification and certifies its proper implementation. ZigBee
builds upon the physical layer and medium access control defined in IEEE
standard 802.15.4 for low-rate WPAN's. The specification goes on to
complete the standard by adding four main components: network layer,
application layer, ZigBee device objects (ZDO's) and manufacturer-defined
application objects which allow for customization and favor total
integration. These are responsible for a number of tasks, which include
keeping of device roles, management of requests to join a network, device
discovery and security. Its network layer natively supports three types of
topologies: both star and tree typical networks and generic mesh networks.
Every network must have one coordinator device, tasked with its creation,
the control of its parameters and basic maintenance. Within star networks,
the coordinator must be the central node.

48
The main functions of the network layer are to enable the correct use of the
MAC sublayer and provide a suitable interface for use by the next upper
layer, namely the application layer. The routing protocol used by the
Network layer is AODV. In order to find the destination device, it broadcasts
out a route request to all of its neighbors. The neighbors then broadcast the
request to their neighbors, etc until the destination is reached. Once the
destination is reached, it sends its route reply via unicast transmission
following the lowest cost path back to the source.

Once the source receives the reply, it will update its routing table for the
destination address with the next hop in the path and the path cost.

The application layer is the highest-level layer defined by the specification,


and is the effective interface of the ZigBee system to its end users. It
comprises the majority of components added by the ZigBee specification:
both ZDO and its management procedures, together with application objects
defined by the manufacturer, are considered part of this layer.

49
Zigbee protocol stack

As one of its defining features, ZigBee provides facilities for carrying out
secure communications, protecting establishment and transport of
cryptographic keys, cyphering frames and controlling devices. It builds on
the basic security framework defined in IEEE 802.15.4. This part of the
architecture relies on the correct management of symmetric keys and the
correct implementation of methods and security policies.

50
LIGHT EMITTING DIODE (LED)

Light emitting diode must be chosen according to how they will be used,
because there are various kinds. The led are available in several colours. The
most common colours are red and green, but there are even blue ones.

The device on the far right in the photograph combines a red LED and green
LED in one package. The component lead in the middle is common to both
LED’s as for the remaining two leads; one side is for green, the other for the
red LED. When both are tuned ON simultaneously, it becomes orange.

When an LED is new out of package, the polarity of the device can be
determined by looking at the leads. The longer leads are the anode sides, and
the shortest one is the cathode side. The polarity of an LED can also be
determined using a resistor meter or even a 1.5 V battery.

51
When using a test meter to determine polarity, set the meter to a low
resistance measurement range. Connect the probe of the meter to the LED. If
the polarity is correct, the LED will glow. If the LED does not glow, switch
the meter probes to the opposite leads on the LED.

CAPACITORS

A capacitor can store charge and its capacity to store charge is called
capacitance. Capacitors consists of two conducting plates, separated by an
insulating material (known as dielectric). The two plates are joined with two
leads. The dielectric could be air, mica , paper ceramic, polyester,
polystyrene etc. The dielectric gives name to the capacitor. Like paper
capacitor, mica capacitor etc.

Types of capacitors :

52
Capacitor can be broadly classified in two categories, i.e., Electrolytic
capacitor and Non-Electrolytic capacitor as shown in the figure above.

Electrolytic Capacitor:

Electrolytic capacitors have an electrolyte as a dielectric. When such an


electrolyte is charged, chemical changes take place in the electrolyte. If it’s
one plate is charged positively, same plate must be charged positively in the
future. We call such capacitor as polarized. Normally we see electrolytic
capacitor as polarized capacitor and the leads are marked with positive or
negative on the can. Non-electrolytic capacitors have dielectric material such

53
as paper, mica or ceramic. Therefore, depending upon the dielectric, these
capacitor are classified.

Mica Capacitor:

It is sandwich of several thin metal plates separated by thin sheet of mica.


Alternate plates are connected together and leads attached for outside
connections. The total assembly is encased in a plastic capsule or Bakelite
case. Such capacitor have small capacitance value (50 to 500pf) and high
working voltage (500V and above). The mica capacitors have excellent
characteristics under stress of temperature variation and high voltage
application. These capacitor are now replaced by ceramic capacitor.

Ceramic Capacitor:

Such capacitor have disc or hollow tabular shaped dielectric made of


ceramic material such as titanium dioxide and barium titanic. Thin coating
of silver compound is deposited on both sides of dielectric disc, which acts
as capacitor plates. Leads are attached to each sides of the dielectric disc and
whole unit is encapsulated in a moisture proof coating. Disc type capacitors
have very high value up to 0.001uf. Their working voltage range from 3V to
60000V. These capacitor have very low leakage current. Breakdown voltage
is very high.

THE DIODE:

54
Diode are polarized, which means that they must be inserted into the PCB
the correct way round. This is because an electric current will only flow
through them in one direction (like air will only flow one way through a tyre
valve). Diode have two connections, an anode and a cathode. The cathode is
always identified by a dot, ring or some other mark.

The PCB is often marked with a +sign for the cathode end. Diodes come in
all shapes and sizes. They are often marked with a type number. Detailed
characteristics of a diode can be found by looking up the type number in a
data book. If you know how to measure resistance with a meter then test
some diodes. A good one has low resistance in one direction and high in
other. They are specialized type of diode available such as the zener and
light emitting diode (LED).

55
CHARACTERSTICS OF DIODES:

When a small voltage is applied to the diode in the forward direction, current
flows easily. Because the diode has a certain amount of resistance, the
voltage will drop slightly as current flow through the diode. A typical diode
causes a voltage drop about 0.6-1V (VF) (In the case of silicon diode almost
0.6V). This voltage drop needs to be taken into consideration in a circuit
which uses many diodes in series. Also, the amount of current passing
through the diodes must be considered.

When voltage is applied in the reverse direction through a diode, the diode
will have a great resistance to current flow. Different diodes have different
characteristics when reverse-biased. A given diode should be selected
depending on how it will be used in the circuit.

56
The current that will flow through a diode biased in the reverse direction will
vary from several mA to just µA, which is very small.

Voltage regulation diode (Zener Diode):


The circuit symbol is

It is used to regulate voltage, by taking advantage of the fact that Zener


Diodes tend to stabilize at a certain voltage when that voltage is applied in
the opposite direction.

Light emitting diode:


The circuit symbol is

This type of Diode emits light when current flows through it in the forward
direction (Forward biased).

Variable capacitance diode :


The circuit symbol is

57
The current does not flow when applying the voltage of the opposite
direction to the diode. In this condition, the diode has a capacitance like the
capacitor. It is a very small capacitance. The capacitance of the diode
changes when changing voltage. With the change of this capacitance, the
frequency of the oscillator can be changed.

RESISTORS:

The flow of charge (or current) through any material, encounter an opposing
force similar in many respect to mechanical friction. This opposing force is
called resistance of the material. It is measured in ohms. In some electric
circuits resistance is deliberetly introduced in the form of resistor.
Resistors are of following types:

1. Wire wound resistors.


2. Carbon resistors.
3. Metal film resistors.

Wire Wound Resistors:

Wire wound resistors are made from a long (usually Ni-Chromium) wound
on a ceramic core. Longer the length of the wire, higher is the resistance. So
depending on the value of resistor required in a circuit, the wire is cut and
wound in a ceramic core. This entire assembly is coated with a ceramic
metal. Such resistors are available in power of 2 watts to several hundred

58
watts and resistance value from 1 Ohm to 100K Ohms. Thus wire wound
resistors are used for high currents.
Carbon Resistor:

Carbon resistors are divided into three types:


a.
Carbon composition resistors are made by mixing carbon grains with
binding material (glue) and module in the forms of rods. Wire leads are
inserted at the two ends. After this an insulating material seals the resistor.
Resistor are available in power rating of 1/10, 1/8, 1/4, 1/2, watts and value
from 1 ohm to 20 ohms.
b.
Carbon film resistors are made by deposition carbon film on a ceramic rod.
They are cheaper than carbon composition resistors.
c.
Cement film resistors are made of thin carbon coating fired onto a solid
ceramic substrate. The main purpose is to have more precise resistance
values and greater stability with heat. They are made in a small square with
leads.

Metal Film Resistor:

They are also called thin film resistors. They are made of thin metal coating
deposited on a cylindrical insulating support. The high resistance values are
not precise in value; however, such resistors are free of induction effect that
is common in wire wound resistors at high frequency.

59
Variable resistors:

Potentiometer is a resistor where value can be set depending on the


requirement. Potentiometer is widely used in electronic systems. Examples
are volume control, tons control, brightness and contrast control of radio or
T.V. sets.

Fusible Resistors:

These resistors are wire wound type and are used in T.V. circuits for
protection. They have resistance of less than 15 ohms. Their function is
similar to a fuse made flow off whenever current in the circuit exceeds the
limit.

MOTORS:

Motor is an electromechanical device or digital motor as it can move in


discrete steps and traverse through 360 degrees. Now a days many computer
peripherals contain one or more motors.

60
The two main characteristics of motors are synchronism and constant step
size. The brushed DC electric motor generates torque directly from DC
power supplied to the motor by using internal commutation, stationary
permanent magnets, and rotating electrical magnets. Like all electric motors
or generators, torque is produced by the principle of Lorentz force, which
states that any current-carrying conductor placed within an external
magnetic field experiences a torque or force known as Lorentz force.
Advantages of a brushed DC motor include low initial cost, high reliability,
and simple control of motor speed. Disadvantages are high maintenance and
low life-span for high intensity uses. Maintenance involves regularly
replacing the brushes and springs which carry the electric current, as well as
cleaning or replacing the commutator. These components are necessary for
transferring electrical power from outside the motor to the spinning wire
windings of the rotor inside the motor.

LCD:
A liquid crystal display (LCD) is a thin, flat electronic visual display that
uses the light modulating properties of liquid crystals(LCs). LCs do not emit
light directly.it is an electronically-modulated optical device made up of any
number of pixels filled with liquid crystals and arrayed in front of alight
source (backlight) or reflector to produce images in colour or monochrome.

Each pixel of an LCD typically consists of a layer of molecules aligned


between two transparent electrodes, and two polarizing filters, the axes of
transmission of which are (in most of the cases) perpendicular to each other.
With no actual liquid crystal between the polarizing filters, light passing

61
through the first filter would be blocked by the second (crossed) polarizer. In
most of the cases the liquid crystal has double refraction.

Before applying an electric field, the orientation of the liquid crystal


molecules is determined by the alignment at the surfaces of electrodes.

Table of Pin Description of LCD :

MAX-232:

The MAX232 is an integrated circuit that converts signals from an RS-


232 serial port to signals suitable for use in TTL compatible digital logic

62
circuits. The MAX232 is a dual driver/receiver and typically converts the
RX, TX, CTS and RTS signals.

The drivers provide RS-232 voltage level outputs from a single + 5 V


supply via on-chip charge pumps and external capacitors. This makes it
useful for implementing RS-232 in devices that otherwise do not need any
voltages outside the 0 V to + 5 V range, as power supply design does not
need to be made more complicated just for driving the RS-232 in this case.

When a MAX232 IC receives a TTL level to convert, it changes a TTL


Logic 0 to between +3 and +15 V, and changes TTL Logic 1 to between -3 to
-15 V, and vice versa for converting from RS232 to TTL.

The MAX232 is a dual driver/receiver that includes a capacitive voltage


generator to supply EIA-232 voltage levels from a single 5-V supply.

RS232 Line Type & Logic RS232 TTL Voltage to/from


Level Voltage MAX232

Data Transmission (Rx/Tx)


+3 V to +15 V 0V
Logic 0

63
Data Transmission (Rx/Tx)
-3 V to -15 V 5V
Logic 1

Max-232(operating circuit)

64
65
IC 7805 :

Three terminal positive fixed voltage regulators:

These voltage regulators are monolithic integrated circuits designed as fixed


voltage. These regulators employ internal current limiting, thermal
shutdown, and safe area compensation. With adequate heat sinking they can
deliver output current in excess of 1.0A. Although designed primarily as
fixed voltage regulator, these devices can be used with external component
to obtain adjustable voltages and currents.

66
WORKING:

 The two blocks represent the two trains having Anti-Collision


System.
 ACD (ANTICOLLISION DEVICE) consists of a microcontroller,LCD
panel and Wireless Communication Unit,Potentiometer,button
switches,transistor,LED etc.
 If the two trains are on same track,heading towards each other
and if it comes in the range of transreceiver then the red LED
will glow and a warning message is displayed on the LCD panel
and both the trains will automatically stop.
 If the two trains are on same track moving in the same
direction then ACD will check for speed and if the speed of rear
end train is more then the rear end train will automatically stop
without affecting the front end train .
 The rear end train will not move until any of the train changes
the track.
 As ACD will detect the collision, the red LED will glow and a
warning message is displayed on the LCD panel.
 The green LED indicates the smooth movement of trains.

RF based Wireless Remote Control

67
The circuit of this project utilises the RF module (Tx/Rx) for making a wireless remote, which
could be used to drive an output from a distant place. RF module, as the name suggests, uses
radio frequency to send signals. These signals are transmitted at a particular frequency and a
baud rate. A receiver can receive these signals only if it is configured for that frequency.

A four channel encoder/decoder pair has also been used in this system. The input signals, at the
transmitter side, are taken through four switches while the outputs are monitored on a set of
four LEDs corresponding to each input switch.
The circuit can be used for designing Remote Appliance Control system. The outputs from the
receiver can drive corresponding relays connected to any household appliance.

This radio frequency (RF) transmission project employs Amplitude Shift Keying (ASK) with
transmitter/receiver (Tx/Rx) pair operating at 434 MHz. The transmitter module takes serial input
and transmits these signals through RF. The transmitted signals are received by the receiver
module placed away from the source of transmission.

68
The system allows one way communication between two nodes, namely, transmission and
reception. The RF module has been used in conjunction with a set of four channel
encoder/decoder ICs. HereHT12E & HT12D have been used as encoder and decoder
respectively. The encoder converts the parallel inputs (from the remote switches) into serial set of
signals. These signals are serially transferred through RF to the reception point. The decoder is
used after the RF receiver to decode the serial format and retrieve the original signals as outputs.
These outputs can be observed on correspondingLEDs.

Encoder IC (HT12E) receives parallel data in the form of address bits and control bits. The control
signals from remote switches along with 8 address bits constitute a set of 12 parallel signals. The
encoder HT12E encodes these parallel signals into serial bits. Transmission is enabled by
providing ground to pin14 which is active low. The control signals are given at pins 10-13 of
HT12E. The serial data is fed to the RF transmitter through pin17 of HT12E.

69
Transmitter, upon receiving serial data from encoder IC (HT12E), transmits it wirelessly to the RF
receiver. The receiver, upon receiving these signals, sends them to the decoder IC (HT12D)
through pin2. The serial data is received at the data pin (DIN, pin14) of HT12D. The decoder then
retrieves the original parallel format from the received serial data.

70
When no signal is received at data pin of HT12D, it remains in standby mode and consumes very
less current (less than 1µA) for a voltage of 5V. When signal is received by receiver, it is given to
DIN pin (pin14) of HT12D. On reception of signal, oscillator of HT12D gets activated. IC HT12D
then decodes the serial data and checks the address bits three times. If these bits match with the
local address pins (pins 1-8) of HT12D, then it puts the data bits on its data pins (pins 10-13) and
makes the VT pin high. An LED is connected to VT pin (pin17) of the decoder. This LED works as
an indicator to indicate a valid transmission. The corresponding output is thus generated at the
data pins of decoder IC.

A signal is sent by lowering any or all the pins 10-13 of HT12E and corresponding signal is
received at receiver’s end (at HT12D). Address bits are configured by using the by using the first
8 pins of both encoder and decoder ICs. To send a particular signal, address bits must be same
at encoder and decoder ICs. By configuring the address bits properly, a single RF transmitter can
also be used to control different RF receivers of same frequency.

To summarize, on each transmission, 12 bits of data is transmitted consisting of 8 address bits


and 4 data bits. The signal is received at receiver’s end which is then fed into decoder IC. If
address bits get matched, decoder converts it into parallel data and the corresponding data bits
get lowered which could be then used to drive the LEDs. The outputs from this system can either
be used in negative logic or NOT gates (like 74LS04) can be incorporated at data pins.

CIRCUIT DIAGRAM

71
RF Module (Transmitter & Receiver)

The RF module, as the name suggests, operates at Radio Frequency. The corresponding
frequency range varies between 30 kHz & 300 GHz. In this RF system, the digital data is

72
represented as variations in the amplitude of carrier wave. This kind of modulation is known as
Amplitude Shift Keying (ASK).

Transmission through RF is better than IR (infrared) because of many reasons. Firstly, signals
through RF can travel through larger distances making it suitable for long range applications.
Also, while IR mostly operates in line-of-sight mode, RF signals can travel even when there is an
obstruction between transmitter & receiver. Next, RF transmission is more strong and reliable
than IR transmission. RF communication uses a specific frequency unlike IR signals which are
affected by other IR emitting sources.

This RF module comprises of an RF Transmitter and an RF Receiver. The transmitter/receiver


(Tx/Rx) pair operates at a frequency of 434 MHz. An RF transmitter receives serial data and
transmits it wirelessly through RF through its antenna connected at pin4. The transmission occurs
at the rate of 1Kbps - 10Kbps.The transmitted data is received by an RF receiver operating at the
same frequency as that of the transmitter.

73
The RF module is often used alongwith a pair of encoder/decoder. The encoder is used for
encoding parallel data for transmission feed while reception is decoded by a decoder. HT12E-
HT12D, HT640-HT648, etc. are some commonly used encoder/decoder pair ICs.

Pin Diagram:

Pin Description:
RF Transmitter

Pin No Function Name


1 Ground (0V) Ground
2 Serial data input pin Data
3 Supply voltage; 5V Vcc
4 Antenna output pin ANT

RF Receiver

Pin No Function Name


1 Ground (0V) Ground
2 Serial data output pin Data

74
3 Linear output pin; not connected NC
4 Supply voltage; 5V Vcc
5 Supply voltage; 5V Vcc
6 Ground (0V) Ground
7 Ground (0V) Ground
8 Antenna input pin ANT

BIBILOGRAPHY AND REFRENCE

Through Books and Magzine

1. INTEGERATED ELECTRONICS (TMH edition 1991) By Jacob Millman


& Christos C. Halkias
2. Kenneth J. Ayala “The 8051 Microcontroller – Architecture,
Programming and application”.
3. James W. Stewart “The 8051 Microcontroller – Hardware, Software
and Interfacing (Pearson).
4. Raj Kamal “Microcontrollers: Architecture, Programming,
Interfacing and System Design” Pearson edition 2005

5. Muhammad Ali Mazidi, Janice Gillispie Mazidi and Rolin D. McKinlay


The 8051 Microcontroller and Embedded Systems ( PHI of India Ltd.,
New Delhi 2nd Edition 2006.

75
Through Internet :

1. www.datasheet.com
2. www.electronicsforyou.com
3. www.coolcircuit.com
4. www.williamsonlabs.com
5. www.wikipedia.com
6. www.fairchildsemi.com
7. www.datasheetcatalog.com

76

S-ar putea să vă placă și