Sei sulla pagina 1di 64

CHAPTER 1

INTRODUCTION

Now a days, in our daily life most of the accidents occur due to rash driving
on highways which may lead to the loss of many passengers and drivers have lost their lives
rash driving on highways, Therefore to overcome this problem, the following project
implements a speed checker to detect rash driving on highways.

The main object of this system to develop a highway speed checker device that detects rash
driving on highways and alerts the traffic authorities if the speed checker finds any vehicle
violating the speed limit on high ways.

In olden days for detecting rash driving on highways the police used to target vehicle by
using radar guns as the vehicle and it would record their speed. If a vehicle would exceeds
its speed, automatically information would reach to the nearby police station for controlling
the speed of the vehicle due to this system a lot of time would be wasted. But in our project,
the proposed system checks rash driving by calculating the speed of vehicle by using the
time taken to travel between the two set points placed on the road at a certain distance. A set
point distance consists of a couple of sensors comprising an IR Transmitter and IR Receiver.
Which are placed on the either side of the road. The speed limit is set by the police who use
the system depending on the traffic at each location.

The time taken by the vehicle to travel from one set point to the other is calculated by the
control circuit calculates the speed and displays the result on a 16*2-bit LCD display. If a
vehicle exceeds the limit between transmitter and receiver, then system sends a message to
the traffic authorities for further action.

1
CHAPTER 2

SPEED CHECKER TO DETECT RASH DRIVING ON


HIGHWAYS

2.1 Introduction:

The aim of this project is to develop a device to detect rash driving on highways and
to alert the traffic authorities in case of any speed violation. Accidents due to rash driving on
highways are on the rise and people are losing their lives because of others mistakes.

2.2 Block diagram:

LCD DISPLAY
RECTIFI
ER

IR
TRANS
MITTER
RFID

IR MICRO
RECEIV CONTRO
ER LLER
GSM
MODEM

Asm/C

Figure 2.1: Block diagram of speed checker to detect rash driving on highways

2
From the block diagram the components used in this project are Micro controller,
Transformer, Bridge rectifier, RFID (Radio frequency identity), Global System for Mobile
communication (GSM) module, LCD (Liquid Crystal Diode) Display, Infrared Transmitter,
Infrared Receiver and also KEIL micro vision-4 software for programming to micro
controller either C-program or Assembly program.

2.3 Main circuit diagram:

Figure 2.2: Circuit Diagram Of Speed Checker To Detect Rash Driving On Highways

Fig.2.2 shows that the detailed connections of all components, In this a step-down
3
transformer (230v/5v) output is connected as input of bridge rectifier. Then bridge rectifier
is converts the AC into DC and given it to the input of microcontroller circuit.
Controller circuit consists of IR sensors i.e, transmitter and receiver with a fixed
distance are consider as two set points to sense the vehicle moment from start to end. Then
the microcontroller calculating the speed of vehicle by using the time taken to travel
between the two set points placed on the road at that fixed distance. The speed limit is set by
the police who use the system depending on the traffic at each location. The controller sends
one signal to LCD to display the speed crosses or not and another to RFID and GSM. If the
vehicle crosses the speed limit then controller collect the data from RFID which is already
stored in it, and sends a message with that vehicle data to the traffic inspector mobile no
through GSM module for future action.

4
CHAPTER 3

HARDWARE REQUIREMENT

3.1 Hardware Components used in this project are:


The given followings are the components which are used in the project of speed checker to
detect rash driving on highways.

AT89s52 Microcontroller.

RFID (radio frequency identity)

GSM (global system for mobile communication)

IR Sensors

LCD display

Power supply circuit

3.2 Brief data of components:

3.2.1 AT89s52 Microcontroller


Microprocessors and microcontrollers are widely used in embedded systems
products. Microcontroller is a programmable device. A microcontroller has a CPU in
addition to a fixed amount of RAM, ROM, I/O ports and a timer embedded all on a single
chip. The fixed amount of on-chip ROM, RAM and number of I/O ports in microcontrollers
makes them ideal for many applications in which cost and space are critical.

The Intel 8051 is Harvard architecture, single chip microcontroller (C) which was
developed by Intel in 1980 for use in embedded systems. It was popular in the 1980s and
early 1990s, but today it has largely been superseded by a vast range of enhanced devices
with 8051-compatible processor cores that are manufactured by more than 20 independent
manufacturers including Atmel, Infineon Technologies and Maxim Integrated Products.

5
8051 is an 8-bit processor, meaning that the CPU can work on only 8 bits of data at a
time. Data larger than 8 bits has to be broken into 8-bit pieces to be processed by the CPU.
8051 is available in different memory types such as UV-EPROM, Flash and NV-RAM.

The present project is implemented on Keil Uvision. In order to program the device,
Pro load tool has been used to burn
the program onto the
microcontroller.

The features, pin


description of the microcontroller
and the software tools used
are discussed in the following
sections.

6
Figure 3.1: Pin Diagram Of Microcontroller

3.2.2 FEATURES OF AT89s52

8K Bytes of Re-programmable Flash Memory.

RAM is 256 bytes.

4.0V to 5.5V Operating Range.

Fully Static Operation: 0 Hz to 33 MHzs

Three-level Program Memory Lock.

256 x 8-bit Internal RAM.

32 Programmable I/O Lines.

Three 16-bit Timer/Counters.

Eight Interrupt Sources.

Full Duplex UART Serial Channel.

Low-power Idle and Power-down Modes.

Interrupt recovery from power down mode.

Watchdog timer.

Dual data pointer.

Power-off flag.

Fast programming time.

Flexible ISP programming (byte and page mode).

7
3.2.3 Description:

The AT89s52 is a low-voltage, high-performance CMOS 8-bit microcomputer with 8K bytes


of Flash programmable memory. The device is manufactured using Atmels high density
nonvolatile memory technology and is compatible with the industry-standard MCS-51
instruction set. The on chip flash allows the program memory to be reprogrammed in system
or by a conventional non-volatile memory programmer. By combining a versatile 8-bit CPU
with Flash on a monolithic chip, the Atmel AT89s52 is a powerful microcomputer, which
provides a highly flexible and cost-effective solution to many embedded control
applications.

8
In addition, the AT89s52 is designed with static logic for operation down to zero
frequency and supports two software selectable power saving modes. The Idle Mode stops
the CPU while allowing the RAM, timer/counters, serial port and interrupt system to
continue functioning. The power-down mode saves the RAM contents but freezes the
oscillator disabling all other chip functions until the next hardware reset.

3.2.4 Block diagram:

Figure 3.2: Block Diagram Of Microcontroller

9
3.2.5 Pin description:

A. Vcc : Pin 40 provides supply voltage to the chip. The voltage source is +5V.

B. GND : Pin 20 is the ground.

C. Port 0 :

Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin
can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as
high impedance inputs. Port 0 can also be configured to be the multiplexed low-order
address/data bus during accesses to external program and data memory. In this mode,
P0 has internal pull-ups.

Port 0 also receives the code bytes during Flash programming and outputs the
code bytes during Program verification. External pull-ups are required during
program verification.

