Você está na página 1de 55

1

Chapter 1: INTRODUCTION
Railway is lifeline of India and it is being the cheapest modes of transportation are preferred
over all other means of transportation. When we go through the daily newspapers we come
across many accidents in railroad railings. Railroad-related accidents are more dangerous
than other transportation accidents in terms of severity and death rate etc. Therefore more
efforts are necessary for improving safety. Collisions with train are generally catastrophic, in
that the destructive forces of a train usually no match for any other type of vehicle. Train
collisions form a major catastrophe, as they cause severe damage to life and property. Train
collisions occur frequently eluding all the latest technology.
Fig1.1: Causalities in Train Accidents during 1995-96 to 2006-07
1.1 PROJECT BACKGROUND
Railway safety is a crucial aspect of rail operation the world over.
Malfunctions resulting in accidents usually get wide media coverage even when the railway
is not at fault and give to rail transport, among the uninformed public, an undeserved image
of inefficiency often fueling calls for immediate
2
reforms. This paper is aimed at helping the railway administrations concerned to
strengthen their safety culture and develop the monitoring tools required by modern
safety management. Railroad intersections are very unique, special, potentially
dangerous and yet unavoidable in the World. Here two different entities with entirely
different responsibilities, domains, performances come together and converge for a
single cause of providing a facility to the road user. During the normal operation
also, there is every possibility of accidents occurring even with very little negligence
in procedure and the result is of very high risk. The potential for accidents is made
higher as the railways control only half the problem. The other half, meanwhile,
cannot really be said to be controlled by one entity, as even though traffic rules and
road design standards supposedly exist, the movements of road users are not
organized and monitored by one specific entity as rigidly as rail movements. The
railway systems of Asia and the Pacific are no exception to this. Each year, accidents
at level crossings not only cause fatalities or serious injuries to many thousands of
road users and railway passengers, but also impose a heavy financial burden in terms
of disruptions of railway and road services and damages to railway and road vehicles
and property. A very high number of these collisions are caused by the negligence,
incompetence or incapacity of road vehicle drivers, who by and large operate their
vehicles in environments in which safety consciousness is practically non-existent.
Since it is the railway which must bear the responsibility for ensuring that it is
protected from the transgressions by road users (despite the fact that in many
countries the law gives it priority of passage over road users), it is the railway which
also has to shoulder most of the financial burden of providing this protection.
Similarly, it is the railway, which has most of the responsibility for educating road
users on the safe use of its level crossings. Notwithstanding this, it appears that in
many regions, railways
are ill-equipped to be in a position to monitor level crossing safety effectively and to
take both corrective and pro-active measures to improve the safety of their level
crossing installations.
In the rapidly flourishing country like ours, even though all the
latest technologies are there train collisions are occurring frequently. The railway
accidents are happening due to the carelessness in manual operations or lack of
workers. The other main reasons for the collisions of Train are: 1.Train Derailment in
3
curves and bends,2.Running Train collisions with the Standing Train,3.Train
Accidents in Slopes,4.Mis- signaling due to fog or Mist. There is no fruitful steps
have been taken so far in these areas. This paper deals about one of the efficient
methods to avoid train Collision and derailment. Also by using simple electronic
components we tried to automate the control of railway gate in an embedded
platform. The system has been implemented and demonstrated by using vibration
sensor and ZigBee with the help of microcontroller.
1.2 SCOPE: To
Review the present status of level-crossing accidents and train collisions.
Present statistics, indicators, technology and problems relating to the systems
adopted for railway protection; in practice
Analyze various alternative systems for train collision avoidance; and
Make recommendations pertaining to the selection of cost-effective
protection systems.
1.3 METHODOLOGY:
The following analyses are considered:
Evaluation of the requirements of a Safety Management Information System
which adequately addresses the needs of railway management for information
on train collision avoidance performance;
Review of the essential and effective safety, enhancements, measures and
priorities for railway security.
Assessment of level crossing safety performance and safety measures
Examination of Cost Benefit Analysis of investments on level crossing safety
enhancement;
Review of the technical attributes and suitability of Networked Anti Collision
System (ACD) for level crossing protection system;
Recommendations and guidelines for adoption of networked ACD Systems
by railways.
4
1.4 ORGANISATION OF THE REPORT
In the following chapter we are going to discuss more about the literature
review in chapter 2, the proposed system in chapter 3, results, discussion and
conclusion of the system in chapter 4. At the end of the report the list of references
and related appendices are attached.
We start with the literature review about the railway security monitoring
system and the existing system. Then we discuss about the flow of the project and the
important components of the project development in chapter 3.Finally we made the
conclusion and future recommendations in chapter 4, follwed by the references and
appendices.
5
Chapter: 2 LITERATURE REVIEW
2.1 EXISTING SYSTEM
The existing conventional signaling system most of the times relay
on the oral communication through telephonic and telegraphic conversations as input
for the decision making in track allocation for trains. There is large scope for
miscommunication of the information or communication gap due to the higher
human interference in the system. This miscommunication may lead to wrong
allocation of the track for trains, which ultimately leads to the train collision. The
statistics in the developing countries showing that 80% of worst collisions occurred
so far is due to either human error or incorrect decision making through
miscommunication in signaling and its implementation. IR sensors are also used to
identify the cracks in the railway. IR sensors have limitations due to the geographic
nature of the tracks. The Anti collision device system also is found to be ineffective
as it is not considering any active inputs from existing Railway signaling system, and
also lacks two ways communication capability between the trains and the control
centers or stations. Later geographical sensors have also been used which makes use
of satellites for communication. But the system is costly and complicated to
implement.
At present laser proximity detector is used for collision avoidance, IR sensors
identifies the cracks in the railway track and gate control is done by manual switch
controlled gate. But there is no combined solution for collision between trains, train
derailment in curves and bends and the automatic control of railway gate.
6
2.2 PROPOSED SYSTEM
RAILWAY SECURITY MONITORING SYSTEM USING GSM
One of the major problems that railroads have faced since the earliest days is the
prevention of service failures in track. As is the case with all modes of high-speed
travel, Rail is manufactured in different weights; there are different rail conditions
wear, corrosion etc.! present; there are a significant number of potential defects
possible; and the task has to be performed with some speed to reliably inspect the
thousands of miles of track stretching across the land failures of an essential
component can have serious conse"uences. #he main problem about a railway
analysis is detection of cracks in the structure. $f these deficiencies are not controlled
at early stages they might cause huge economical problems affecting the rail network
une%pected re"uisition of spare parts, handling of incident and&or accidents!. #he
main part of the work was to carry out a feasibility study on two methods for
detection of cracks and avoidance of the collision between the rails. #he detection of
cracks can be done by sensors.
'ig. (.) shows the circuit of the microcontroller-based detection of crack in railway
system. *icrocontroller A#+,-(./) is the heart of the system. $t is an +-bit
microcontroller with +k0 'lash programmable and erasable read-only memory
12RO*!, (/34+ bits of RA*, 5( input&output $&O! lines, three )3-bit
timers&counters, a si%-vector two-level interrupt architecture, a full-duple% serial port,
a precision analogue comparator, on-chip oscillator and clock circuitry.
7
'ig.(.)

8

Chapter:3 CIRCUIT WORKING
6e divided our project in to three important phases7
). #rack -rack detection
(. #o stop train nearby track crack position with help sensor
5. #rain anti collusion system to avoid accident
r!"e#t #!$%tr&#t'!$
Step(1
6e use a toy train model in our project. 'irst we remove toy train fast dc motor with
slow speed dc gear motor for smooth drive in our project. 8econdly we fi% train track
on wooden base.
'ig 5.)
Step(2
9
6e divided our project track in to four different route or station. 6e are flowing
ground current on the track with help of thin wire, this wire send signal in case of
broken.
6e put ir sensor on the starting of route track. $f wire broken track signal generate,
this ir sensor unit goes active. $f any train interrupt these sensors by crossing it,
control unit send rf signal to train for applying brake
'ig 5.(
)*!#+ ,'a-ra. !/ #!$tr!**'$- &$'t
N!r.a* #a%e
'ig 5.5
Tra#+ Cra#+ ,ete#t'!$ #a%e
10
'ig 5.9
Step(3
A$t' #!**'%'!$ %0%te.
#his unit is installing in the train, when any object or train comes in front this device
controlling unit cut the power supply of train.
'ig 5./
11
Tra'$ #'r#&'t

'ig 5.3
A$t' #!**'%'!$ #'r#&'t
1'- 3.2
12
O)STACLES AND DETH SENSOR UNIT
$n this unit the dc supply is first converted into /: using regulator
;*<+./ and supplied to the complete circuit. #he high-efficiency $R;2=
driven by pnp transistor tbc53, with a modulating fre"uency of about (.
kh> available from pin no / of the $- ;*/3<, the versatile 1;; tone
decoder $-!, emit infrared light. At this juncture the output at pin no + is
high and this condition is maintained until $- ;*/3< receives a valid (.
kh> signal at its pin 5.
1'- 3.3
6henever the $R beam is radiated by $R;2= is reflected by a nearby
object obstacles!, ;*/3< receives (.kh> reflected signal at its pin 5 on
detection by photo diode. As a result ;*/3< pulls its output pin low.
$f the output at pin + is high then it will switch the transistor in O?
state and it will ground the collector. As the collector of first npn transistor is
grounded, the ne%t transistor will not switch and the output at second npn
transistor is high, because of collector of second transistor connected to :--.
6hereas when the obstacle is detected the output at pin + is low and thus the
collector of second transistor is grounded and the output to the
microcontroller is low.
6hen a low signal is sent to the microcontroller it will come to know
an obstacle is detected. #he obstacle sensor logic is used for left, right and
front sensors. Respectively, ).left!, ))right! and )( front! pins of
microcontroller are connected to their own obstacle sensors.
Circuit
13
OWER SULY.
/ :O;# R2@A;A#2= 1O62R 8A11;B -$R-A$#.
$n this project firstly we use one step down transformer. 8tep down transformer step
down the voltage from ((. volt Ac to )( volt Ac. #his Ac voltage is further
converted into =- with the help of rectifier circuit. $n rectifier circuit we use #6O
diode. All the diodes are arranges as a full wave rectifier circuit. Output of this
rectifier is pulsating =c. #o convert this pulsating =- into smooth dc we use one
capacitor as a filter components. -apacitor converts the pulsating =c into smooth =-
with the help of its charging and discharging effect.
Output of the rectifier is now regulated with the help of $- regulator circuit. $n this
project we use positive voltage regulator circuit. Cere we use three pin regulator.
Output of this regulator is regulated voltage. $f we use <+./ regulator then its means
its is / volt regulator and if we use <+.+ regulator then its means that it is + volt
regulator circuit. $n this project we use / volt dc regulated power supply for the
complete circuit.
'ig. 5.,
14
'ig5.).
MICRCONTROLLER INTER1ACE
Cere we use ic +,s/( controller. #his controller is a 9. pin ic. 1in no 9. of the ic is
connected with the positive / volt supply. 1in no 5) is also connected to the positive
supply. 1in no (. of the ic is connected to the ground pin. 1in no , is reset pin. $n this
pin we connect a one capacitor and resistor to provide a auto reset circuit. 6hen
supply is on then capacitor is charge through the supply and immediately discharge
through the resistor , so pin no , ia active high for a second and due to this ic is to be
reset properly and always start from the .... location.
1in no ) to pin no + is port ) and pin no ). to )< is port 5. pin no )+ and ), of the ic
is connected to the e%ternal crystal to provide a e%ternal clock to run the internal cpu
of controller . pin no (. is ground pin. 1in no () to (+ is port ( pins. 1in no (,,5.,5)
is not use in this project. 6e use these pin when we re"uire a e%tra memory for the
project. $f we internal memory of the +,s/( which is 9k rom! then we connect pin
no 5) to the positive supply.#here is total 5( pins are available for the input and
output. 1in no () to (< is connected to ;-= .
15
Re%et C'r#&'tr0:
1in no , of the controller is connected to the reset circuit. On the circuit we connect
one resistor and capacitor circuit to provide a reset option when power is on
As soon as you give the power supply the +./) doesnDt start. Bou need to restart for
the microcontroller to start. Restarting the microcontroller is nothing but giving a
;ogic ) to the reset pin at least for the ( clock pulses. 8o it is good to go for a small
circuit which can provide the ( clock pulses as soon as the microcontroller is
powered.
#his is not a big circuit we are just using a capacitor to charge the microcontroller
and again discharging via resistor.
'ig 5.))
-rystals 1in no )+ and ), is connected to e%ternal crystal oscillator to provide a
clock to the circuit.
16
-rystals provide the synchroni>ation of the internal function and to the peripherals.
6henever ever we are using crystals we need to put the capacitor behind it to make it
free from noises. $t is good to go for a 55pf capacitor.

'ig 5.)(

6e can also resonators instead of costly crystal which are low cost and e%ternal
capacitor can be avoided.
0ut the fre"uency of the resonators varies a lot. And it is strictly not advised when
used for communications projects.
17
Chapter:4 I$tr!,&#t'!$ t! MICROCONTROLLERS
WELCOME TO THE WORLD O1 THE MICROCONTROLLERS.
;ook around. ?otice the smart EintelligentF systemsG 0e it the #.:, washing
machines, video games, telephones, automobiles, aero planes, power systems, or any
application having a ;2= or a ;-= as a user interface, the control is likely to be in
the hands of a micro controllerH *easure and control, thatDs where the micro
controller is at its best. *icro controllers are here to stay. @oing by the current trend,
it is obvious that micro controllers will be playing bigger and bigger roles in the
different activities of our lives.
#hese embedded chips are very small, but are designed to replace components much
bigger and bulky $n si>e. #hey process information very intelligently and efficiently.
#hey sense the environment around them. #he signals they gather are tuned into
digital data that streams through tributaries of circuit lines at the speed of light. $nside
the microprocessor collates and calculators. #he software has middling intelligence.
#hen in a split second, the processed streams are shoved out.
What is the primary difference between a microprocessor and a micro
controllerG
Anlike the microprocessor, the micro controller can be considered to be a true
E-omputer on a chipF.
$n addition to the various features like the A;A, 1-, 81 and registers found on a
microprocessor, the micro controller also incorporates features like the RO*, RA*,
1orts, timers, clock circuits, counters, reset functions etc.
6hile the microprocessor is more a general-purpose device, used for read, write and
calculations on data, the micro controller, in addition to the above functions also
controls the environment.
18
3562 .'#r! #!$tr!**er
#he +./( developed and launched in the early +.Is, is one of the most popular micro
controller in use today. $t has a reasonably large amount of built in RO* and RA*.
$n addition it has the ability to access e%ternal memory.
#he generic term I+%/(I is used to define the device. #he value of % defining the kind
of RO*, i.e. %J., indicates none, %J5, indicates mask RO*, %J<, indicates 21RO*
and %J, indicates 221RO* or 'lash.
A $!te !$ ROM
#he early +./), namely the +.5) was designed without any RO*. #his device could
run only with e%ternal memory connected to it. 8ubse"uent developments lead to the
development of the 1RO* or the programmable RO*. #his type had the
disadvantage of being highly unreliable.
#he ne%t in line, was the 21RO* or 2rasable 1rogrammable RO*. #hese devices
used ultraviolet light erasable memory cells. #hus a program could be loaded, tested
and erased using ultra violet rays. A new program could then be loaded again.
An improved 21RO* was the 221RO* or the electrically erasable 1RO*. #his
does not re"uire ultra violet rays, and memory can be cleared using circuits within
the chip itself.
'inally there is the ';A8C, which is an improvement over the 221RO*. 6hile the
terms 221RO* and flash are sometimes used interchangeably, the difference lies in
the fact that flash erases the complete memory at one stroke, and not act on the
individual cells. #his results in reducing the time for erasure.
D'//ere$t .'#r!#!$tr!**er% '$ .ar+et.
1$- One of the famous microcontrollers used in the industries. $t is
based on R$8- Architecture which makes the microcontroller process faster
than other microcontroller.
$?#2; #hese are the first to manufacture microcontrollers. #hese are
not as sophisticated other microcontrollers but still the easiest one to learn.

A#*2; AtmelDs A:R microcontrollers are one of the most
powerful in the embedded industry. #his is the only microcontroller having
)kb of ram even the entry stage. 0ut it is unfortunate that in $ndia we are
unable to find this kind of microcontroller.
19
I$te* 3562
$ntel +./( is -$8- architecture which is easy to program in assembly language and
also has a good support for Cigh level languages.
#he memory of the microcontroller is 39k.
#his microcontroller is one of the easiest microcontrollers to learn.
#he +./( microcontroller is in the field for more than (. years. #here are lots of
books and study materials are readily available for +./(.
Der'7at'7e%
#he best thing done by $ntel is to give the designs of the +./( microcontroller to
everyone. 8o it is not the fact that $ntel is the only manufacture for the +./) there
more than (. manufactures, with each of minimum (. models. ;iterally there are
hundreds of models of +./( microcontroller available in market to choose. 8ome of
the major manufactures of +./( are
Atmel
1hilips
h'*'p%
#he 1hilipsKs +./) derivatives has more number of features than in any
microcontroller. #he costs of the 1hilips microcontrollers are higher than the AtmelDs
which makes us to choose Atmel more often than 1hilips
Da**a%
=allas has made many revolutions in the semiconductor market. =allasDs
+./) derivative is the fastest one in the market. $t works 5 times as fast as a +./) can
process. 0ut we are unable to get more in $ndia.
At.e*
#hese people were the one to master the flash devices. #hey are the cheapest
microcontroller available in the market. AtmelDs even introduced a (.pin variant of
+./) named (./). #he AtmelDs +./) derivatives can be got in $ndia less than <.
rupees. #here are lots of cheap programmers available in $ndia for Atmel. 8o it is
always good for students to stick with +./) when you learn a new microcontroller.
20
Ar#h'te#t&re
Architecture is must to learn because before learning new machine it is necessary to
learn the capabilities of the machine. #his is some thing like before learning about
the car you cannot become a good driver. #he block diagram of the +./( is given
below.
'ig. 9.)
#he +./( doesnDt have any special feature than other microcontroller. #he only
feature is that it is easy to learn. Architecture makes us to know about the hardware
features of the microcontroller. #he features of the +./( are

+L 0ytes of 'lash *emory
(/3 % +-0it $nternal RA*
'ully 8tatic Operation7 ) *C> to (9 *C>
21
5( 1rogrammable $&O ;ines
#hree )3-0it #imer&-ounters
2ight $nterrupt 8ources
1rogrammable 8erial -hannel
;ow 1ower $dle and 1ower =own *odes
;etDs now move on to a practical e%ample. 6e shall work on a simple practical
application and using the e%ample as a base, shall e%plore the various features of the
+./) microcontroller.
-onsider an electric circuit as follows,
#he positive side Mve! of the battery is connected to one side of a switch. #he other
side of the switch is connected to a bulb or ;2= ;ight 2mitting =iode!. #he bulb is
then connected to a resistor, and the other end of the resistor is connected to the
negative -ve! side of the battery.
6hen the switch is closed or Kswitched onD the bulb glows. 6hen the switch is open
or Kswitched offD the bulb goes off
$f you are instructed to put the switch on and off every 5. seconds, how would you
do itG Obviously you would keep looking at your watch and every time the second
hand crosses 5. seconds you would keep turning the switch on and off.
$magine if you had to do this action consistently for a full day. =o you think you
would be able to do itG ?ow if you had to do this for a month, a yearGG
?o way, you would sayH
#he ne%t step would be, then to make it automatic. #his is where we use the
*icrocontroller.
0ut if the action has to take place every 5. seconds, how will the microcontroller
keep track of timeG
22
E8e#&t'!$ t'.e
;ook at the following instruction,
#*r p1.5
#his is an assembly language instruction. $t means we are instructing the
microcontroller to put a value of K>eroD in bit >ero of port one. #his instruction is
e"uivalent to telling the microcontroller to switch on the bulb. #he instruction then to
instruct the microcontroller to switch off the bulb is,
Set p1.5
#his instructs the microcontroller to put a value of KoneD in bit >ero of port one.
=onDt worry about what bit >ero and port one means. 6e shall learn it in more detail
as we proceed.
#here are a set of well defined instructions, which are used while communicating
with the microcontroller. 2ach of these instructions re"uires a standard number of
cycles to e%ecute. #he cycle could be one or more in number.
H!9 '% th'% t'.e the$ #a*#&*ate,:
#he speed with which a microcontroller e%ecutes instructions is determined by what
is known as the crystal speed. A crystal is a component connected e%ternally to the
microcontroller. #he crystal has different values, and some of the used values are
3*CN, ).*CN, and ))../, *C> etc.
#hus a ).*CN crystal would pulse at the rate of ).,...,... times per second.
#he time is calculated using the formula
?o of cycles per second J -rystal fre"uency in CN & )(.
'or a ).*CN crystal the number of cycles would be,
).,...,...&)(J+55555.55555 cycles.
#his means that in one second, the microcontroller would e%ecute +55555.55555
cycles.
#herefore for one cycle, what would be the timeG #ry it out.
#he instruction clr p).. would use one cycle to e%ecute. 8imilarly, the instruction
setb p).. also uses one cycle.
8o go ahead and calculate what would be the number of cycles re"uired to be
23
e%ecuted to get a time of 5. secondsH
@etting back to our bulb e%ample, all we would need to do is to instruct the
microcontroller to carry out some instructions e"uivalent to a period of 5. seconds,
like counting from >ero upwards, then switch on the bulb, carry out instructions
e"uivalent to 5. seconds and switch off the bulb.
Oust put the whole thing in a loop, and you have a never ending on-off se"uence.
;et us now have a look at the /eat&re% !/ the 3561 #!re, keeping the above e%ample
as a reference,
1. 3(;'t CU.< C!$%'%t'$- !/ the =A> a$, =)> re-'%ter%?
*ost of the transactions within the microcontroller are carried out through the KAD
register, also known as the Accumulator. $n addition all arithmetic functions are
carried out generally in the KAD register. #here is another register known as the K0D
register, which is used e%clusively for multiplication and division.
#hus an +-bit notation would indicate that the ma%imum value that can be input into
these registers is K))))))))D. 1u>>ledG
#he value is not decimal ))), )),)))H $t represents a binary number, having an
e"uivalent value of K''D in Ce%adecimal and a value of (// in decimal.
6e shall read in more detail on the different numbering systems namely the 0inary
and Ce%adecimal system in our ne%t module.
2. 3K !$(#h'p ROM
Once you have written out the instructions for the microcontroller, where do you put
these instructionsG
Obviously you would like these instructions to be safe, and not get deleted or
changed during e%ecution. Cence you would load it into the KRO*D
#he si>e of the program you write is bound to vary depending on the application, and
the number of lines. #he +./) microcontroller gives you space to load up to +L of
program si>e into the internal RO*.
+L, thatDs allG 6ell just wait. Bou would be surprised at the amount of stuff you can
load in this +L of space.
Of course you could always e%tend the space by connecting to 39L of e%ternal RO*
if re"uired.
24
3. 26@ ;0te% !$(#h'p RAM
#his is the space provided for e%ecuting the program in terms of moving data, storing
data etc.
4. 32 IAO *'$e%. <1!&r( 3 ;'t p!rt%B *a;e*e, 5B 1B 2B 3?
$n our bulb e%ample, we used the notation p)... #his means bit >ero of port one. One
bit controls one bulb.
#hus p!rt !$e would have + bits. #here are a total of four ports named p., p), p(,
p5, giving a total of 5( lines. #hese lines can be used both as input or output.
6. Three 1@ ;'t t'.er% A #!&$ter%.
A microcontroller normally e%ecutes one instruction at a time. Cowever certain
applications would re"uire that some event has to be tracked independent of the main
program.
#he manufacturers have provided a solution, by providing two timers. #hese timers
e%ecute in the background independent of the main program. Once the re"uired time
has been reached, remember the time calculations described aboveG!, they can
trigger a branch in the main program.
#hese timers can also be used as counters, so that they can count the number of
events, and on reaching the re"uired count, can cause a branch in the main program.
@. 1&** D&p*e8 %er'a* ,ata re#e'7er A tra$%.'tter.
#he +./) microcontroller is capable of communicating with e%ternal devices like the
1- etc. Cere data is sent in the form of bytes, at predefined speeds, also known as
baud rates.
#he transmission is serial, in the sense, !$e ;'t at a t'.e
2. 3( '$terr&pt %!&r#e% 9'th t9! pr'!r't0 *e7e*%
=uring the discussion on the timers, we had indicated that the timers can trigger a
branch in the main program. Cowever, what would we do in case we would like the
microcontroller to take the branch, and then return back to the main program, without
having to constantly check whether the re"uired time & count has been reachedG
#his is where the interrupts come into play. #hese can be set to either the timers, or
to some e%ternal events. 6henever the background program has reached the re"uired
criteria in terms of time or count or an e%ternal event, the branch is taken, and on
25
completion of the branch, the control returns to the main program.
1riority levels indicate which interrupt is more important, and needs to be e%ecuted
first in case two interrupts occur at the same time.
3. O$(#h'p #*!#+ !%#'**at!r.
#his represents the oscillator circuits within the microcontroller. #hus the hardware
is reduced to just simply connecting an e%ternal crystal, to achieve the re"uired
pulsing rate.
PIN FUNCTION OF IC 89C5!
) S&pp*0 pin of this ic is pin no 9.. ?ormally we apply a / volt regulated
dc power supply to this pin. 'or this purpose either we use step down
transformer power supply or we use , volt battery with <+./ regulator.
( Gr!&$, pin of this ic is pin no (.. 1in no (. is normally connected to the
ground pin normally negative point of the power supply.
5 CTAL is connected to the pin no )+ and pin no ), of this ic. #he "uart>
crystal oscillator connected to P#A;) and P#A;( 1$?. #hese pins also
needs two capacitors of 5. pf value. One side of each capacitor is
connected to crystal and other pis is connected to the ground point.
?ormally we connect a )( *C> or ))../,( *C> crystal with this ic.. 0ut
we use crystal upto (. *C> to this pins
9 RESET 1$?.. 1in no , is the reset pin of this ic.. $t is an active high pin.
On applying a high pulse to this pin, the micro controller will reset and
terminate all activities. #his is often referred to as a power on reset. #he
high pulse must
be high for a minimum of ( machine cycles before it is allowed to go
low.
5. ORT5 1ort . occupies a total of + pins. '$ $! 32 t! p'$ $! 3D. $t can
be used for input or output. 6e connect all the pins of the port . with the
pullup resistor ). k ohm! e%ternally. #his is due to fact that port . is an
open drain mode. $t is just like a open collector transistor.
6. ORT1. A;; the ports in micrcontroller is + bit wide p'$ $! 1 t! p'$ $!
3 because it is a + bit controller. All the main register and sfr all is mainly
+ bit wide. 1ort ) is also occupies a + pins. 0ut there is no need of pull up
resistor in this port. Apon reset port ) act as a input port. Apon reset all
the ports act as a input port
7. PO"T! port ( also have a + pins. $t can be used as a input or output.
#here is no need of any pull up resistor to this pin.
ORT 3. 1ort5 occupies a totoal + pins from pin no ). to pin no )<. $t
can be used as input or output. 1ort 5 does not re"uire any pull up
resistor. #he same as port ) and port(. 1ort 5 is configured as an output
26
port on reset. 1ort 5 has the additional function of providing some
important signals such as interrupts. 1ort 5 also use for serial
communication.
ALE A;2 is an output pin and is active high. 6hen connecting an +.5) to e%ternal
memory, port . provides both address and data. $n other words, the +.5) multiple%es
address and data through port . to save pins. #he A;2 pin is used for demultiple%ing
the address and data by connecting to the ic <9ls5<5 chip.
SEN. 182? stands for program store eneable. $n an +.5) based system in which an
e%ternal rom holds the program code, this pin is connected to the O2 pin of the rom.
EA. 2A. $n +,c/) +</) or any other family member of the ateml +,c/) series all
come with on-chip rom to store programs, in such cases the 2A pin is connected to
the :cc. 'or family member +.5) and +.5( is which there is no on chip rom, code is
stored in e%ternal memory and this is fetched by +.5). $n that case 2A pin must be
connected to @?= pin to indicate that the code is stored e%ternally.
SECIAL 1UNCTION REGISTER < S1R? ADDRESSES.
A-- A--A*A;A#OR .2.C
0 0 R2@$8#2R .'.C
186 1RO@RA* 8#A#A8 6OR= .=.C
81 8#A-L 1O$?#2R +)C
=1#R =A#A 1O$?#2R ( 0B#28
=1; ;O6 0B#2 O' =1#R +(C
=1C C$@C 0B#2 O' =1#R +5C
1. 1OR#. +.C
1) 1OR#) ,.C
1( 1OR#( .A.C
15 1OR#5 .0.C
#*O= #$*2R&-OA?#2R *O=2 -O?#RO; +,C
27
#-O? #$*2R -OA?#2R -O?#RO; ++C
#C. #$*2R 0 HIGH BYTE 8CH
#;O #$*2R . ;O6 0B#2 +AC
#C) #$*2R ) C$@C 0B#2 +=C
#;) #$*2R ) ;O6 0B#2 +0C
8-O? 82R$A; -O?#RO; ,+C
80A' 82R$A; =A#A 0A''2R ,,C
1-O? 1O62R -O?#RO; +<C
28
Chapter:6 INSTRUCTIONS
SINGLE )IT INSTRUCTIONS.
82#0 0$# 82# #C2 0$# J)
-;R 0$# -;2AR #C2 0$# J.
-1; 0$# -O*1;$*2?# #C2 0$# . J), )J.
O0 0$#,#AR@2# OA*1 #O #AR@2# $' 0$# J)
O?0 0$#, #AR@2# OA*1 #O #AR@2# $' 0$# J.
O0- 0$#,#AR@2# OA*1 #O #AR@2# $' 0$# J) Q#C2? -;2AR #C2
0$#