D. Port 1:

Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1
output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins,
they are pulled high by the internal pull-ups and can be used as inputs. As inputs,
Port 1 pins that are externally being pulled low will source current (IIL) because of
the internal pull-ups. In addition, P1.0 and P1.1 can be configured to be the
timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input
(P1.1/T2EX), respectively, as shown in the following table. Port 1 also receives the
low-order address bytes during Flash programming and verification.
Table 3.1: 8051 Microcontroller Port 1 Specifications

10
E. Port 2:

Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2
output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins,
they are pulled high by the internal pull-ups and can be used as inputs. As inputs,
Port 2 pins that are externally being pulled low will source current (IIL) because of
the internal pull-ups.

Port 2 emits the high-order address byte during fetches from external
program memory and during accesses to external data memory that uses 16-bit
addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups
when emitting 1s. During accesses to external data memory that uses 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. The
port also receives the high-order address bits and some control signals during Flash
programming and verification.

F. Port 3:

Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3
output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins,
they are pulled high by the internal pull-ups and can be used as inputs. As inputs,
Port 3 pins that are externally being pulled low will source current (IIL) because of
the pull-ups. Port 3 receives some control signals for Flash programming and
verification.

Port 3 also serves the functions of various special features of the AT89S52, as
shown in the following table.
Table 3.2: 8051 Microcontroller Port 3 Specifications

11
G. RST:

Reset input. A high on this pin for two machine cycles while the oscillator is
running resets the device. This pin drives high for 98 oscillator periods after the
Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to
disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature
is enabled.

H. ALE/PROG:

Address Latch Enable (ALE) is an output pulse for latching the low byte of
the address during accesses to external memory. This pin is also the program pulse
input (PROG) during Flash programming.

In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator


frequency and may be used for external timing or clocking purposes. Note, however,
that one ALE pulse is skipped during each access to external data memory.

If desired, ALE operation can be disabled by setting bit 0 of SFR location


8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction.
Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if
the microcontroller is in external execution mode.

I. PSEN:

Program Store Enable (PSEN) is the read strobe to external program memory.
When the AT89S52 is executing code from external program memory, PSEN is
activated twice each machine cycle, except that two PSEN activations are skipped
during each access to external data memory.

J. EA/VPP:

External Access Enable. EA must be strapped to GND in order to enable the


device to fetch code from external program memory locations starting at 0000H up
to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally
latched on reset.

EA should be strapped to VCC for internal program executions. This pin also
receives the 12-volt programming enable voltage (VPP) during Flash programming.
12
K. XTAL1:

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

L. XTAL2:

Output from the inverting oscillator amplifier.

M. Oscillator Connections:

Figure: 3.3 Circuit Diagram Of Oscillator Connections

C1, C2 = 30 pF 10 pF for Crystals

= 40 pF 10 pF for Ceramic Resonators

N. External Clock Drive Configuration:

Figure: 3.4 Clock circuit

XTAL1 and
XTAL2 are the input
and output,
respectively, of an inverting amplifier that can be configured for use as an
on-chip oscillator. Either a quartz crystal or ceramic resonator may be used. To drive
the device from an external clock source, XTAL2 should be left unconnected while

13
XTAL1 is driven. There are no requirements on the duty cycle of the external clock
signal, since the input to the internal clocking circuitry is through a divide-by-two
flip-flop, but minimum and maximum voltage high and low time specifications must
be observed.

O. Special Function Registers:

A map of the on-chip memory area called the Special Function Register
(SFR) space is shown in the following table.

It should be noted that not all of the addresses are occupied and unoccupied
addresses may not be implemented on the chip. Read accesses to these addresses will
in general return random data, and write accesses will have an indeterminate effect.

User software should not write 1s to these unlisted locations, since they may
be used in future products to invoke new features. In that case, the reset or inactive
values of the new bits will always be 0.

Timer 2 Registers:

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

P. Interrupt Registers:

The individual interrupt enable bits are in the IE register. Two priorities can be set for
each of the six interrupt sources in the IP register.

Table 3.3: AT89S52 SFR Map And Reset Values

14
Table 3.4: T2CON Timer/Counter 2 Control Register

15
Table 3.5: Auxiliary Register

Q. Dual Data Pointer Registers:

To facilitate accessing both internal and external data memory, two banks of
16-bit Data Pointer Registers are provided: DP0 at SFR address locations 82H-83H
and DP1 at 84H and 85H. Bit DPS = 0 in SFR AUXR1 selects DP0 and DPS = 1
selects DP1. The user should ALWAYS initialize the DPS bit to the appropriate value
before accessing the respective Data Pointer Register.

16
Table 3.6: Auxilary Register I

R. Power Off Flag:

The Power OFF Flag (POF) is located at bit 4 (PCON.4) in the PCON SFR.
POF is set to 1 during power up. It can be set and rest under software control and
is not affected by reset.

S. Memory Organization:

MCS-51 devices have a separate address space for Program and Data
Memory. Up to 64K bytes each of external Program and Data Memory can be
addressed.

T. Program Memory:

If the EA pin is connected to GND, all program fetches are directed to


external memory. On the AT89S52, if EA is connected to VCC, program fetches to
addresses 0000H through 1FFFH are directed to internal memory and fetches to
addresses 2000H through FFFFH are to external memory.

U. Data Memory:

The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes
occupy a parallel address space to the Special Function Registers. This means that
the upper 128 bytes have the same addresses as the SFR space but are physically
separate from SFR space.

17
3.3 Radio Frequency Identification (RFID):

Figure: 3.5 Radio Frequency Identification

3.3.1 Features of RFID:

RFID technology provides many benefits for organisations to use the system. RFID
provide an easy way in which data can be collected and assets tracked:
RFID technology provides a low cost form of data collection and asset management.
RFID technology is widely used and therefore the economies of scale can be utilised
to advantage.
RFID technology enables data collection in environments that are unsuitable for
workers as RFID tags can provide data in harsh environments.
RFID is able to provide many reads and write functions per second, although it is not
a very high data rate system, it is sufficient for most data monitoring applications.
Data on an RFID tag can be altered repeatedly.
RFID technology can be used with existing systems including bar codes and Wi-Fi
As a result, RFID technology is being used increasingly as organizations need
automatic methods of tracking assets and collecting data.
RFID technology can be used with existing systems including bar codes and Wi-Fi.
In this project we are using RFID to know the details of particular vehicle . Initially
the vehicle information is stored in RFID when a vehicle moves from IR transmitter

18
and receiver pair the speed is sensed and the information is send to controller unit
and RFID
When the speed exceeds the rated speed than RFID sends the information to GSM
modem.

3.4 Global System for Mobile Communication (GSM) :

Definition:
GSM, which stands for Global System for Mobile communications, reigns
(important) as the worlds most widely used cell phone technology. Cell phones use a cell
phone service carriers GSM network by searching for cell phone towers in the nearby area.
Global system for mobile communication (GSM) is a globally accepted standard for digital
cellular communication.

GSM is the name of a standardization group established in 1982 to create a


common European mobile telephone standard that would formulate specifications for a pan-
European mobile cellular radio system operating at 900 MHz. It is estimated that many
countries outside of Europe will join the GSM partnership.

Need of GSM:
The GSM study group aimed to provide the followings through the GSM:
Improved spectrum efficiency.
International roaming.
Low-cost mobile sets and base stations (BS)
High-quality speech
Compatibility with Integrated Services Digital Network (ISDN) and other telephone
company services.
19
Support for new services.

GSM Brief History:


Following table shows many of the important events in the rollout of the
GSM system; other events were introduced, but had less significant impact on the overall
systems.

Years Events

CEPT establishes a GSM group in order to develop the standards for a pan-
1982
European cellular mobile system.

1985 A list of recommendations to be generated by the group is accepted.

Field tests are performed to test the different radio techniques proposed for the
1986
air interface.

Time Division Multiple Access (TDMA) is chosen as the access method (with
Frequency Division Multiple Access [FDMA]). The initial Memorandum of
1987
Understanding (MoU) is signed by telecommunication operators representing 12
countries.

1988 GSM system is validated.

The responsibility of the GSM specifications is passed to the European


1989
Telecommunications Standards Institute (ETSI).

1990 Phase 1 of the GSM specifications is delivered.

Commercial launch of the GSM service occurs. The DCS1800 specifications


1991
are finalized.

The addition of the countries that signed the GSM Memorandum of


1992
Understanding takes place. Coverage spreads to larger cities and airports.

1993 Coverage of main roads' GSM services starts outside Europe.

Data transmission capabilities launched. The number of networks raises to 69


1994
in 43 countries by the end of 1994.

1995 Phase 2 of the GSM specifications occurs. Coverage is extended to rural areas.

1996 June: 133 network in 81 countries operational.

1997 July: 200 network in 109 countries operational, around 44 million subscribers

20
worldwide.

Wireless Application Protocol came into existence and 130 countries


1999
operational with 260 million subscribers

2000 General Packet Radio Service (GPRS) came into existence.

As of May 2001, over 550 million people were subscribers to mobile


2001
telecommunications

The GSM Specifications:


Specifications for different Personal Communication Services (PCS) systems
vary among the different PCS networks. The GSM specification is listed below with
important characteristics.

Modulation:
Modulation is a form of change process where we change the input information
into a suitable format for the transmission medium. We also changed the information by
demodulating the signal at the receiving end.
The GSM uses Gaussian Minimum Shift Keying (GMSK) modulation method.

Access Methods:
Because radio spectrum is a limited resource shared by all users, a method must
be devised to divide up the bandwidth among as many users as possible.
GSM chose a combination of TDMA/FDMA as its method. The FDMA part
involves the division by frequency of the total 25 MHz bandwidth into 124 carrier
frequencies of 200 kHz bandwidth.
One or more carrier frequencies are then assigned to each BS. Each of these
carrier frequencies is then divided in time, using a TDMA scheme, into eight time slots. One
time slot is used for transmission by the mobile and one for reception. They are separated in
time so that the mobile unit does not receive and transmit at the same time.

Transmission Rate:
The total symbol rate for GSM at 1 bit per symbol in GMSK produces 270.833 K
symbols/second. The gross transmission rate of the time slot is 22.8 Kbps.
GSM is a digital system with an over-the-air bit rate of 270 kbps.
21
Frequency Band:
The uplink frequency range specified for GSM is 933 - 960 MHz (basic 900
MHz band only). The downlink frequency band 890 - 915 MHz (basic 900 MHz band only).

Channel Spacing:
This indicates separation between adjacent carrier frequencies. In GSM, this is 200
kHz.

Speech Coding:
GSM uses linear predictive coding (LPC). The purpose of LPC is to reduce the
bit rate. The LPC provides parameters for a filter that mimics the vocal tract. The signal
passes through this filter, leaving behind a residual signal. Speech is encoded at 13 kbps.

Duplex Distance:
The duplex distance is 80 MHz. Duplex distance is the distance between the
uplink and downlink frequencies. A channel has two frequencies, 80 MHz apart.

Misc:
Frame duration: 4.615 ms
Duplex Technique: Frequency Division Duplexing (FDD) access mode previously
known as WCDMA.
Speech channels per RF channel: 8.

Send SMS using AT commands:


Some advanced GSM modems like Wave Com and Multi-tech, support the SMS text mode.
This mode allows you to send SMS messages using AT commands, without the need to
encode the binary PDU field of the SMS first. This is done by the GSM modem

Check if your GSM phone or modem supports SMS text mode:


To check if your modem supports this text mode, you can try the following command:

AT+CMGF=1 <ENTER>

22
If the modem responds with "OK" this mode is supported. Please note that using this mode it
is only possible to send simple text messages. It is not possible to send multipart, Unicode,
data and other types of messages.

Setting up the modem


If the modem contains a SIM card with is secured with a PIN code, we have to enter this
pin code first:

AT+CPIN="0000" <ENTER> (replace 0000 with your PIN code).


Please not that in most cases you have only 3 attempts to set the correct PIN code. After
setting the PIN code, wait some seconds before issuing the next command to give the
modem some time to register with the GSM network.
In order to send a SMS, the modem has to be put in SMS text mode first using the following
command:

AT+CMGF=1<ENTER>
In text mode there are some additional parameters that can be set.
Using the following command we can read the current values:

AT+CSMP?<ENTER>
The modem will response with a string like this:

+CSMP: 1, 169, 0, 0 <OK>


To send a message with a validity period of 1 day, the parameters have to be set like this:
Bit 0 and 4 of the first field has to be set, so the first value will become 1 + 16 = 17.
Send the following command to the modem to set this parameters.

AT+CSMP=17, 167, 0, 16 <ENTER>


If the modem responds with "OK" the modem is ready to send (flash) text messages with
a validity period of 1 day.
Sending the message
To send the SMS message, type the following command.

AT+CMGS="+31638740161" <ENTER>
23
Replace the above phone number with your own cell phone number. The modem will
respond with.
You can now type the message text and send the message using the <CTRL>-<Z> key
combination.

Hello World! <CTRL-Z>


After some seconds the modem will respond with the message ID of the message,
indicating that the message was sent correctly.
+CMGS: 62
The message will arrive on the mobile phone shortly.

Sending an Unicode SMS message


Some modems also have the capability to send Unicode or UCS2 messages without
encoding a PDU.
You can send Unicode messages by only converting the Unicode data to a HEX string
and send this string to the modem.
To check whether your modem supports this mode, just type the following command.

AT+CSCS=?
This commands displays the code pages supported by the modem. The modem will respond
like this.
+CSCS: ("GSM","PCCP437","CUSTOM","HEX")
If this string contains "HEX" or "UCS2", Unicode seems to be supported.
To specify that you will use an HEX string to send the message, set the code page
to"HEX" or "UCS2" depending on the modem response In our example we will set the
modem to "HEX".

AT+CSCS="HEX" <ENTER>

Next, we have to specify the correct DCS (Data Coding Scheme) for Unicode messages,
which is 0x08. We can set this value by changing the fourth parameter of the AT+CSMP
command to '8'.

24
AT+CSMP=1, 167, 0, 8 <ENTER>
The modem is now ready to send messages as Unicode. Now is the time to send the
actual message.

AT+CMGS="+31638740161" <ENTER>
Replace the above phone number with your own cell phone number. The modem will
respond with.
The only thing you have to program by yourself, is a simple routine which converts the
Unicode string to a hexadecimal string like this.
Which is 'Hello' in Arabic will be converted like this:
"06450631062D06280627"

You can send this hexadecimal string to the modem:


06450631062D06280627 <CTRL-Z>
after some seconds the modem will respond with the message ID of the message, indicating
that the message was sent correctly:

+CMGS: 63
The message will arrive on the mobile phone shortly.

3.5 IR Sensors:

3.5.1 Infrared transmitter


Features 880 nm
Nine standard packages in hermetic and low-cost epoxy
End- and side-radiating packages

25
Graded Output
High efficiency GaAIAs, 880 nm LPE process delivers twice the power of
Conventional GaAs 940 nm emitters
Infrared (IR) radiation is electromagnetic radiation whose wavelength is longer
than that of visible light (400-700 nm), but shorter than that of terahertz radiation (100 m -
1 mm) and microwaves (~30,000 m). Infrared radiation spans roughly three orders of
magnitude (750 nm and 100 m).

Direct sunlight has a luminous efficacy of about 93 lumens per watt of radiant
flux, which includes infrared (47% share of the spectrum), visible (46%), and ultra-violet
(only 6%) light. Bright sunlight provides luminance of approximately 100,000 candela per
square meter at the Earth's surface.

Overview
Infrared imaging is used extensively for both military and civilian purposes. Military
applications include target acquisition, surveillance, night vision, homing and tracking. Non-
military uses include thermal efficiency analysis, remote temperature sensing, short-ranged
wireless communication, spectroscopy, and weather forecasting.. Infrared astronomy uses
sensor-equipped telescopes to penetrate dusty regions of space, such as molecular clouds;
detect cool objects such as planets, and to view highly red-shifted objects from the early
days of the universe.

At the atomic level, infrared energy elicits vibration modes in a molecule through a change
in the dipole moment, making it a useful frequency range for study of these energy states for
molecules of the proper symmetry. Infrared spectroscopy examines absorption and
transmission of photons in the infrared energy range, based on their frequency and intensity.

Origins of the term


The name means below red (from the Latin infra, "below"), red being the color of the
longest wavelengths of visible light. IR light has a longer wavelength (a lower frequency)
than that of red light, hence below.

Different regions in the infrared


Objects generally emit infrared radiation across a spectrum of wavelengths, but only a
specific region of the spectrum is of interest because sensors are usually designed only to
26
collect radiation within a specific bandwidth. As a result, the infrared band is often
subdivided into smaller sections.

Figure: 3.6 IR Transmitter


An infrared emitter is an LED made from gallium arsenide, which emits near-
infrared energy at about 880nm. The infrared phototransistor acts as a transistor with the
base voltage determined by the amount of light hitting the transistor. Hence it acts as a
variable current source. Greater amount of IR light cause greater currents to flow through
the collector-emitter leads. As shown in the diagram below, the phototransistor is wired in a
similar configuration to the voltage divider. The variable current traveling through the
resistor causes a voltage drop in the pull-up resistor. This voltage is measured as the output
of the device

27
Figure:3.7 Circuit Diagram Of Emitter And Photo Diode

Figure 3.8: Circuit Diagram Of A Infrared Reflectance Sensor

Photo IR reflectance sensors contain a matched infrared transmitter and infrared receiver
pair. These devices work by measuring the amount of light that is reflected into the receiver.
Because the receiver also responds to ambient light, the device works best when well
shielded from ambient light, and when the distance between the sensor and the reflective
surface is small(less than 5mm). IR reflectance sensors are often used to detect white and

28
black surfaces. White surfaces generally reflect well, while black surfaces reflect poorly.

Figure: 3.9 Infrared Emitter Detector Circuit

How Infrared Trans Rex detectors work?

Fig.3.10 Schematic Diagram for a Single Pair of Infrared Transmitter and Receiver

29
Fig.3.11. Internal Diagram For A Single Pair Of Infrared Transmitter And Receiver
Theory of Sensor Circuit

Figure: 3.12 Schematic Diagram Of A Single Sensor

30
= a/ (a+R1)-b/ (b+R1)
Description of operation of a typical circuit

If the emitter and detector (aka phototransistor) are not blocked, then the output on pin 2 of

31
the 74LS14 will be high (apx. 5 Volts). When they are blocked, then the output will be low
(apx. 0 Volts). The 74LS14 is a Schmitt triggered hex inverter.
A Schmitt trigger is a signal conditioner. It ensures that above a threshold value, we will
always get "clean" HIGH and LOW signals. Not Blocked Case: Pin 2 High Current from
Vcc flows through the detector. The current continues to flow through the base of Q2.
Current from Vcc also flows through R2, and Q2's Drain and Emitter to ground. As a result
of this current path, there will be no current flowing through Q1's base. The signal at U1's
pin 1 will be low, and so pin 2 will be high. Blocked Case: Pin 2 Low Current "stops" at the
detector. Q2's base is not turned on. The current is re-routed passing through R2 and into the
base of Q1. This allows current to flow from Q1's detector and exiting out Q1's emitter. Pin
1 is thus high and pin 2 will be low. To detect a line to be followed, we are using two or
more number of poto-reflectors. Its output current that proportional to reflection rate of the
floor is converted to voltage with a resister and tested it if the line is detected or not.
However the threshold voltage cannot be fixed to any level because optical current by
ambient light is added to the output current. Most photo-detecting modules are using
moderated light to avoid interference by the ambient light. The detected signal is filtered
with a band pass filter and disused signals are filtered out.
Therefore only the moderated signal from the light emitter can be detected.
Of course the detector must not be saturated by ambient light, this is effective when the
detector is working in linear region.

32
33
The line position is compared to the center value to be tracked; the position error is
processed with Proportional/Integral/Defense filters to generate steering command. The line
following robot tracks the line in PID control that the most popular algorithm for servo
control. The proportional term is the common process in the servo system. It is only a gain
amplifier without time dependent process. The differential term is applied in order to
improve the response to disturbance, and it also compensate phase lag at the controlled
object. The D term will be required in most case to stabilize tracking motion. The I term that
boosts DC gain is applied in order to remove left offset error, however, it often decrease
servo stability due to its phase lag. When any line sensing error has occurred for a time due
to getting out of line or end of line, the motors are stopped and the microcontroller enters
sleep state of zero power consumption. Typical Examples of infrared Transmitter and
Receiver installation.

3.5.2 IR Receiver
34
Features

Tight production distribution.


Steel lead frames for improved reliability in solder mounting.
Good optical-to-mechanical alignment.
Plastic package is infrared transparent black to attenuate visible light.
Can be used with QECXXX LED, Black plastic body allows easy recognition
from LED.
Phototransistors also consist of a photodiode with internal gain. A phototransistor is in
essence nothing more than a bipolar transistor that is encased in a transparent case so that
light can reach the base-collector junction. The electrons that are generated by photons in the
base-collector junction are injected into the base, and this photodiode current is amplified by
the transistor's current gain. Note that while phototransistors have a higher responsively for
light they are not able to detect low levels of light any better than photodiodes.
Phototransistors also have slower response times. A simple model of a phototransistor,
would be a forward based LED (emitterbase) and a reverse based photodiode (base
collector) sharing an anode (base) in a single package such that 99% (F%) of the light
emitted by the led is absorbed by the photodiode. Each electron-hole recombination in the
LED produces one photon and each photon absorbed by the photodiode produces one
electron-hole pair.

Fig.3.13 Circuit Of Pnp And Npn Diodes


IR Receiver needs to be in line of sight with the transmitter to efficiently transform
light impulses into digital values. The light emitted from the IR LED is modulated with a
lens into a compact beam and then turned and of concerning the message.