MOV INSTRUCTIONS
*O: instruction simply copy the data from one location to another location
MOV DBS
-opy the data from8! source to =destination!
MOV R5BA ; -opy contents of A into Register R.
MOV R1BA ; -opy contents of A into register R)
MOV ABR3 ; copy contents of Register R5 into Accumulator.
=$R2-# ;OA=$?@ #CROA@C *O:
29
MOV ABE23H ; =irect load the value of (5h in A
MOV R5BE12h ; direct load the value of )(h in R.
MOV R6BE51DH ; ;oad the ', value in the Register R/
ADD INSTRUCTIONS.
A== instructions adds the source byte to the accumulator A! and place the result in
the Accumulator.
MOV AB E26H
ADD ABE42H ; 0B this instructions we add the value 9(h in Accumulator
9(CM (/C!
ADDABR3 ;0y this instructions we move the data from register r5 to
accumulator and then add the contents of the register into
accumulator .
8A0ROA#$?2 -A;; 'A?-#$O?.
ACALLBTARGET ADDRESS
0y this instructions we call subroutines with a target address within (k bytes from
the current program counter.
LCALL, #AR@2# A==R288.
ACALL is a limit for the ( k byte program counter, but for upto 39k byte we use
;-A;; instructions.. ?ote that ;-A;; is a 5 byte
instructions. A-A;; is a two byte instructions.
AFM TARGET ADDRESS.
Th'% '% /!r a;%!*&te "&.p
30
AFM stand for absolute jump. $t transfers program e%ecution to the target address
unconditionally. #he target address for this instruction must be
withib ( k byte of program memory.
LFM is also for absoltute jump. $t tranfer program e%ecution to the target addres
unconditionally. #his is a 5 byte instructions ;O*1 jump to
any address within 39 k byte location.
INSTRUCTIONS RELATED TO THE CARRY
FC TARGET
OA*1 #O #C2 #AR@2# $' -B ';A@ J)
FNC TARGET
OA*1 #O #C2 #AR@2# A==R288 $' -B ';A@ $8 J .
INSTRUCTIONS RELASTED TO FUM WITH ACCUMULATOR
#$ T%"&'T
FUM TO TARGET I1 A G 5
O?N #AR@2#
JUMP IF ACCUMULATOR IS NOT ZERO
#his instructions jumps if registe A has a value other than >ero
INSTRUCTIONS RELATED TO THE ROTATE
31
"( %
RO#A#2 ;2'# #C2 A--A*A;A#OR
0B this instructions we rotate the bits of A left. #he bits rotated out of A are rotated
back into A at the opposite end
RR A
0y this instruction we rotate the contents of the accumulator from right to left from
;80 to *80
RRC A
#his is same as RR A but difference is that the bit rotated out of register first enter in
to carry and then enter into *80
RLC A
RO#A#2 A ;2'# #CROA@C -ARRB
8ame as above but but shift the data from *80 to carry and carry to ;80
RET
#his is return from subroutine. #his instructions is used to return from a subroutine
previously entered by instructions ;-A;; and A-A;;.
RET1
#C$8 is used at the end of an interrupt service routine. 6e use this instructions after
intruupt routine,
USH.
#his copies the indicated byte onto the stack and increments 81 by . #his instructions
supports only direct addressing mode.
O.
1O1 'RO* 8#A-L.
32
#his copies the byte pointed to be 81 to the location whose direct address is
indicated, and decrements 81 by ). ?otice that this instructions supports only direct
addressing mode.
=1#R $?8#RA-#$O?8.
MOV DTRBE1@ )IT VALUE
;OA= =A#A 1O$?#2R
#his instructions load the )3 bit dptr register with a )3 bit immediate value
MOV C ABHAIDTR
#his instructions moves a byte of data located in program RO* into register A. #his
allows us to put strings of data, such as look up table elements.
MOVC ABHAIC
#his instructions moves a byte of data located in the program area to A. the address
of the desired byte of data is formed by adding the program counter 1-! register to
the original value of the accumulator.
INC )YTE
#his instructions add ) to the register or memory location specified by the operand.
$?- A
$?- Rn
$?- =$R2-#
DEC )YTE
#his instructions subtracts ) from the byte operand. ?ote that -B is unchanged
33
=2- A
=2- Rn
=2- =$R2-#
ARITHMATIC INSTRUCTIONS.
ANL ,e%t(;0teB %!&r#e(;0te
#his perform a logical A?= operation
#his performs a logical A?= on the operands, bit by bit, storing the result in the
destination. ?otice that both the source and destination values are byte Rsi>e only
I
DIV A)
#his instructions divides a byte accumulator by the byte in register 0. $t is assumed
that both register A and 0 contain an unsigned byte. After the division the "uotient
will be in register A and the remainder in register 0.
#*O= #$*2R *O=2 ! R2@$8#2R
0oth timer is the +,c/) share the one register #*O=. 9 ;80 bit for the timer . and
9 *80 for the timer ).
$n each case lower ( bits set the mode of the timer
34
Apper two bits set the operations.
@A#27 @ating control when set. #imer&counter is enabled only while the
$?#P pin is high and the #R% control pin is set. 6hen cleared, the timer is enabled
whenever the #R% control bit is set
-&# 7 #imer or counter selected cleared for timer operation input from
internal system clock!
*) *ode bit )
*. *ode bit .
*) *. *O=2 O12RA#$?@ *O=2
. . . )5 0$# #$*2R&*O=2
. ) ) )3 0$# #$*2R *O=2
) . ( + 0$# AA#O R2;OA=
) ) 5 81;$# #$*2R *O=2
186 1RO@RA* 8#A#A8 6OR=!
-B 186.< -ARRB ';A@
A- 186.3 AAP$;$ARB -ARRB
'. 186./ A:A$;A0;2 'OR #C2 A82R 'RO @2?2RA; 1AR1O82
R8) 186.9 R2@$8#2R 0A?L 82;2-#OR 0$# )
R8. 186.5 R2@$8#2R 0A?L 82;2-#OR 0$# .
.: 186.( O:2R';O6 ';A@
35
-- 186.) A82R =2'$?A0;2 0$#
1 186.. 1AR$#B ';A@ 82#&-;2AR2= 0B CAR=6AR2
CON REGISATER < NON )IT ADDRESSA)LE?
If th SMO! " 0 # !EFAULT ON RESET$
TH% " CRYSTAL FRE&UENCY
'56(((( ))))))))))))))))))))
*8+ , BAU! RATE
If th SMO! IS " %
CRYSTAL FRE&UENCY
TH1 G 26@((((((((((((((((((((((((((((((((((((((
%-' , BAU! RATE
#here are two ways to increase the baud rate of data transfer in the +./)
). #o use a higher fre"uency crystal
(. #o change a bit in the 1-O? register
1-O? register is an + bit register . Of the + bits, some are unused, and some are used
for the power control capability of the +./). the bit which is used for the serial
communication is =<, the 8*O= bit. 6hen the +./) is powered up, =< 8*O=
0$#! O' 1-O? register is >ero. 6e can set it to high by software and thereby
double the baud rate
36
)%U* "%T' CO+P%"I,ION FO" ,+O* - . %N* ,+O* -/
TH1 < DECIMAL? HEC SMOD G5 SMOD G1
(3 1D D@55 1D255
(@ 1A 4355 D@55
(12 14 2455 4355
(24 E3 1255 2455
0T%( - //!.59 +1$

$2 $?#2RRA1# 2?A0;2 R2@$8#OR!
2A $2.< =isable all interrupts if 2A J ., no interrupts is acknowledged
$f 2A is ), each interrupt source is individually enabled or disbaled
0y sending or clearing its enable bit.
$2.3 ?O# implemented
2#( $2./ enables or disables timer ( overflag in +,c/( only
28 $2.9 2nables or disables all serial interrupt
2#) $2.5 2nables or =isables timer ) overflow interrupt
2P) $2.( 2nables or disables e%ternal interrupt
2#. $2.) 2nables or =isbales timer . interrupt.
2P. $2.. 2nables or =isables e%ternal interrupt .
$?#2RRA1# 1R$OR$#B R2@$8#2R
37
$f the bit is ., the corresponding interrupt has a lower priority and if the bit is ) the
corresponding interrupt has a higher priority
$1.< ?O# $*1;2*2?#2=, R282R:2= 'OR 'A#AR2 A82.
$1.3 ?O# $*1;2*2?#2=, R282R:2= 'OR 'A#AR2 A82
1#( $1./ =2'$?2 #C2 #$*2R ( $?#2RRA1# 1R$OR$#B ;2;:2;
18 $1.9 =2'$?28 #C2 82R$A; 1OR# $?#2RRA1# 1R$OR$#B ;2:2;
1#) $1.5 =2'$?28 #C2 #$*2R ) $?#2RRA1# 1R$OR$#B ;2:2;
1P) $1.( =2'$?28 2P#2R?A; $?#2RRA1# ) 1R$OR$#B ;2:2;
1#. $1.) =2'$?28 #C2 #$*2R . $?#2RRA1# 1R$OR$#B ;2:2;
1P. $1.. =2'$?28 #C2 2P#2R?A; $?#2RRA1# . 1R$OR$#B ;2:2;
SCON: SERIAL ORT CONTROL REGISTER B )IT ADDRESSA)LE
8-O?
8*. 7 8-O?.< 8erial 1ort mode specifier
8*) 7 8-O?.3 8erial 1ort mode specifier
8*( 7 8-O?./
R2? 7 8-O?.9 8et&cleared by the software to 2nable&disable reception
#0+ 7 8-O?.5 #he ,
th
bit that will be transmitted in modes ( and 5,
8et&cleared
0y software
R0+ 7 8-O?.( $n modes ( Q5, is the ,
th
data bit that was received. $n mode
),
$f 8*( J ., R0+ is the stop bit that was received. $n mode .
R0+ is not used
38
#) 7 8-O?.) #ransmit interrupt flag. 8et by hardware at the end of the +
th
bit
#ime in mode ., or at the beginning of the stop bit in the
other
*odes. *ust be cleared by software
R) 8-O?.. Receive interrupt flag. 8et by hardware at the end of the +
th
bit
#ime in mode ., or halfway through the stop bit time in the
other
*odes. *ust be cleared by the software.
TCON TIMER COUNTER CONTROL REGISTER
#his is a bit addressable
#') #-O?.< #imer ) overflow flag. 8et by hardware when the
#imer&-ounter )
Overflows. -leared by hardware as processor
#R) #-O?.3 #imer ) run control bit. 8et&cleared by software to turn #imer
-ounter ) On&off
#'. #-O?./ #imer . overflow flag. 8et by hardware when the
timer&counter .
Overflows. -leared by hardware as processor
#R. #-O?.9 #imer . run control bit. 8et&cleared by software to turn timer
-ounter . on&off.
$2) #-O?.5 2%ternal interrupt ) edge flag
$#$ #-O?.( $nterrupt ) type control bit
$2. #-O?.) 2%ternal interrupt . edge
$#. #-O?.. $nterrupt . type control bit.
( 3561 I$%tr&#t'!$ Set
Ar'th.et'# Operat'!$%
*nemonic =escription 8i>e -ycles
39
A== A,Rn Add register to Accumulator A--!. ) )
A== A,direct Add direct byte to A--. ( )
A== A,SRi Add indirect RA* to A-- . ) )
A== A,Tdata Add immediate data to A-- . ( )
A==- A,Rn Add register to A-- with carry . ) )
A==- A,direct Add direct byte to A-- with carry. ( )
A==- A,SRi Add indirect RA* to A-- with carry. ) )
A==- A,Tdata Add immediate data to A-- with carry. ( )
8A00 A,Rn 8ubtract register from A-- with borrow. ) )
8A00 A,direct 8ubtract direct byte from A-- with borrow ( )
8A00 A,SRi 8ubtract indirect RA* from A-- with borrow. ) )
8A00 A,Tdata 8ubtract immediate data from A-- with borrow. ( )
$?- A $ncrement A--. ) )
$?- Rn $ncrement register. ) )
$?- direct $ncrement direct byte. ( )
$?- SRi $ncrement indirect RA*. ) )
=2- A =ecrement A--. ) )
=2- Rn =ecrement register. ) )
=2- direct =ecrement direct byte. ( )
=2- SRi =ecrement indirect RA*. ) )
$?- =1#R $ncrement data pointer. ) (
*A; A0 *ultiply A and 0 Result7 A U- low byte, 0 U- high byte. ) 9
=$: A0 =ivide A by 0 Result7 A U- whole part, 0 U- remainder. ) 9
=A A =ecimal adjust A--. ) )
40
;ogical Operations
*nemonic =escription 8i>e -ycles
A?; A,Rn A?= Register to A--. ) )
A?; A,direct A?= direct byte to A--. ( )
A?; A,SRi A?= indirect RA* to A--. ) )
A?; A,Tdata A?= immediate data to A--. ( )
A?; direct,A A?= A-- to direct byte. ( )
A?; direct,Tdata A?= immediate data to direct byte. 5 (
OR; A,Rn OR Register to A--. ) )
OR; A,direct OR direct byte to A--. ( )
OR; A,SRi OR indirect RA* to A--. ) )
OR; A,Tdata OR immediate data to A--. ( )
OR; direct,A OR A-- to direct byte. ( )
OR; direct,Tdata OR immediate data to direct byte. 5
(
PR; A,Rn 2%clusive OR Register to A--. ) )
PR; A,direct 2%clusive OR direct byte to A--. ( )
PR; A,SRi 2%clusive OR indirect RA* to A--. ) )
PR; A,Tdata 2%clusive OR immediate data to A--. ( )
PR; direct,A 2%clusive OR A-- to direct byte. ( )
PR; direct,Tdata POR immediate data to direct byte. 5 (
-;R A -lear A-- set all bits to >ero!. ) )
-1; A -ompliment A--. ) )
R; A Rotate A-- left. ) )
R;- A Rotate A-- left through carry. ) )
41
RR A Rotate A-- right. ) )
RR- A Rotate A-- right through carry. ) )
86A1 A 8wap nibbles within A--. ) )
=ata #ransfer
*nemonic =escription 8i>e
-ycles
*O: A,Rn *ove register to A--. ) )
*O: A,direct *ove direct byte to A--.
( )
*O: A,SRi *ove indirect RA* to A--. ) )
*O: A,Tdata *ove immediate data to A--. ( )
*O: Rn,A *ove A-- to register. ) )
*O: Rn,direct *ove direct byte to register. ( (
*O: Rn,Tdata *ove immediate data to register. ( )
*O: direct,A *ove A-- to direct byte. ( )
*O: direct,Rn *ove register to direct byte. ( (
*O: direct,direct *ove direct byte to direct byte. 5 (
*O: direct,SRi *ove indirect RA* to direct byte. ( (
*O: direct,Tdata *ove immediate data to direct byte. 5 (
*O: SRi,A *ove A-- to indirect RA*. ) )
*O: SRi,direct *ove direct byte to indirect RA*. ( (
*O: SRi,Tdata *ove immediate data to indirect RA*. ( )
*O: =1#R,Tdata)3 *ove immediate )3 bit data to data pointer register. 5 (
*O:- A,SAM=1#R *ove code byte relative to =1#R to A-- )3 bit
address!. ) (
*O:- A,SAM1- *ove code byte relative to 1- to A-- )3 bit address!.) (
42
*O:P A,SRi *ove e%ternal RA* to A-- + bit address!. ) (
*O:P A,S=1#R *ove e%ternal RA* to A-- )3 bit address!. ) (
*O:P SRi,A *ove A-- to e%ternal RA* + bit address!. ) (
*O:P S=1#R,A *ove A-- to e%ternal RA* )3 bit address!. ) (
1A8C direct 1ush direct byte onto stack. ( (
1O1 direct 1op direct byte from stack. ( (
P-C A,Rn 2%change register with A--. ) )
P-C A,direct 2%change direct byte with A--. ( )
P-C A,SRi 2%change indirect RA* with A--. ) )
P-C= A,SRi 2%change low order nibble of indirect
RA* with low order nibble of A-- ) )
0oolean :ariable *anipulation
*nemonic =escription 8i>e -ycles
-;R - -lear carry flag. ) )
-;R bit -lear direct bit. ( )
82#0 - 8et carry flag. ) )
82#0 bit8et direct bit ( )
-1; - -ompliment carry flag. ) )
-1; bit -ompliment direct bit. ( )
A?; -,bit A?= direct bit to carry flag. ( (
A?; -,&bit A?= compliment of direct bit to carry. ( (
OR; -,bit OR direct bit to carry flag. ( (
OR; -,&bit OR compliment of direct bit to carry. ( (
*O: -,bit *ove direct bit to carry flag. ( )
*O: bit,- *ove carry to direct bit. ( (
43
O- rel Oump if carry is set. ( (
O?- rel Oump if carry is not set. ( (
O0 bit,rel Oump if direct bit is set. 5 (
O?0 bit,rel Oump if direct bit is not set. 5 (
O0- bit,rel Oump if direct bit is set Q clear bit. 5 (
r!-ra. )ra$#h'$-
*nemonic =escription 8i>e
-ycles
A-A;; addr)) Absolute subroutine call. ( (
;-A;; addr)3 ;ong subroutine call. 5 (
R2# Return from subroutine. ) (
R2#$ Return from interrupt. ) (
AO*1 addr)) Absolute jump. ( (
;O*1 addr)3 ;ong jump. 5 (
8O*1 rel 8hort jump relative address!. ( (
O*1 SAM=1#R Oump indirect relative to the =1#R. ) (
ON rel Oump relative if A-- is >ero. ( (
O?N rel Oump relative if A-- is not >ero. ( (
-O?2 A,direct,rel -ompare direct byte to A-- and jump if not e"ual. 5 (
-O?2 A,Tdata,rel -ompare immediate byte to A-- and jump if not e"ual.5 (
-O?2 Rn,Tdata,rel -ompare immediate byte to register and jump if not e"ual.5(
-O?2 SRi,Tdata,rel -ompare immediate byte to indirect and jump if not e"ual.5(
=O?N Rn,rel =ecrement register and jump if not >ero. ( (
=O?N direct,rel =ecrement direct byte and jump if not >ero. 5 (
44
#he RW line is the VRead&6riteV control line. 6hen R6 is low .!, the information
on
Chapter:@ HOW TO ROGRAM )LANK CHI.
3562 .'#r! #!$tr!**er
The 3562
#he +./( developed and launched in the early +.Is, is one of the most popular micro
controller in use today. $t has a reasonably large amount of built in RO* and RA*.
$n addition it has the ability to access e%ternal memory.
#he generic term I+%/(I is used to define the device. #he value of % defining the kind
of RO*, i.e. %J., indicates none, %J5, indicates mask RO*, %J<, indicates 21RO*
and %J, indicates 221RO* or 'lash.
D'//ere$t .'#r! #!$tr!**er% '$ .ar+et.
1$- One of the famous microcontrollers used in the industries. $t is
based on R$8- Architecture which makes the microcontroller process faster
than other microcontroller.
45
$?#2; #hese are the first to manufacture microcontrollers. #hese are
not as sophisticated other microcontrollers but still the easiest one to learn.
A#*2; AtmelDs A:R microcontrollers are one of the most powerful in
the embedded industry. #his is the only microcontroller having )kb of ram even
the entry stage. 0ut it is unfortunate that in $ndia we are unable to find this kind
of microcontroller.
I$te* 3562
$ntel +./( is -$8- architecture which is easy to program in assembly language and
also has a good support for Cigh level languages.
#he memory of the microcontroller can be e%tended up to 39k.
#his microcontroller is one of the easiest microcontrollers to learn.
#he +./( microcontroller is in the field for more than (. years. #here are lots of
books and study materials are readily available for +./(.
First of all we select and open the assembler and wrote a pro2ram
code in the file! %fter wrote a software we assemble the software by
3sin2 internal assembler of the 8.5/ editor! If there is no error then
assembler assemble the software abd . error is show the o3tp3t
window!
46
'ig. 3.)
?ow assembler generate a A8* file and C2P file. #his he% file is useful for us to
program the blank chip.
?ow we transfer the he% code into the blank chip with the help of serial programmer
kit. $n the programmer we insert a blank chip .f +,s/) series . these chips are multi R
time programmable chip. #his programming kit is separately available in the market
and we transfer the he% code into blank chip with the help of the serial programmer
kit
47
'ig. 3.(
'ig. 3.5
48
'ig. 3.9
49
Appendix 1
r!-ra. #!,e

TincludeVreg/(.hV
&&lcd
Tdefine ;-==A#A 1(
sbit R8J1)W.; &&;-= Register &8elect
sbit 2?J1)W); &&;-= 2nable
&&sensor
sbit sensorX) J 15W(;
sbit sensorX( J 15W5;
sbit sensorX5 J 15W9;
sbit sensorX9 J 15W/;
&&break key
sbit keyX) J 1)W(;
sbit keyX( J 1)W5;
sbit keyX5 J 1)W9;
sbit keyX9 J 1)W/;
sbit stopXrf J 15W3;
sbit bu>>er J 1)W3;
typedef unsigned int ui;
typedef unsigned char uc;
typedef unsigned long ul;
void displaylinechar4 ptr,int line!;
void sendXbitsint i,uc com!;
50
void delayui t!,lcdinit!;
uc timecountJ.,trainXstopYZJ[.,.,.,.,.\;
uc phnoY))ZJ[,,<,),<,+,),+,.,5,,\,i;
bit bu>>erXflagJ.;
void systeminit!,gsmXmoduleXinit!;
void sendXserXcomuc 4ptr!,putcint i!;
void messageXsendint i!;
void main!
[ systeminit!;stopXrfJ.;
while)!
[ ifkeyX)!bu>>erXflagJ),trainXstopY)ZJ);
ifkeyX(!bu>>erXflagJ),trainXstopY(ZJ);
ifkeyX5!bu>>erXflagJ),trainXstopY5ZJ);
ifkeyX9!bu>>erXflagJ),trainXstopY9ZJ);
else
[ bu>>erJ);bu>>erXflagJ.;trainXstopY)ZJ.;
trainXstopY(ZJ.;trainXstopY5ZJ.;
trainXstopY9ZJ.;stopXrfJ.;&&train run
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
ifsensorX)JJ.!
[ displaylineV ?26 =2;C$ V,)!;
displaylineV RA$;6AB8#A#$O? V,(!;
stopXrfJ);&&train stop
iftrainXstopY)ZJJ)!
[ displaylineVA;2R#-#R2-L 0RAL2V,)!;
displaylineV?26 =2;C$J&JLO#A V,(!;
bu>>erJ.;stopXrfJ);messageXsend)!;
\
51
whilekeyX)JJ)!delay)...!;stopXrfJ.;
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
else ifsensorX(JJ.!
[ displaylineV LO#A V,)!;
displaylineV RA$;6AB8#A#$O? V,(!;
stopXrfJ);&&train stop
iftrainXstopY(ZJJ)!
[ displaylineVA;2R#-#R2-L 0RAL2V,)!;
displaylineVLO#A J&J :A=O=RA V,(!;
bu>>erJ.;stopXrfJ);messageXsend(!;
\
whilekeyX(JJ)!delay)...!;stopXrfJ.;
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
else ifsensorX5JJ.!
[ displaylineV :A=O=RA V,)!;
displaylineV RA$;6AB8#A#$O? V,(!;
stopXrfJ);&&train stop
iftrainXstopY5ZJJ)!
[ displaylineVA;2R#-#R2-L 0RAL2V,)!;
displaylineV:A=O=RAJ&J *A*0A$V,(!;
bu>>erJ.;stopXrfJ);messageXsend5!;
\
whilekeyX5JJ)!delay)...!;stopXrfJ.;
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
52
else ifsensorX9JJ.!
[ displaylineV *A*0A$ V,)!;
displaylineV RA$;6AB8#A#$O? V,(!;
stopXrfJ);&&train stop
iftrainXstopY9ZJJ)!
[ displaylineVA;2R#-#R2-L 0RAL2V,)!;
displaylineV*A*0A$ J&J =2;C$ V,(!;
bu>>erJ.;stopXrfJ);messageXsend9!;
\
whilekeyX9JJ)!delay)...!;stopXrfJ.;
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
\
\
void messageXsendint k!
[ sendXserXcomVatMcmgsJV!;&&8end 8*8
putc]V]!;putc]M]!;putc],]!;putc])]!;
foriJ.;iU).;iMM!putcphnoYiZ!;putc]V]!;
ifkJJ.!
sendXserXcomV ok testing V!;
ifkJJ)!
sendXserXcomVA;2R#-#R2-L 0RAL2 ?26 =2;C$J&JLO#A V!;
ifkJJ(!
sendXserXcomVA;2R#-#R2-L 0RAL2 LO#A J&J :A=O=RA V!;
ifkJJ5!
sendXserXcomVA;2R#-#R2-L 0RAL2 :A=O=RAJ&J *A*0A$ V!;
ifkJJ9!
sendXserXcomVA;2R#-#R2-L 0RAL2 *A*0A$ J&J =2;C$ V!;
putc(3!;
53
\
void systeminit!
[ 1.J.P'';1)J.P'';1(J.P'';15J.P'';
$2 J .P,(;&&enable timer. and serial interrupt
#C) J .%fd;&&setting baud rate ,3..
#C.J.P+a;#;.J.Pa(;#R)J);#R.J);
lcdinit!;gsmXmoduleXinit!;
\
void timer.isr!interrupt ) using (
[ ifbu>>erXflag!
[ if--timecount JJ .!
[ ifbu>>er!bu>>erJ.,timecountJ9.;
else bu>>erJ),timecountJ/;
\
\
else
bu>>erJ);
\
void putcint i!
[ 80A'Ji;
\
void sendXserXcomuc 4ptr !
[ while4ptr!
[ 80A'J4ptr;
\
\
void gsmXmoduleXinit!
[ displaylineV 1;2A82 6A$# V,)!;
displaylineV $nitiali>ing V,(!;
sendXserXcomVat^rV!;delay3....!;
54
sendXserXcomVate)^rV!;delay3....!;
messageXsend.!;&&ok testing
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
void displaylinechar4 ptr,int line!
[ iflineJJ)!sendXbits.,.%+.!;
iflineJJ(!sendXbits.,.%c.!;
sendXbits),4ptr!,ptrMM;
\
void sendXbitsint i,uc com!
[ ;-==A#A J com;
R8Ji;2?J);delay).!;2?J.;
delay)..!;
\
void delayui t!
[ while--t!;
\
void lcdinit!
[ sendXbits.,.%5+!;delay)..!;&& initiali>ation of )3P( ;-= in +bit mode
sendXbits.,.%.)!;delay)..!;&& clear ;-=
displaylineV RAO=CA?$ 2P1. V,)!;
displaylineV -O?#RO; 8B8#2* V,(!;
\
55
REFRENCES
1. Arun.P, Saritha.S, K.M.Martin, Madhukumar.S Simula tion of zigbee based
TACS for collision detection and avoidance for railway traffic., in
International conference on advanced computing & communication
technologies for high performance application, paper ID 51,June 2012.
2. www.howstuffworks.com
3. www.alldatasheets.com
4. D.Roychoudhary and Sail JainL.I.C, New Age International.
5. Kenneth.J.AyalaThe 89C51 Microcontroller Architect ure programming and
Applications, Pen ram International.
6. Principles of Electronics by V.K.MEHTA.

Você também pode gostar