3.6 Liquid crystal diode:

35
It is an electronically-modulated optical device shaped into a thin, flat panel made up
of any number of color or monochrome pixels filled with liquid crystals and arrayed in front
of a light source (backlight) or reflector. It is often used in battery-powered electronic
devices because it requires very small amounts of electric power.

3.6.1 Features:

* High contrast LCD supertwist display

* EA dip162-dnled: yellow/green with led backlight

* Incl. HD 44780 or compatible controller

* Interface for 4- and 8-bit data bus

*Power supply +5v or 2.7v or 3.3v

* Operating temperature 0~+50c (-dn3lw, -dhnled, -20~+70c)

* Led backlight y/g MAX. 150Ma@+25c

* Led backlight white MAX. 45Ma@+25c

* Some more modules with same mechanic and same pin out

-Dot matrix 1X8, 4X20

-Graphic 122X32

* No screws required: solder on in PCB only

* Detachable via 9-pin socket EA b200-9 (2 pcs. required)

36
Liquid crystal display is very important device in embedded system. It offers high
flexibility to user as he can display the required data on it. But due to lack of proper
approach to LCD interfacing many of them fail. Many people consider LCD interfacing a
complex job but according to me LCD interfacing is very easy task, you just need to have a
logical approach. This page is to help the enthusiast who wants to interface LCD with
through understanding. Copy and Paste technique may not work when an embedded system
engineer wants to apply LCD interfacing in real world projects.

You will be knowing about the booster rockets on space shuttle. Without these
booster rockets the space shuttle would not launch in geosynchronous orbit. Similarly to
understand LCD interfacing you need to have booster rockets attached! To get it done right
you must have general idea how to approach any given LCD.This page will help you
develop logical approach towards LCD interfacing.

First thing to begin with is to know what LCD driver/controller is used in LCD.Yes,
your LCD is dumb it does not know to talk with your microcontroller. LCD driver is a link
between the microcontroller and LCD. You can refer the datasheet of LCD to know the LCD
driver for e.g. JHD 162A is name of LCD having driver HD44780U.You have to interface
the LCD according to the driver specification. To understand the algorithm of LCD
interfacing user must have datasheet of both LCD and LCD driver. Many people ignore the
datasheets and end up in troubles. If you want to interface LCD successfully you must have
datasheets.

37
Figure: 3.14. Circuit Connections Of LCD Display

Why people ignore datasheets? Most of us do not like to read 100 pages of datasheet.
But for accurate technical specification datasheets are must. I will show you a technique to
manipulate a datasheet within minutes.

First thing to find out in datasheet is the features viz. operating voltage, type of
interface, maximum speed for interface in MHz, size of display data RAM, number of
pixels, bits per pixel, number of row and columns. You must have the pin diagram of
LCD.Pin diagram of LCD driver can be omitted.

Study the type of communication protocol whether it is parallel or serial interface.


Check how LCD discriminates data bytes and command bytes, which pins on LCD are used
for communication. Study Interface timing diagram given in the datasheet.

From datasheet of LCD driver find out whether hardware reset is required at startup,
what is the time of reset pulse, is it active low and which pins of LCD are to be toggled.

Major task in LCD interfacing is the initialization sequence. In LCD initialization you have
to send command bytes to LCD. Here you set the interface mode, display mode, address
counter increment direction, set contrast of LCD, horizontal or vertical addressing mode,
38
color format. This sequence is given in respective LCD driver datasheet. Studying the
function set of LCD lets you know the definition of command bytes. It varies from one LCD
to another. If you are able to initialize the LCD properly 90% of your job is done.

Next step after initialization is to send data bytes to required display data RAM
memory location. Firstly set the address location using address set command byte than send
data bytes using the DDRAM write command. To address specific location in display data
RAM one must have the knowledge of how the address counter is incremented.

3.7 Power supply:

The input to the circuit is applied from the regulated power supply. The a.c. input
i.e., 230V from the mains supply is step down by the transformer to 12V and is fed to a
rectifier. The output obtained from the rectifier is a pulsating d.c voltage. So in order to get a
pure dc voltage, the output voltage from the rectifier is fed to a filter to remove any a.c
components present even after rectification. Now, this voltage is given to a voltage regulator
to obtain a pure constant dc voltage.

230V D.C
AC Output
supply
50Hz

Step down Bridge Regulator


transformer Rectifier
Filter

Figure: 3.15 Power Supply Circuit

Transformer:

39
Usually, DC voltages are required to operate various electronic equipment and these
voltages are 5V, 9V or 12V. But these voltages cannot be obtained directly. Thus the a.c
input available at the mains supply i.e., 230V is to be brought down to the required voltage
level. This is done by a transformer. Thus, a step down transformer is employed to decrease
the voltage to a required level.

Rectifier:
The output from the transformer is fed to the rectifier. It converts A.C. into pulsating
D.C. The rectifier may be a half wave or a full wave rectifier. In this project, a bridge
rectifier is used because of its merits like good stability and full wave rectification.

Filter:
Capacitive filter is used in this project. It removes the ripples from the output of
rectifier and smoothens the D.C. Output received from this filter is constant until the mains
voltage and load is maintained constant. However, if either of the two is varied, D.C. voltage
received at this point changes. Therefore a regulator is applied at the output stage.

Voltage regulator:
As the name itself implies, it regulates the input applied to it. A voltage regulator is
an electrical regulator designed to automatically maintain a constant voltage level. In this
project, power supply of 5V and 12V are required. In order to obtain these voltage levels,
7805 and 7812 voltage regulators are to be used. The first number 78 represents positive
supply and the numbers 05, 12 represent the required output voltage levels.A variable
regulated power supply, also called a variable bench power supply, is one where you can
continuously adjust the output voltage to your requirements. Varying the output of the power
supply is the recommended way to test a project after having double checked parts
placement against circuit drawings and the parts placement guide.

This type of regulation is ideal for having a simple variable bench power supply.
Actually this is quite important because one of the first projects a hobbyist should undertake
is the construction of a variable regulated power supply. While a dedicated supply is quite
handy e.g. 5V or 12V, it's much handier to have a variable supply on hand, especially for
testing.

40
Most digital logic circuits and processors need a 5-volt power supply. To use these
parts we need to build a regulated 5-volt source. Usually you start with an unregulated
power supply ranging from 9 volts to 24 volts DC (A 12 volt power supply is included with
the Beginner Kit and the Microcontroller Beginner Kit.). To make a 5 volt power supply,
we use a LM7805 voltage regulator IC (Integrated Circuit). The IC is shown below.

Figure: 3.16 Voltage Regulator


The LM7805 is simple to use. You simply connect the positive lead of your
unregulated DC power supply (anything from 9VDC to 24VDC) to the Input pin, connect
the negative lead to the Common pin and then when you turn on the power, you get a 5 volt
supply from the Output pin.

CIRCUIT FEATURES:

Brief description of operation: Gives out well regulated +5V output, output current
capability of 100 mA

Circuit protection: Built-in overheating protection shuts down output when regulator IC
gets too hot

Circuit complexity: Very simple and easy to build

Circuit performance: Very stable +5V output voltage, reliable operation

Availability of components: Easy to get, uses only very common basic components

41
Design testing: Based on datasheet example circuit, I have used this circuit successfully as
part of many electronics projects

Applications: Part of electronics devices, small laboratory power supply

Power supply voltage: Unregulated DC 8-18V power supply

Power supply current: Needed output current + 5 mA

Component costs: Few dollars for the electronics components + the input transformer cost.

BLOCK DIAGRAM:

Figure: 3.17 Power Supply Circuit Diagram

42
This 5V dc acts as Vcc to the microcontroller. The excess voltage is dissipated as
heat via an Aluminum heat sink attached to the voltage regulator.

Bridge Rectifier:

A diode bridge is an arrangement of four diodes connected in a bridge circuit as


shown below, that provides the same polarity of output voltage for any polarity of the input
voltage. When used in its most common application, for conversion of alternating current
(AC) input into direct current (DC) output, it is known as a bridge rectifier. The diagram
describes a diode-bridge design known as a full-wave rectifier. This design can be used to
rectify single phase AC when no transformer center tap is available. A bridge rectifier
makes use of four diodes in a bridge arrangement to achieve full-wave rectification. This is a
widely used configuration, both with individual diodes wired as shown and with single
component bridges where the diode bridge is wired internally.

Typical Bridge Rectifier

For both positive and negative swings of the transformer, there is a Forward path
through the diode bridge. Both conduction paths cause Current to flow in the same direction
through the load resistor, accomplishing full-wave rectification. While one set of diodes is
forward biased, the other set is reverse biased and effectively eliminated from the circuit.

Current Flow in the Bridge Rectifier

43
Figure: 3.18 Current In Bridge Rectifier For +Ve Half Cycle

Figure: 3.19 Current In Bridge Rectifier For -Ve Half Cycle

44
CHAPTER 4

SOFTWARE REQUIREMENTS

4.1 KEIL vision:

Keil is an IDE(Integrated Development Environment) which is used to develop an


application program , compile and run it Even the code can be debugged .It is a simulator
where we can check the application code even in the absence of the hardware board.

Keil is also a cross compiler The process of development of the soft code on a
processor for a particular application and which can be implemented on the target processor
is known as Cross Development.
In our design the main heart of the hardware module is the micro controller which is
the programmable IC .The programming language used for developing the software to the
micro controller is Embedded C /Assembly. The KEIL cross compiler is used to edit,
compile and debug this program Micro Flash programmer is used for burning the developed
code on Keil in to the micro controller Chip.

Software Development Cycle

When you use the Keil Software tools, the project development cycle is roughly the
same as it is for any other software development project.

Figure :4.1 Functional Diagram Of KEIL Software

45
1. Create a project, select the target chip from the device database, and configure the tool
settings.

2. Create source files in C or assembly.

3. Build your application with the project manager.

4. Correct errors in source files.

5. Test the linked application.

Vision2 IDE:

The Vision2 IDE combines project management, a rich-featured editor with


interactive error correction, option setup, make facility, and on-line help. Use Vision2 to
create your source files and organize them into a project that defines your target application.
Vision2 automatically compiles, assembles, and links your embedded application and
provides a single focal point for your development efforts.

C51 Compiler & A51 Assembler:

Source files are created by the Vision2 IDE and are passed to the C51 Compiler or
A51 assembler. The compiler and assembler process source files and create relocatable
object files.

The Keil C51 Compiler is a full ANSI implementation of the C programming


language that supports all standard features of the C language. In addition, numerous
features for direct support of the 8051 architecture have been added. The Keil A51 macro
assembler supports the complete instruction set of the 8051 and all derivatives.

Vision2 Debugger

The Vision2 symbolic, source-level debugger is ideally suited for fast, reliable
program debugging. The debugger includes a high-speed simulator that let you simulate an
entire 8051 system including on-chip peripherals and external hardware. The attributes of
the chip you use are automatically configured when you select the device from the Device
Database.

The Vision2 Debugger provides several ways for you to test your programs on real target
hardware.
46
_ Install the MON51 Target Monitor on your target system and download your program
using the Monitor-51 interface built-in to the Vision2 Debugger.

_ Use the Advanced GDI interface to attach use the Vision2 Debugger front end with your
target system.

Vision2 Integrated Development Environment

The Vision2 IDE is a Windows-based software development platform that


combines a robust editor, project manager, and make facility. Vision2 supports all of the
Keil tools for the 8051 including the C compiler, macro assembler, linker/locator, and
object-HEX converter. Vision2 helps expedite the development process of your embedded
applications by providing the following:

_ Full-featured source code editor,

_ Device database for configuring the development tool setting,

_ Project manager for creating and maintaining your projects,

_ Integrated make facility for assembling, compiling, and linking your embedded
applications,

_ Dialogs for all development tool settings,

_ True integrated source-level Debugger with high-speed CPU and peripheral simulator,

_ Advanced GDI interface for software debugging in the target hardware and for connection
to Monitor-51,

_ Links to development tools manuals, device datasheets & users guides.

C51 Optimizing C Cross Compiler

The Keil C51 Cross Compiler is an ANSI C Compiler that was written specifically to
generate fast,

compact code for the 8051 microcontroller family.

The C51 Compiler generates object code that matches the efficiency and speed of assembly
programming.

47
Using a high-level language like C has many advantages over assembly language
programming:

_ Knowledge of the processor instruction set is not required. Rudimentary knowledge of the
memory structure of the 8051 CPU is desirable (but not necessary).

_ Details like register allocation and addressing of the various memory types and data types
is managed by the compiler.

_ Programs get a formal structure (which is imposed by the C programming language) and
can be divided into separate functions. This contributes to source code reusability as well as
better overall application structure.

_ The ability to combine variable selection with specific operations improves program
readability.

_ Keywords and operational functions that more nearly resemble the human thought process
may be used.

_ Programming and program test time is drastically reduced.

_ The C run-time library contains many standard routines such as: formatted output, numeric
conversions, and floating-point arithmetic.

_ Existing program parts can be more easily included into new programs because of modular
program construction techniques.

_ The language C is a very portable language (based on the ANSI standard) that enjoys wide
popular support and is easily obtained for most systems. Existing program investments can
be quickly adapted to other processors as needed.

C51 Language Extensions

Even though the C51 Compiler is ANSI-compliant, some extensions were added to
support the facilities of the 8051 microprocessor. The C51 Compiler includes extensions for:

_ Data Types,

_ Memory Types,

_ Memory Models,
48
_ Pointers,

_ Reentrant Functions,

_ Interrupt Functions,

_ Real-Time Operating Systems,

_ Interfacing to PL/M and A51 source files.

Code Optimizations

The C51 Compiler is an aggressive optimizing compiler that takes numerous steps to
ensure that the code generated and output to the object file is the most efficient (smallest
and/or fastest) code possible. The compiler analyzes the generated code to produce the most
efficient instruction sequences. This ensures that your C program runs as quickly and
effectively as possible in the least amount of code space.

The C51 Compiler provides nine different levels of optimizing. Each increasing level
includes the optimizations of levels below it. The following is a list of all optimizations
currently performed by the C51 Compiler.

General Optimizations

_ Constant Folding: Constant values occurring in an expression or address calculation are


combined as a single constant.

_ Jump Optimizing: Jumps are inverted or extended to the final target address when the
program efficiency is thereby increased.

_ Dead Code Elimination: Code that cannot be reached (dead code) is removed from the
program.

_ Register Variables: Automatic variables and function arguments are located in registers
whenever possible. No data memory space is reserved for these variables.

_ Parameter Passing Via Registers: A maximum of three function arguments may be


passed in registers.

49
_ Global Common Sub expression Elimination: Identical sub expressions or address
calculations that occur multiple times in a function are recognized and calculated only once
whenever possible.

_ Common Tail Merging: Common instruction blocks are merged together using jump
instructions.

_ Re-use Common Entry Code: Common instruction sequences are moved in front of a
function to reduce code size.

_ Common Block Subroutines: Multiple instruction sequences are packed into subroutines.
Instructions are rearranged to maximize the block size.

8051-Specific Optimizations

_ Peephole Optimization: Complex operations are replaced by simplified operations when


memory space or execution time can be saved as a result.

_ Access Optimizing: Constants and variables are computed and included directly in
operations.

_ Extended Access Optimizing: The DPTR register is used as a register variable for
memory specific pointers to improve code density.

_ Data Overlaying: Function data and bit segments are OVERLAYABLE and are overlaid
with other data and bit segments by the BL51 linker.

_ Case/Switch Optimizing: Depending upon their number, sequence, and location, switch
and case statements may be optimized using a jump table or string of jumps.

Options for Code Generation

_ OPTIMIZE(SIZE): Common C operations are replaced by subprograms. Program code


size is reduced at the expense of program speed.

_ OPTIMIZE(SPEED): Common C operations are expanded in-line. Program speed is


increased at the expense of code size.

_ NOAREGS: Absolute register access is not used. Program code is independent of the
register bank.

50
_ NOREGPARMS: Parameter passing is performed in local data segments rather than
dedicated registers. This is compatible with earlier versions of the C51 Compiler, the PL/M-
51 compiler, and the ASM-51 assembler.

Debugging:

The C51 Compiler uses the Intel Object Format (OMF51) for object files and
generates complete symbol information. Additionally, the compiler can include all the
necessary information such as; variable names, function names, line numbers, and so on to
allow detailed and thorough debugging and analysis with the Vision2 Debugger or any
Intel-compatible emulators.

In addition, the OBJECTEXTEND control directive embeds additional variable


type information in the object file that allows type-specific display of variables and
structures when using certain emulators.

You should check with your emulator vendor to determine if it is compatible with the
Intel OMF51 object module format and if it can accept Keil object modules.

A51 Macro Assembler

The A51 Assembler is a macro assembler for the 8051 microcontroller family. It
translates symbolic assembler language mnemonics into executable machine code. The A51
Assembler allows you to define each instruction in an 8051 program and is used where
utmost speed, small code size, and exact hardware control is essential. The assemblers
macro facility saves development and maintenance time since common sequences need only
be developed once.

Source-Level Debugging

The A51 Assembler generates complete line number, symbol, and type information
in the object file created. This allows exact display of program variables in your debugger.
Line numbers are used for source-level debugging of your assembler programs with the
Vision2 Debugger or third-party emulator.
Functional Overview

51
The A51 Assembler translates an assembler source file into a relocatable object
module. It generates a listing file optionally with symbol table and cross reference. The A51
Assembler supports two different macro processors:

The Standard Macro Processor is the easier macro processor to use. It allows you
to define and use macros in your 8051 assembly programs. The standard macro syntax is
compatible with that used in many other assemblers.

The Macro Processing Language (MPL) is a string replacement facility that is fully
compatible with the Intel ASM51 macro processor. MPL has several predefined macro
processor functions that perform many useful operations like string manipulation or number
processing. Another powerful feature of the A51 Assembler macro processors is conditional
assembly depending on command line directives or assembler symbols. Conditional
assembly of sections of code can help you achieve the most compact code possible. It also
allows you to generate different applications from one assembly source file.

ASSEMBLY VS C:

The assembly code is difficult to read and maintain.

The amount of code reusable from assembly code is very low.

C programs are easy to read, understand, maintain, because it possesses greater


structure.

With C the programmer need not know the architecture of the processor.

Code developed in C will be more portable to other systems rather than in


assembly.

Difference between Conventional C and Embedded C:

Compliers for conventional C are TC, BC

Compilers for Embedded C are keil vision - 2 & 3, PIC C etc.

Conventional C programs needs complier to compile the program & run it.
52
The embedded C program needs a cross compiler to compile & generate HEX
code.

The programs in C are basically processor dependent whereas Embedded C


programs are micro controller dependent.

The C program is used for developing an application and not suitable for embedded
systems.

The embedded C is an extension of the conventional C. i.e Embedded C has all the
features of normal C, but has some extra added features which are not available in C.

Many functions in C do not support Reentrant concept of functions.

C is not memory specific. i.e variables cannot be put in the desired memory

location but the location of variable can be found out.

In embedded C this can be done using specific inbuilt instructions.

C depends on particular processor or application.

Embedded C is Controller or target specific.

Embedded C allows direct communication with memory.

Why C for Micro controllers:

Compatibility

Direct access to hardware address

Direct connection to interrupts

Optimization consideration

Development environment

Rules for developing Embedded C Program:

53
Code Optimization.

1. Minimize local variables

If the number of local variables in a function is less, the compiler will be able to fit
them into registers. Hence, it will be avoiding frame pointer operations on local variables
that are kept on stack. This can result in considerable improvement due to two reasons.

All local variables are in registers so this improves performance over accessing them
from memory.

If no local variables need to be saved on the stack, the compiler will not incur the overhead
of setting up and restoring the frame pointer.

Do not declare all the local variables in the outermost function scope.

If local variables are declared in the inner most scope.

If the parameter was declared in the outermost scope, all function calls would have
incurred the overhead of object .

Place case labels in narrow range

If the case labels are in a narrow range, the compiler does not generate a if-else-if cascade
for the switch statement.

Instead, it generates a jump table of case labels along with manipulating the value of the
switch to index the table.

This code generated is faster than if-else-if cascade code that is generated in cases where
the case labels are far apart.

Also, performance of a jump table based switch statement is independent of the number of
case entries in switch statement.

54
Reduce the number of parameters

Function calls with large number of parameters may be expensive due to large
number of parameter pushes on stack on each call. For the same reason, avoid passing
complete structures as parameters. Use pointers and references in such cases.

4.2 Programming code for this project:

#include<reg52.h>

#define lcd_data P2

sbit lcd_rs=P2^0;
sbit lcd_en=P2^1;

void delay(unsigned int ch) //delay function


{
unsigned int i=0,j=0;
for(i=0;i<=ch;i++)
for(j=0;j<=i;j++);
}
void clcd(unsigned char ch)
{
lcd_data=ch&(0xf0); //send msb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(25);
lcd_en=0;
lcd_data=((ch<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(25);
lcd_en=0;
}
void dlcd(unsigned char ch)
{
lcd_data=ch&(0xf0); //send msb 4 bits
lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
delay(25);
lcd_en=0;
lcd_data=((ch<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=1; //select data register
lcd_en=1; //enable the lcd to execute data
delay(25);
lcd_en=0;

55
delay(3);
}
void stringlcd(unsigned char ch,const unsigned char *chrt)
{
unsigned int ix=0;
if(ch==0x80) clcd(0x01);
clcd(ch);
for(ix=0;chrt[ix]!='\0';ix++)
{
if(ix == 16){clcd(0xc0);}
dlcd(chrt[ix]);
}
}
void initlcd()
{
clcd(0x02);
clcd(0x02);
clcd(0x28);
clcd(0x28);
clcd(0x0e);
clcd(0x06);
clcd(0x01);
clcd(0x80);

/*void conv2(unsigned long int ch)


{
unsigned long int temp=0,temp2=0;
temp2=ch;
temp=temp2/10000;
// dlcd(temp+0x30);
temp2=temp2%10000;

temp=temp2/1000;
dlcd(temp+0x30);
temp2=temp2%1000;
temp=temp2/100;
dlcd(temp+0x30);
temp2=temp2%100;
temp=temp2/10;
dlcd(temp+0x30);
temp2=temp2%10;
dlcd(temp2+0x30);
} */
void conv(unsigned int ch)
{
unsigned int temp=0,temp2=0;
temp2=ch;
56
temp=temp2/10000;
dlcd(temp+0x30);
temp2=temp2%10000;

temp=temp2/1000;
dlcd(temp+0x30);
temp2=temp2%1000;
temp=temp2/100;
dlcd(temp+0x30);
temp2=temp2%100;
temp=temp2/10;
dlcd(temp+0x30);
temp2=temp2%10;
dlcd(temp2+0x30);
}

#include"serial.h"
#include"gsm.h"
#include<string.h>

sbit s1 = P1^0;
sbit s2 = P1^1;
sbit s3 = P1^2;
sbit s4 = P1^3;

code unsigned char mob1[15] = "8125981864\0";


//code unsigned char mob2[15] = "8125981865\0";
//code unsigned char mob3[15] = "8125981866\0";
//code unsigned char mob4[15] = "8125981867\0";

unsigned char rfid_t[15],r = 0,rec=0,card=0;


code unsigned char rfid1[15] = "0D0021A269E7\0";
code unsigned char rfid2[15] = "0D0010CCD504\0";
code unsigned char rfid3[15] = "0D0010F01FF2\0";
code unsigned char rfid4[15] = "0D0010F51BF3\0";

void main()
{
int speed=0;

initlcd();
stringlcd(0x80,"WELCOME");
serialinit();
gsminit();
delay(400);
57
while(1)
{
start:
stringlcd(0x80,"swipe card");
for(r=0;r<12;r++)
{
rfid_t[r] = rx();
}
rfid_t[12] = 0;
if(strcmp(rfid_t,rfid1) == 0){card = 1;}
if(strcmp(rfid_t,rfid2) == 0){card = 2;}
if(strcmp(rfid_t,rfid3) == 0){card = 3;}
if(strcmp(rfid_t,rfid4) == 0){card = 4;}
if(card == 1)
{
stringlcd(0x80,"CAR 1");

}
if(card == 2)
{
stringlcd(0x80,"CAR 2");

}
if(card == 3)
{
stringlcd(0x80,"CAR 3");

}
if(card == 4)
{
stringlcd(0x80,"CAR 4");

}
while(1)
{
if(s1 == 1)
{
while(s1 == 1);
while(s2 == 0)
{
speed++;
delay(10);
if(speed > 2500){card=0;goto start;}
}
speed = speed/5;
speed = 500 - speed;
stringlcd(0x80,"Speed:");conv(speed); delay(600);
if(speed > 300)
{
stringlcd(0x80,"Over Speed");
58
if(card == 1)
{
stringlcd(0xc0,"CAR 1");
sendmsg(mob1,"Over Speed
Car1");delay(600);
card=0;
}
if(card == 2)
{
stringlcd(0xc0,"CAR 2");
sendmsg(mob1,"Over Speed
Car2");delay(600);
card=0;
}
if(card == 3)
{
stringlcd(0xc0,"CAR 3");
sendmsg(mob1,"Over Speed
Car3");delay(600);
card=0;
}
if(card == 4)
{
stringlcd(0xc0,"CAR 4");
sendmsg(mob1,"Over Speed
Car4");delay(600);
card=0;
}
}
speed = 0;
break;
}
}
}
}

59
CHAPTER 5
OUTPUT OF THE PROJECT

Figure 5.1: Image showing the output of the project


In the above image, describes that the car 2 is moving above the threshold speed.
The procedure involved in this project is first power supply is given to the kit i.e., 5v to the
unit, welcome text will be displayed on LCD, after few seconds swipe card text is displayed
than we swipe the card to the reader the entire details will stored in the reader and when
particular car is moving through IR transmitter and receiver pair they senses the speed of the
vehicle and sends to microcontroller unit. The microcontroller unit performs the calculation
part if the speed of the vehicle is excess then it sends signal to GSM modem by the way the
traffic authorities will recognize the particular over speeding vehicle.

60
Figure 5.2: Image Showing The Below Rated Speed Details

61
Figure 5.3: Image Showing The Over speed Vehicle DetailsCHAPTER 6
CONCLUSION
Since number of accidents on highways increases day by day so it is necessary to check
speed of the vehicles on highways so as to remove accident cases and to provide a safe
journey by controlling high speed of the vehicle. It also minimizes the difficulties of traffic
police department and make ease to control the rash driving on highways. The police can
perform their duties while sitting in control room and can provide their service with more
ease and accuracy. In this project we mainly concentrated on vehicle details which can be
possible by using RFID cards with very low cost and the information is send to traffic
authorities through GSM modem. This concept can be extended in future by integrating a
camera with the system which could capture the image of the number plate of the vehicle to
sends that to the traffic authorities.

CHAPTER 7
62
FUTURE SCOPE

o In previous works the over speeding vehicles are detected by using radar guns and
the extension to this radar guns is buzzer.
o In this project we used RFID cards to know the details of particular over speed
vehicle and also GSM to send the over speed vehicle details to the traffic authorities.
o The future scope to this project is installing a camera such that the image of the over
speed vehicle is recognized.

63
REFERENCES
1. Channabasavaiah M S, Shrinivas Mayya D, 2014.Automated Control System for
Emission Level and Rash Driving Detection in Vehicles. International Journal of
Electrical and Electronics Research Vol. 2, Issue 2, pp: (96-99).
2. Chris Thompson, Jules White,2013. Using Smartphones and Wireless Mobile
Sensor Networks to Detect Car Accidents and Provide Situational Awareness to
Emergency Responders.
3. Monika Jain, Praveen Kumar, 2015, Detection of Over Speeding Vehicles on
Highways. International Journal of Computer Science and Mobile Computing,
Vol.4 Issue.4, pg. (613-619).
4. Mr.Girish.Patwari,Mr.Chinmaya.Masali,2015. Relative Wireless Rash Driving
Detection System. International Journal of Emerging Technology in Computer
Science & Electronics (IJETCSE),Volume 14 Issue 2.
5. Peddi Anudeep, K. Hari Babu, 2014. Wireless Reporting System for Accident
Detection at Higher Speeds. Peddi Anudeep Int. Journal of Engineering
Research and Applications Vol. 4, Issue 9( Version 2), pp.17-20.
6. R. Manoj Kumar, Dr.R.Senthil, 2013. Effective Control Of Accidents Using
Routing And Tracking System With Integrated Network Of Sensors,
International Journal of Advancements in Research & Technology, Volume 2,
Issue4.

64

Potrebbero piacerti anche