i
Implementation of Intelligent Toll Plaza
By
Adam Khan
Iqbal Munir
Israr Ahmad
Thesis submitted to the faculty of N-WFP UET in partial fulfillment of requirements for the Degree of B.Sc. Computer Systems Engineering
Department of Computer Systems Engineering,
N-W.F.P. University of Engineering & Technology,
Peshawar, Pakistan.
January, 2008.
ii
Department of Computer Systems Engineering,
N-W.F.P. University of Engineering & Technology
Peshawar, Pakistan
Declaration of Originality
I hereby declare that the work contained in this thesis and the intellectual content of
this thesis are the product of my own work. This thesis has not been previously
published in any form nor does it contain any verbatim of the published resources
which could be treated as infringement of the international copyright law.
I also declare that I do understand the terms ‘copyright’ and ‘plagiarism,’ and
that in case of any copyright violation or plagiarism found in this work, I will be held
fully responsible of the consequences of any such violation.
Signature: _______________________________
Name: __________________________________
Date: ____________________
Place: ____________________
iii
Certificate of Approval
This is to certify that the work contained in this thesis entitled
“IMPLEMENTATIN OF INTELLIGENT TOLL PLAZA SYSTEM”
was carried out by
Israr Ahmad
Adam Khan
Iqbal Munir
Under my supervision and that in my opinion, it is fully adequate, in
scope and quality, for the degree of B.Sc. Computer Systems
Engineering from
N-W.F.P. University of Engineering & Technology, Peshawar.
Approved By:
Signature:________________________
Supervisor: Engr. Zahid Wadood Mufthi
Signature: ________________________
Advisor: Engr. Tariq Saeed
Verified By:
Signature: ________________________
Chairman,
Department of Computer Systems Engineering
Stamp:
iv
Dedication
I completed my project by the grace of all mighty Allah. I dedicate my project
to my family, parents and my friends
Israr Ahmad
I dedicate all my work to my parents and friends
Adam Khan
I would like to dedicate my work to my teachers, friends, family and specially
my parents.
Iqbal Munir
v
In the Name of Almighty
ALLAH The Most Merciful
AND
The Most Beneficent
iv
Acknowledgment
All praises are for the Almighty Allah, who is the source of all the knowledge and
wisdom endowed to mankind, and to the holy profit that showed the light of
knowledge to the whole mankind. We wish to express our deepest obligations to our
parents for their all sort of sacrifices they made during our education. It is indeed
because of their encouragement, and prayers that we have been able to complete this
project.
We are very thankful to our project advisor Engr. Tariq Saeed for his guidance and
encouragement that enabled us to complete this project. We are also very thankful to
our project supervisor Engr. Zahid Wadood Mufthi who have been a constant source
of motivation and dedication.
We are also indebted to Department of Computer Systems Engineering for enhancing
and strengthening our knowledge and skills by providing the best teachers, and also
with suitable timing conditions and dedicated FYP lab to work on this Final Year
Project.
v
Table of Contents
1 INTRODUCTION ........................................................................................................................ 1
1.1 BACKGROUND OF THE PROJECT ............................................................................................. 1
1.2 SYSTEM DESCRIPTION............................................................................................................ 2
1.2.1 Automatic Vehicle Identification (AVI) ............................................................................ 2
1.2.2 Automatic Vehicle Classification (AVC) .......................................................................... 3
2 RFID TECHNOLOGIES ............................................................................................................. 4
2.1 WHAT IS RADIO FREQUENCY IDENTIFICATION ...................................................................... 4
2.2 RADIO FREQUENCY (RF) BASIC TECHNOLOGIES ................................................................... 4
2.3 WHY RFID WHY NOT INFRARED OR BLUETOOTH ................................................................. 5
2.4 THE CRUCIAL ISSUES OF POWER SELECTION ......................................................................... 6
2.5 BASIC ELECTROMAGNETIC (EM) PROPAGATION MODEL....................................................... 6
2.5.1 Free Space Line of Sight Transmission ............................................................................ 6
2.5.2 Reflection.......................................................................................................................... 6
2.5.3 Refraction ......................................................................................................................... 6
2.5.4 Diffraction ........................................................................................................................ 7
2.6 BASIC TYPES OF TAGS........................................................................................................... 7
2.6.1 Passive Tags ..................................................................................................................... 7
2.6.1.1 Load Modulation...................................................................................................................7
2.6.1.2 Back Scatter ..........................................................................................................................8
2.6.2 Semi Passive Tags ............................................................................................................ 8
2.6.3 Active Tags ....................................................................................................................... 9
2.7 DIFFERENT FREQUENCIES OF RFID........................................................................................ 9
2.7.1 125 and 134.2 kHz. LF (Low Frequency)......................................................................... 9
2.7.1.1 Pros .......................................................................................................................................9
2.7.1.2 Cons ....................................................................................................................................10
2.7.2 13.56 MHz. HF (High Frequency) ................................................................................. 10
2.7.2.1 Pros .....................................................................................................................................10
vi
2.7.2.2 Cons ....................................................................................................................................10
2.7.3 860 ~ 960 MHz. UHF (Ultra High Frequency).............................................................. 10
2.7.3.1 Pros .....................................................................................................................................10
2.7.3.2 Cons ....................................................................................................................................11
3 THE BIG PICTURE................................................................................................................... 12
3.1 TRANSMITTER SIDE.............................................................................................................. 12
3.1.1 Brief description of the components ............................................................................... 12
3.1.2 89c51 microcontroller .................................................................................................... 13
3.1.3 Voltage Regulator........................................................................................................... 14
3.1.4 MAX232.......................................................................................................................... 14
3.1.5 Crystal ............................................................................................................................ 15
3.1.6 Capacitors ...................................................................................................................... 15
3.1.7 Transistor ....................................................................................................................... 16
3.1.8 Resistors ......................................................................................................................... 16
3.1.9 DB-9 connectors............................................................................................................. 16
3.1.10 Power source ............................................................................................................. 16
3.2 RFID RECEIVER................................................................................................................... 16
4 EXPLORING ACTIVITIES OF MICROCONTROLLER 89C51 ........................................ 18
4.1 BASIC FEATURES OF 89C51.................................................................................................. 18
4.1.1 Types of Memory ............................................................................................................ 18
4.1.1.1 On-Chip Memory................................................................................................................19
4.1.1.2 External Code Memory .......................................................................................................20
4.1.1.3 Code memory......................................................................................................................20
4.1.2 Timers used in 8051........................................................................................................ 20
4.1.3 Timer SFRs ..................................................................................................................... 21
4.1.4 Addressing modes........................................................................................................... 22
4.1.4.1 Immediate addressing..........................................................................................................22
4.1.4.2 Direct addressing.................................................................................................................22
4.1.4.3 Indirect addressing ..............................................................................................................22
5 SERIAL COMMUNICATION.................................................................................................. 23
5.1 THE 8051 SERIAL PORT........................................................................................................ 23
vii
5.1.1 RS-232 Serial Communications...................................................................................... 23
5.1.1.1 Asynchronous Serial Communications ...............................................................................24
5.2 SETTING THE SERIAL PORT MODE ....................................................................................... 25
5.3 SETTING THE SERIAL PORT BAUD RATE .............................................................................. 26
5.4 WRITING TO THE SERIAL PORT ............................................................................................ 27
5.5 READING FROM THE SERIAL PORT ....................................................................................... 27
5.6 SERIAL COMMUNICATION OF PC (USING HYPER TERMINAL) ............................................... 28
5.6.1 Hyper Terminal: ............................................................................................................. 28
5.6.1.1 Baud rate: ............................................................................................................................29
5.6.1.2 Start bit:............................................................................................................................... 29
5.6.1.3 Stop bit:............................................................................................................................... 29
5.6.1.4 Parity bit:.............................................................................................................................29
5.6.1.5 Frame: .................................................................................................................................29
5.7 THE RS-232 ......................................................................................................................... 30
5.7.1 Introduction .................................................................................................................... 30
5.7.2 Rules of communication using RS232............................................................................. 31
5.7.3 Baud rates for RS232...................................................................................................... 31
5.7.4 Modes of Communication used by RS232 ...................................................................... 32
5.7.4.1 Synchronous mode ..............................................................................................................32
5.7.4.2 Three asynchronous modes .................................................................................................32
5.7.5 Serial port registers........................................................................................................ 32
5.8 CHECKING OUR OPERATIONS ON DATA................................................................................. 32
6 LCD INTERFACING AND PROGRAMMING...................................................................... 33
6.1 44780 BACKGROUND...................................................................................................... 33
6.2 HANDLING THE EN CONTROL LINE............................................................................ 34
6.3 HOW TO CONFIGURE LCD ................................................................................................... 35
6.4 INITIALIZING THE LCD ......................................................................................................... 35
6.5 CLEARING THE DISPLAY ...................................................................................................... 36
6.6 WRITING TEXT TO THE LCD ................................................................................................ 37
6.7 CURSOR POSITIONING................................................................................................... 38
7 REFERENCES ........................................................................................................................... 40
viii
List of Figures FIGURE 3- 1 TRANSMITTER CIRCUITRY ................................................................................................... 12
FIGURE 3- 2 VOLTAGE REGULATOR ........................................................................................................ 14
FIGURE 3- 3 MAX232 CIRCUITRY .......................................................................................................... 15
FIGURE 3- 4 TRANSMITTER OVERVIEW.................................................................................................... 16
FIGURE 3- 5 RECEIVER CIRCUITRY.......................................................................................................... 17
FIGURE 3- 6 RECEIVER OVERVIEW .......................................................................................................... 17
FIGURE 4- 1 BLOCK DIAGRAM OF 8051.................................................................................................. 18
FIGURE 4- 2 MEMORY DESCRIPTION OF 8051.......................................................................................... 19
FIGURE 4- 3 ON-CHIP MEMORY OF 8051 [7] ............................................................................................ 19
FIGURE 5- 1 REPRESENTAION OF SERIAL COMMUNICATION.................................................................... 23
FIGURE 5- 2 TWO WAY COMMUNICATION USING THREE WIRES ............................................................... 24
FIGURE 5- 3 REPRESENTATION OF A CHARACTER ................................................................................... 24
FIGURE 5- 4 FRAME REPRESENTATION.................................................................................................... 25
FIGURE 5- 5 FRAMED DATA INCLUDING PARITY ..................................................................................... 25
FIGURE 5- 6 SCON SFR......................................................................................................................... 25
FIGURE 5- 7 SELECTION COM PORT......................................................................................................... 28
FIGURE 5- 8 SETTING THE DATA RATE..................................................................................................... 28
FIGURE 5- 9 THE HYPERTERMINAL WINDOW .......................................................................................... 30
ix
LIST OF TABLES TABLE 3- 1 TABLE OF COMPONENTS ....................................................................................................... 13
TABLE 4- 1 SFR NAMES & ADDRESSES .................................................................................................. 21
x
ABSTRACT
A system for Intelligent Toll Plaza includes a toll facility, an in-vehicle toll processor
having memory for storing a toll-money-available quantity purchased by the user, and
a toll-facility-identification site that transmits a toll-facility-identifier signal indicating
the identity of the upcoming toll facility and the toll to be collected. As the vehicle
approaches the identification site, the in-vehicle processor receives the identifier
signal and calculates the toll to be debited. When the vehicle passes through the toll
facility, the facility transmits a toll-collect signal instructing the in-vehicle toll
processor to debit the calculated toll from memory. The in-vehicle processor debits
the calculated amount and transmits an acknowledgement signal to the toll facility.
1
1 Introduction
1.1 Background of the Project
Our project relates generally to systems for vehicle toll collection, and, more
particularly, relates to apparatus and methods for automatic, non-contact, high-speed
collection of vehicular tolls.
An increasing number of vehicles are traveling over progressively more
congested highways. The collection of tolls by conventional means has a negative
effect upon highway throughput and safety. Congestion and long backups on toll
plazas are becoming more common. Such conditions involve a significant economic
cost, through lost time, and reduced productivity. Moreover, serious accidents at toll
plazas, caused by operator or mechanical failure, have also increased in frequency.
Certain toll authorities have attempted to respond to these problems by
providing coin-operated toll collection devices, or by instituting a toll-plate system in
which toll-takers visually inspect each incoming vehicle for an appropriate toll plate
or sticker. Coin-operated toll collection systems, however, do little to increase
throughput, and are susceptible to fraud, through the use of counterfeit coins. Toll-
plate systems suffer the same deficiencies, requiring each vehicle to slow sharply
while entering the visual inspection area; these systems also rely heavily on toll-taker
attentiveness.
Additionally, a number of systems have been proposed for utilizing radio frequency
identification (RFID) techniques for toll collection. Under these systems, drivers
acquire a "tag" or card that acts as a reflective transmitter or discrete transmitter to
identify the vehicle by serial number as it passes through a toll booth. This technique
is also referred to as Automatic Vehicle Identification (AVI).
This system also suffers from a number of deficiencies. In particular, because the
RFID tag lacks a machine-intelligent processor for manipulation and storage of
accounts, toll authorities must maintain individual toll accounts for all users of the
system. This becomes especially burdensome in urban areas or regions of high toll
traffic volume. Toll agencies would need to manage hundreds of thousands of
individual accounts, a burden that is created by operation of the AVI system.
2
Additionally, because the RFID tags lack a processor or user interface, vehicle
operators cannot readily ascertain account balances, and have no warning as to limited
or exhausted credit. This creates both confusion, and potential safety hazards, as
drivers cross over to conventional toll collection lanes with little warning.
Further, in the absence of a single national toll agency, each participating driver
would need to have multiple cards attached to the vehicle, each corresponding to a
separate toll authority account. The RFID system also raises user-privacy issues by
requiring the generation and storage of detailed vehicle-specific travel records. It is
accordingly an object of the system to provide improved toll collection methods and
apparatus that significantly increase the traffic capacity of roadways. Another object
of the system is to provide toll collection methods and apparatus that increase the rate
of toll collection while enhancing highway safety. A further object of the system is to
provide such methods and apparatus that are convenient to use and support toll
collection by a plurality of toll authorities. Yet another object of the system is to
provide toll collection systems that reduce administrative burdens, facilitate the
generation of transaction reports for users and toll authorities, and preserve the
privacy of users. It is a further object of the system to provide toll collection systems
that are reliable and resistant to attempts at fraud or toll evasion, and which are readily
integrated into existing toll management systems.[1]
1.2 System Description
Electronic Toll Collection (ETC) is used in urban areas, over bridges, in tunnels, in
High Occupancy Toll (HOT) lanes, on toll roads, or through turnpikes. A toll
collection system can be either open or closed. The closed system requires all
entrances and exits to have either manual tollbooths or an ETC system. Nearly all
manual toll systems will get converted to an ETC system in the future.
An ETC system typically includes two main components:
1.2.1 Automatic Vehicle Identification (AVI)
AVI entails the use of electronic radio frequency tags installed in the vehicle. The
tags either passively or actively communicate with roadside readers to identify vehicle
ownership. Once ownership is determined, the toll cost can be deducted from the
corresponding account.
3
1.2.2 Automatic Vehicle Classification (AVC)
AVC technologies installed in the roadway can determine a vehicle’s class by its
physical attributes. Transaction processing is the process of debiting customers’
accounts and answering customer inquiries. There are several methods used for
violation enforcement, including automatic number plate recognition (ANPR)
technology. Highway patrol officers are usually posted by unmanned toll booths,
acting as a visible, and effective, violation deterrent.
The four components are somewhat independent, and various toll agencies have
contracted out functions separately. In some cases, this division of functions has
resulted in difficulties.
4
2 RFID Technologies
2.1 What Is Radio Frequency Identification
Radio Frequency Identification is a technology that uses Radio Frequency waves to
interrogate or read objects known as transponders or tags. Each tag always has a
Unique Identification Number (UID) stored in bits in the tag memory that is
transmitted to the reader when the Tag is Read. In addition to the UID there may be
other information stored in the tag memory. The technology allows for reading of tags
from physical contact to beyond the line of sight of the reader. A simple RFID
system consists of a reader with a cable attached to an antenna and a tag that is
read(interrogated) by the reader.
2.2 Radio Frequency (RF) Basic Technologies
Radio Frequency signals are actually electromagnetic wave consisting of the same
radiation as light, ultra-violet, and infra-red rays. Radio Frequency waves/signals
radiate outward from an antenna and have both an electric and a magnetic wave
component.
The frequency that a radio frequency identification (RFID) system operates is called a
“carrier wave” or "carrier frequency".
RFID systems operate on a number of frequencies. Some of the common RFID
Frequencies are:
1) 125 kHz. Also known as Low Frequency (LF)
2) 134.2 kHz. Also known as Low Frequency (LF)
3) 2.4MHz. or High Frequency (HF)
There is also another radio band assigned to RFID – 5.8 GHz. SHF (Super High
Frequency); also known as Microwave. Currently this band is not being used due to
lack of standards and some inherent limitations.
Antennas are tuned to resonate only to a narrow range of carrier frequencies that are
centered on the designated RFID system frequency. This means that a system with a
5
carrier wave of 915 MHz. (Center of 902 ~ 928 MHz.) will not read a tag at 13.56
MHz, 125 kHz frequencies .
RFID systems use the decibel (dB) to describe antenna gain, cables losses and power
output for all hardware specifications and regulations. There are different regulations
for different frequencies in different countries that must be taken into consideration
when designing, installing and maintaining an RFID system.
2.3 Why RFID Why Not Infrared or Bluetooth
If one decide to use infrared for data transmission he will find that line of sight is a
big problem in IR. If any obstacle comes in between the infrared transmitter and
receiver the signal will drop and the data will get corrupted but will even fail to reach
the receiver. To avoid this one has to search for the best alternative. If RFID is used
instead of IR the problem of line of sight will get solved. Line of sight creates the
same problem at lower frequency but we can increase the RFID’s frequency easily.
Apart from this the RFID is more secure for that it only receive those frequencies
which are only registered with it, the other frequencies are out of range for it. It works
just like the bar code reader reads the bars.[2]
Figure 2- 1 RFID Circuitry
6
2.4 The Crucial Issues of Power Selection
The Decibel is a ratio between two signal strength levels and is a 10th of a Bel. These
calculations are "logarithmic scale measurements" hence they use the logarithm of a
physical quantity instead of the quantity itself!
Bel = log (P2/P1)
dB is also a logarithmic measurement and gives simple numbers for large-scale
variations in signal strength. This is very useful as you can easily calculate the RFID
system gain and losses by adding and subtracting whole numbers.
dB=10*log (P2/P1)
The dB unit allows big variations in signal strengths/levels to be handled with simple
math.
The Radio Frequency POWER LEVEL is expressed in watts or in dBm. dBm refers
to the power in decibel referenced to one milliwatt (1mW). The relation between
dBm and watts is given by the formula:
P(dBm) = 10 x Log (P/1mW)
P (dBi; references an isotropic radiator) = 1 - log (Pr/Pi), where Pi is power received
from an isotropic antenna.
P (dBd; references a dipole antenna) = 10 Log (Pr/Pd), where Pd is power received
from a dipole antenna.[3]
2.5 Basic Electromagnetic (EM) Propagation Model
2.5.1 Free Space Line of Sight Transmission
Satellite communications.
2.5.2 Reflection
Most commonly used for land mobile communications.
2.5.3 Refraction
Bending the EM waves when it passes through media such as water, plastic, and other
materials that have different refractive indexes.
7
2.5.4 Diffraction
Bending the EM waves around an object.
Attenuation is the reduction in amplitude and intensity of a signal. As the EM wave
goes farther, is reflected, refracted or diffracted the signal strength drops dramatically.
An Isotropic source radiates power equally in all directions – laboratory and theory
only just to assist you in understanding theory versus practicality.
As the EM signal travels from the transmit antenna to the receiving antenna it loses
strength.
2.6 Basic Types Of Tags
2.6.1 Passive Tags
Passive tags are the most employed in the world due to many reasons, many of which
are shown below.
They are small, inexpensive and have a long life (some over 20 years) .They do not
have their own power source therefore they require no maintenance to replace a worn
out battery. They obtain power from the RF waves emitted by a reader. Therefore they
can only communicate when in the read zone of a reader. Tag read range is any where
from a few centimeters/inches to about 9 meters or 30 feet. We have successfully
been able to obtain an excellent read rate but with only a few tags per second at about
40 feet. This was accomplished using very low loss cables and a high gain circular
polarized antenna. You can not obtain this read range in Europe due to power and
bandwidth limitations.
The disadvantage of passive tags is the shorter read range.
Passive tags have no batteries and rely on the electromagnetic wave from the reader to
build up enough power in the tag’s integrated circuit to send back the UID response to
the reader.
Passive RFID tags and readers communicate by coupling the transmitter to the
receiver using:
2.6.1.1 Load Modulation
It is used in the near field (close range) in LF, HF and some UHF.
8
2.6.1.2 Back Scatter
It is used in the far field (longer range) for UHF and Microwave
In near field communication the tag communicates with the reader by electromagnetic
inductance. The coiled antennas of the tag and reader form a transformer. The reader
uses the carrier wave and changes the amplitude (displacement/size), phase or
frequency. The tag detects this as a change in modulation and responds appropriately.
In far field communication backscatter is used. Backscatter is the reflection of the
radio frequency wave when it hits a conductive surface. The amount of energy
reflected depends on how well the surface resonates with the frequency on the wave.
Resonance is the tendency of a system to oscillate at maximum amplitude at a certain
frequency. Similar to when you pick a guitar string, the string and the sound box of
the guitar resonates – it’s not just the string that is making the sound the whole system
resonates!
The tag antenna is designed to resonate with the specific carrier frequency of the
designated system. This is why 125 kHz tags can not be read by 134.2 kHz readers
even though the frequencies are very close.
In far field communication UHF tags can be specifically tuned to resonate depending
on the type of material that they are attached to. Hence you can now have Pallet tags
– for wood or plastic, metal tags for metal bins, metal tags for computer hardware.
The UHF tag can be tuned so that when you attach it to the material it is designed for
you get maximum resonance! So checking a tag read rate and distance without the
tag being mounted to the material will not provide correct information.
In the UHF tags passive backscatter is used to transmit data between the reader and
the tag. Part of the electromagnetic wave is used to power the IC in the tag and the
reflected part (backscatter) is used to communicate with the reader.[4]
2.6.2 Semi Passive Tags
1. Semi passive tags have batteries to power the IC.
2. Tag read range can be up to 30 meters or about 100 feet.
3. Tag can be coupled to sensors for measuring many different conditions.
9
4. Tag requires lower reader signal to activate.
5. Tag can have sleep mode to conserve battery life.
6. Disadvantage is higher cost, larger and heavier tag and battery maintenance is
required.
2.6.3 Active Tags
1. Active tags have a battery or other power source. Some active tags can be
attached to larger power sources such a 9 Volt, 12 Volt or AC power supplies.
2. Active tags contain their own radio transmitter.
3. Tag has a longer read range – up to 750 feet or more.
4. Tag can have a larger memory up to 64 K bytes.
5. Tags can be configured to alarm when moved, tampered with, or attached
cable cut.
6. Tags can contain environmental sensors for movement, temperature, pressure,
magnetic flux density change, and more with tolerance limits for activation.
7. Tags can be set to continuously beacon or send out their identification, put into
sleep mode until activated by a reader, or activate only when an environmental
condition is met.
8. Histories of activities or events sensed by the tag can be stored in the tags
memory for retrieval at a later date.
Disadvantages of active tags are cost, size and weight.
2.7 Different frequencies of RFID
2.7.1 125 and 134.2 kHz. LF (Low Frequency)
2.7.1.1 Pros
1. Minimum regulations from governments.
2. Small amounts of data stored 128 bit to 2 K bit.
3. Excellent for reading at slow speed and minimum distance.
4. Penetrates most materials such as water, tissue, and wood.
10
5. Can have high security using encryption and adjustable frequency.
2.7.1.2 Cons
1. Minimum penetration around metals.
2. Slower read rates.
3. Minimum range.
4. Largest antenna requirement due to wavelength of 2,400 meters or 7,860 feet.
2.7.2 13.56 MHz. HF (High Frequency)
2.7.2.1 Pros
1. Penetrates water and tissue well.
2. Longer read and write range than LF.
3. Simpler antenna due to size of wavelength being 22 meters or 73 feet.
4. Higher data rate than LF.
5. Smaller form factor.
6. Ideal for Smart Card read/write.
2.7.2.2 Cons
1. Maximum read range of 1.5 Meters or 4.8 feet under ideal conditions.
2. Does not penetrate or transmit well around metals - low read distance or about
20 cm or 8 inches.
3. Requires specific antenna configurations to obtain good read rates.
2.7.3 860 ~ 960 MHz. UHF (Ultra High Frequency)
2.7.3.1 Pros
1. Best frequency for read distances of over 1 meter or 3 feet.
2. Range of up to about 9 Meters or 30 feet under ideal conditions. (Europe 7
meters or 22 feet)
3. High Data transfer rate
4. Smaller antenna as wavelength is .33 Meters or 1.1 feet.
11
5. Controlled read zones using antenna directional capabilities.
6. One tag can be used to identify a product in one continent and read by a reader
on another continent using a different frequency. 860 MHz. ~ 928 MHz.
provides global interoperability.
7. Tags can be made in many form factors to work in many environments.
8. Tags can be tuned to operate better when attached to a specific material.
2.7.3.2 Cons
1. Difficult to penetrate water and tissue (though you can now obtain tags for
bottled liquids)
2. Numerous regulatory issues for frequency, power, channels, duty cycles,
bands and more.
3. To operate globally an IC must be capable of operating at 0.5 W to 4.0 W with
varying duty cycles and output power.
4. Readers are more expensive than HF.
12
3 The Big Picture
3.1 Transmitter Side
The circuit at the vehicle side (Transmitter Side) consists of:
Figure 3- 1 Transmitter Circuitry
3.1.1 Brief description of the components
The list of the components that are required for designing the circuit of the
mobility based control system is following.
13
Table 3- 1 Table of components
Name of component value quantity
AT89S52 µcontroller ___ 1
MAX232 ___ 1
Crystal 11.0592 MHz 1
Capacitor (1) 10µf 6
Capacitor (2) 30pf 2
Transistors 2N2222 4
Resistor (1) 8.2KΩ 1
Resistor (1) 80 Ω 4
DB-9 (Female) 2
Regulator 5V 1
Diodes 2
DC Battery 9V 2
LED 5V 3
3.1.2 89c51 microcontroller
The 8051 is the central part of our project, which controls all the activities of
the systems. The 40- pins DIP (dual in line package) of 8051 is used. This
version of 8051 is serially programmable.
We have stored the data of the vehicle like:
• Name:
• License Number:
• Car Number:
• Chassis Number
14
The microcontroller gets its clock from the crystal Y1 at pin#18 and 19.
The RFID continuously transmits the radio waves for its identification at the toll
plaza. As the vehicle enters the vicinity of the Toll Plaza it sends the information
through its pin # 10 which is used for transmission by the 8051 and the receiver gets
the data through pin # 9 of the microcontroller from the vehicle and checks its
registration.
3.1.3 Voltage Regulator
The voltage regulator LM7805 gives a constant power to the microcontroller. A diode
---- is connected with LM7805 so that the circuit work only forward biased settings.
LM7805 has three legs out of which, one get the input voltage, one acts as ground and
the other gives the constant voltage.
Figure 3- 2 Voltage Regulator
3.1.4 MAX232
The exchange of information between 8051 and RFID is done in serial manner. One
has to use the max232 to make this possible. The max232 converts the uni-polar
signal (0v to 5v) of microcontroller to a bipolar signal (-12v to +12v).CMOS and TTL
Description. The MAX232 is also called the line driver.
The max232 sends the modified signal using its pin # 6 to the serial port at pin # 4.
Now one can check the circuitry by making the Tx and Rx of the microcontroller
short. Making a hyper-terminal connection the data from the key board goes to the
15
microcontroller and comes back to display on the monitor. It means the circuit is
functional.
Now put the microcontroller containing the program in the port and attach the antenna
to the serial data. Attach the antenna to the input of oscilloscope (supporting high
frequency) and check the resultant signal.
For purpose of demonstration one can store data of eight different vehicles in one
microcontroller at receiver side. Now one can access data of a single vehicle by using
a dip switch. DIP switch has eight buttons, the data of a specific vehicle can be
selected by making the corresponding button connected with ground. Data of the
selected vehicle is displayed on the 2*16 LCD to make the circuit interactive of the
other wise one can check on monitor screen of a computer by making a hyper
terminal connection.
Figure 3- 3 MAX232 Circuitry [5]
3.1.5 Crystal
A crystal is used to provide clock to µcontroller. The value of the crystal used
in the circuit is 11.0592 MHz.
3.1.6 Capacitors
The 10µf and 16V polar capacitors are used in this circuitry. The 30pf
monolithic capacitors are used with the crystal of 8051.
16
3.1.7 Transistor
This 2N2222 transistor is used. The purpose of this transistor is switching
here. It is a PNP transistor.
3.1.8 Resistors
The 8.2KΩ resistor is used in the reset circuitry of the 8051. The 80Ω resistors
are used in the circuitry of relays.
3.1.9 DB-9 connectors
The male DB-9 connector is used to connect the reciever circuitry while the
other DB-9 connector is used to watch the response of the µcontroller on
Hyper Terminal.
3.1.10 Power source
A 9V battery is connected to the circuit to provide it the necessary power. A
regulator IC is used to provide 5V DC to the µcontroller.
Figure 3- 4 Transmitter overview
3.2 RFID Receiver
1. These devices are installed at tollgate lanes where ETC can be used. They
communicate by radio with the on-board equipment installed in vehicles
passing through toll plaza.
2. Roadside antennas are connected to computers for toll calculation. The tolls
are calculated by these computers.
17
Figure 3- 5 Receiver Circuitry
Serial Port
RFID Receiver
Figure 3- 6 Receiver overview
The basic process for ETC with Active RFID transponders is as follows:
i. As the vehicle enters the toll lane, sensors detect the vehicle’s presence
ii. A transponder mounted on the vehicle’s windshield transmits the tag status which
is read by an electronic reader or antenna.
iii. The antenna transmits the information to the lane controller, which then sends the
data to the host for processing.
iv. The corresponding customer account is charged. If the vehicle does not have a
transponder, or a corresponding customer account cannot be identified, the system
classifies the vehicle as a violator and cameras photograph the vehicle and its license
plate.
18
4 Exploring Activities of Microcontroller 89c51
8051 is the central component of the system and is used to store the vehicle record
like name, license number, chassis number etc in it built-in memory.
4.1 Basic Features of 89c51
4 K Bytes ROM, 128 Bytes RAM, Four 8-bit I/O Ports, Two 16 Bit Timers, Serial
Interface,64 K External Code Memory Space, 64 K External Data Memory Space,
Boolean processor (operates on single bits),210 Bit Addressable Locations,4
Microseconds Multiply / Divide [6]
Figure 4- 1 Block Diagram of 8051
4.1.1 Types of Memory
The 8051 has three very general types of memory. The memory types are illustrated
in the following graphic. They are: On-Chip Memory, External Code Memory, and
External RAM.
19
Figure 4- 2 Memory Description of 8051
4.1.1.1 On-Chip Memory
It refers to any memory (Code, RAM, or other) that physically exists on the
microcontroller itself. On-chip memory can be of several types. On-chip memory is
really one of two types: Internal RAM and Special Function Register (SFR) memory.
The layout of the 8051's internal memory is presented in the following memory map:
Figure 4- 3 On-chip memory of 8051 [7]
As is illustrated in this map, the 8051 has a bank of 128 bytes of Internal RAM. This
Internal RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is
also the most flexible in terms of reading, writing, and modifying its contents. Internal
RAM is volatile, so when the 8051 is reset this memory is cleared.
20
4.1.1.2 External Code Memory
It is code (or program) memory that resides off-chip. This is often in the form of an
external EPROM. External RAM As an obvious opposite of Internal RAM, the 8051
also supports what is called External RAM. As the name suggests, External RAM is
any random access memory which is found off-chip. What External RAM loses in
speed and flexibility it gains in quantity. While Internal RAM is limited to 128 bytes
(256 bytes with an 8052), the 8051 supports External RAM up to 64K.
4.1.1.3 Code memory
It is the memory that holds the actual 8051 program that is to be run. This memory is
limited to 64K and comes in many shapes and sizes: Code memory may be found on-
chip, either burned into the microcontroller as ROM or EPROM.
4.1.2 Timers used in 8051
The 8051 comes equipped with two timers, both of which may be controlled, set,
read, and configured individually. The 8051 timers have three general functions:
1) Keeping time and/or calculating the amount of time between events,
2) Counting the events themselves, or
3) Generating baud rates for the serial port.
A timer always counts up. It doesn’t matter whether the timer is being used as a timer,
a counter, or a baud rate generator: A timer is always incremented by the
microcontroller.
Different modes of TMOD Registers are:
1. 13-bit Time Mode (mode 0)
2. 16-bit Time Mode (mode 1)
3. 8-bit Time Mode (mode 2)
4. Split Timer Mode (mode 3)
When a timer is used to measure time it is also called an "interval timer" since it is
measuring the time of the interval between two events. [8]
21
4.1.3 Timer SFRs
As mentioned before, the 8051 has two timers which each function essentially the
same way. One timer is TIMER0 and the other is TIMER1. The two timers share two
SFRs (TMOD and TCON) which control the timers, and each timer also has two
SFRs dedicated solely to itself (TH0/TL0 and TH1/TL1).
Generally SFRs are called an used by there names, but in reality an SFR has a
numeric address. It is often useful to know the numeric address that corresponds to an
SFR name. The SFRs relating to timers are:
Table 4- 1 SFR Names & Addresses
SFR Name Description SFR Address
TH0 Timer 0 High Byte 8Ch
TL0 Timer 0 Low Byte 8Ah
TH1 Timer 1 High Byte 8Dh
TL1 Timer 1 Low Byte 8Bh
TCON Timer Control 88h
TMOD Timer Mode 89h
When we enter the name of an SFR into an assembler, it internally converts it to a
number.[12] For example, the command:
MOV TH0,#25h
moves the value 25h into the TH0 SFR. However, since TH0 is the same as SFR
address 8Ch this command is equivalent to:
MOV 8Ch,#25h
Timer 0 has two SFRs dedicated exclusively to itself: TH0 and TL0. Without making
things too complicated to start off with, you may just think of this as the high and low
byte of the timer. That is to say, when Timer 0 has a value of 0, both TH0 and TL0
22
will contain 0. When Timer 0 has the value 1000, TH0 will hold the high byte of the
value (3 decimal) and TL0 will contain the low byte of the value (232 decimal).
Reviewing low/high byte notation, recall that you must multiply the high byte by 256
and add the low byte to calculate the final value.
4.1.4 Addressing modes
An "addressing mode" refers to how you are addressing a given memory location.
Each of these addressing modes provides important flexibility.
4.1.4.1 Immediate addressing
is so-named because the value to be stored in memory immediately follows the
operation code in memory. That is to say, the instruction itself dictates what value will
be stored in memory. This instruction uses Immediate Addressing because the
Accumulator will be loaded with the value that immediately follows; in this case 20
(hexidecimal).
4.1.4.2 Direct addressing
It is so-named because the value to be stored in memory is obtained by directly
retrieving it from another memory location. For example: This instruction will read
the data out of Internal RAM address 30 (hexadecimal) and store it in the
Accumulator.
4.1.4.3 Indirect addressing
It is a very powerful addressing mode which in many cases provides an exceptional
level of flexibility. Indirect addressing is also the only way to access the extra 128
bytes of Internal RAM found on an 8052. This instruction causes the 8051 to analyze
the value of the R0 register. The 8051 will then load the accumulator with the value
from Internal RAM which is found at the address indicated by R0.
23
5 Serial Communication One of the 8051.s many powerful features is its integrated UART, otherwise known
as a serial port.
5.1 The 8051 Serial Port
5.1.1 RS-232 Serial Communications
Figure 5.1 shows a PC connected to a device such as a modem or a serial printer using
the RS-232 connection. In a modern PC the RS-232 interface is referred to as a COM
port. The COM port uses a 9-pin D-type connector to attach to the RS-232 cable. The
RS-232 standard defines a 25-pin D-type connector but IBM reduced this connector to
a 9-pin device so as to reduce cost and size. Figure 5.2 shows a simple simplex serial
communication link where data is being transmitted serially from left to right. A
single Tx (transmit) wire is used for transmission and the return (GND) wire is
required to complete the electrical circuit. Figure 5.3 shows the inclusion of another
physical wire to support full-duplex (or half-duplex) serial communication. The RS-
232 (COM port) standard includes additional signal wires for “hand-shake” purposes,
but the fundamental serial communication can be achieved with just two or three
wires as shown in figure 5.1 [9]
Figure 5- 1 Representaion of Serial Communication
24
Gnd
9-pinD-type
connector
9-pinD-type
connector
TxRx
Figure 5- 2 Two way communication using three wires
The serial data is transmitted at a predefined rate, referred to as the baud rate.
The term baud rate refers to the number of state changes per second, which is the
same as the bit rate for this particular communication scheme. Typical baud rates are:
9600 bps; 19,200 bps; 56kbps etc.[10]
5.1.1.1 Asynchronous Serial Communications
Since data is sent is a serial fashion, without any reference to a timing clock to
help synchronize the receiver clock in terms of frequency and phase, the
system is said to be non-synchronous, or asynchronous. The baud rate clocks
at each end of the RS-232 link are set to the same frequency values but there is
no mechanism to synchronize these clocks. Figure 5.4 shows three bytes
transmitted by the PC. Assume the bytes are ASCII coded to represent the
characters A, B and C. The receiver needs to know exactly where each
character starts and finishes. To achieve
Figure 5- 3 Representation of a Character
this, the data character is framed with a start bit at the beginning of each character and
a stop bit at the end of each character. Figure 5.5 shows the start bit as a low logic
level and the stop bit as a high logic level. Thus the receiver can detect the start bit
and it then clocks in the next eight character bits.
25
Figure 5- 4 Frame Representation
Figure 5- 5 Framed Data including Parity
The receiver then expects to find the stop bit, existing as a logic high bit. This is a
crude form of synchronization applied to a system, which is inherently non-
synchronous. A high price is paid for this form of synchronization in terms of
bandwidth; as for every eight bits of data transmitted two bits are required to support
the framing. Ten bits are transmitted to support eight bits of data thus the scheme is, at
best, just eighty percent efficient. Figure 5.6 shows the inclusion of an additional
parity bit for error control purposes.[11]
5.2 Setting the Serial Port Mode
The first thing we must do when using the 8051.s integrated serial port is, obviously,
configure it. This lets us tell the 8051 how many data bits we want, the baud rate we
will be using, and how the baud rate will be determined. First, let's present the "Serial
Control" (SCON) SFR and define what each bit of the SFR represents:
Figure 5- 6 SCON SFR
The SCON SFR allows us to configure the Serial Port.
26
The high four bits (bits 4 through 7) are configuration bits. Bits SM0 and SM1 let us
set the serial mode to a value between 0 and 3, inclusive. The four modes are defined
in the chart immediately above. As you can see, selecting the Serial Mode selects the
mode of operation (8-bit/9-bit, UART or Shift Register) and also determines how the
baud rate will be calculated. In modes 0 and 2 the baud rate is fixed based on the
oscillator's frequency. In modes 1 and 3 the baud rate is variable based on how often
Timer 1 overflows. The bit SM2 is a flag for "Multiprocessor communication."
Generally, whenever a byte has been received the 8051 will set the "RI" (Receive
Interrupt) flag. The bit REN is "Receiver Enable." This bit is very straightforward: If
you want to receive data via the serial port, set this bit. The low four bits (bits 0
through 3) are operational bits. They are used when actually sending and receiving
data--they are not used to configure the serial port. TI means "Transmit Interrupt."
When a program writes a value to the serial port, a certain amount of time will pass
before the individual bits of the byte are "clocked out" the serial port. The RI bit
means "Receive Interrupt." It functions similarly to the "TI" bit, but it indicates that a
byte has been received.
5.3 Setting the Serial Port Baud Rate
Once the Serial Port Mode has been configured, as explained above, the program
must configure the serial port's baud rate. This only applies to Serial Port modes 1 and
3. In modes 0 and 2, the baud rate is determined based on the oscillator's frequency
and no additional configuration is necessary. In mode 0, the baud rate is always the
oscillator frequency divided by 12.
In modes 1 and 3, the baud rate is determined by how frequently timer 1 overflows.
The more frequently timer 1 overflows, the higher the baud rate. There are many ways
one can cause timer 1 to overflow at a rate that determines a baud rate but the most
common method is to put timer 1 in 8-bit auto-reload mode (timer mode 2) and set a
reload value (TH1) that causes Timer 1 to overflow at a frequency appropriate to
generate a baud rate.
To determine the value that must be placed in TH1 to generate a given baud rate, we
may use the following equation (assuming PCON.7 is clear).
TH1 = 256 - ((Crystal / 384) / Baud)
27
If PCON.7 is set then the baud rate is effectively doubled, thus the equation becomes:
TH1 = 256 - ((Crystal / 192) / Baud)
For example, if we have an 11.059Mhz crystal and we want to configure the serial
port to 19,200 baud we
try plugging it in the first equation:
TH1 = 256 - ((Crystal / 384) / Baud)
TH1 = 256 - ((11059000 / 384) / 19200)
TH1 = 256 - ((28,799) / 19200)
TH1 = 256 - 1.5 = 254.5
As one can see, to obtain 19,200 baud with an 11.059Mhz crystal we'd have to set
TH1 to 254.5. If we set it to 254 we will have achieved 14,400 baud and if we set it to
255 we will have achieved 28,800 baud. 5.4 Writing to the Serial Port
Once the serial port has been properly configured as explained above, the serial port is
ready to be used to send and receive data. To write a byte to the serial port one must
simply write the value to the SBUF (99h) SFR. For example, if you want to send the
value contained in variable a to the serial port, it could be accomplished as easily as:
SBUF=a; // Suppose a has the value to be sent
5.5 Reading from the Serial Port
Reading data received by the serial port is equally easy. To read a byte from the serial
port one just needs to read the value stored in the SBUF (99h) SFR after the 8051 has
automatically set the RI flag in SCON. The following code segment may be used:
a=SBUF;
Always set TI flag manually out side the interrupt coding for automatic occurrence of
Serial Interrupt i.e.
TI=1.
In our project we do serial communication with pc through RS232.
28
5.6 Serial Communication of PC (using Hyper Terminal)
In personal computer the serial communication is mostly done with COM
ports. There are several COM ports in PC, but only COM1 is used now a days. The
prototype is developed using Windows® environment. The program used for serial
communication in Windows® is Hyper Terminal.
5.6.1 Hyper Terminal:
It is a program that is present in the Windows for serial communication. The
print screen of Hyper Terminal are shown in figure 5.10 and figure 5.11
Figure 5- 7 Selection Com port
Figure 5- 8 Setting the data rate
29
It can be seen that the COM1 port is used for serial communication. There are some
parameters in figure 5.7, which needs to be set before starting the serial
communication. These parameters are.
5.6.1.1 Baud rate:
It is the number of discrete signals transferred per second.
5.6.1.2 Start bit:
It is used to show the receiving end about the incoming data, this bit is used.
It is usually a ‘space’ or binary 0.
5.6.1.3 Stop bit:
To notify the receiving end about the end of data this bit is used. It is a ‘mark’
or binary ‘1’. Stop bits sent at the end of every character allow the receiving signal
hardware detect the end of a character and to resynchronise with the character stream.
Electronic devices usually use one stop bit. Occasionally, and especially if slow
electromechanical devices are used, such as teleprinters, one-and-one half or two stop
bits are required. A stop bit is a way to indicate the end of a byte of data.
5.6.1.4 Parity bit:
Parity is a method of detecting some errors in transmission. Where parity is
used with a serial port, an extra data bit is sent with each data character, arranged so
that the number of 1 bits in each character, including the parity bit, is always odd or
always even. If a byte is received with the wrong number of 1 bits, then it must have
been corrupted. If parity is correct there may have been no errors or an even number
of errors. Electromechanical teleprinters were arranged to print a special character
when received data contained a parity error, to allow detection of messages damaged
by line noise. A single parity bit does not allow implementation of error correction on
each character, and communication protocols working over serial data links will have
higher-level mechanisms to ensure data validity and request retransmission of data
that has been incorrectly received.
5.6.1.5 Frame:
Start bit , 8 bit Data , Parity bit , Stop bit
30
After setting all these parameters, the communication is started and the following
window opens.
Figure 5- 9 The HyperTerminal window
Rest of the serial communication is held using this window. Anything received can be
viewed in this window.
5.7 The RS-232
5.7.1 Introduction
The ‘RS-232’ standard includes details of:
1. The protocol to be used for data transmission.
2. The voltages to be used on the signal lines.
3. The connectors to be used to link equipment together.
RS-232 is a peer-to-peer communication standard.RS-232 is intended to link only two
devices together.
Old PC's used 25 pin connectors but only about 9 pins were actually used so today
most connectors are only 9-pin. Each of the 9 pins usually connects to a wire. Besides
the two wires used for transmitting and receiving data, another pin (wire) is signal
ground. The voltage on any wire is measured with respect to this ground. Thus the
minimum number of wires to use for 2-way transmission of data is 3. Except that it
31
has been known to work with no signal ground wire but with degraded performance
and sometimes with errors.
RS-232 is a byte-oriented protocol. That is, it is intended to be used to send single 8-
bit blocks of data. To transmit a byte of data over an RS-232 link, we generally
encode the information as follows: We send a ‘Start’ bit. We send the data (8 bits).
We send a ‘Stop’ bit (or bits).
5.7.2 Rules of communication using RS232
RS-232 uses an asynchronous protocol. This means that no clock signal is sent with
the data. Instead, both ends of the communication link have an internal clock,
running at the same rate. The data (in the case of RS-232, the ‘Start’ bit) is then used
to synchronize the clocks, if necessary, to ensure successful data transfer.
5.7.3 Baud rates for RS232
RS-232 generally operates at one of a (restricted) range of baud rates. Typically these
are: 75, 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 33600, 56000,
115000 and (rarely) 330000 baud.
RS-232 is often used with some form of flow control. Although hardware
handshaking can be used, this requires extra signal lines. he most common flow
control technique is ‘Xon / Xoff’ control. This requires a alf- or full-duplex
communication link, and can operate as follows:
1. Transmitter sends a byte of data.
2. The receiver is able to receive more data: it does nothing.
3. The transmitter sends another byte of data.
Steps 1–3 continue until the receiver cannot accept any more data:
it then sends a ‘Control s’ (Xoff) character back to the transmitter. The transmitter
receives the ‘Xoff’ command and pauses the data transmission. When the receiver
node is ready for more data, it sends a ‘Control q’ (Xon) character to the transmitter.
The transmitter resumes the data transmission.
This port is full duplex, meaning it can transmit and receive simultaneously. It is also
receive-buffered, meaning it can commence reception of a second byte before a
32
previously received byte has been read from the receive register. (However, if the first
byte still has not been read by the time reception of the second byte is complete, one
of the bytes will be lost.)
5.7.4 Modes of Communication used by RS232
The serial port can operate in four modes
5.7.4.1 Synchronous mode
5.7.4.2 Three asynchronous modes
In our system one is primarily interested in Mode 1. In this mode, 10 bits are
transmitted (through TxD) or received (through RxD): a start bit
(0), 8 data bits (least-significant bit first), and a stop bit (1).
One must note that the serial interface may also provide interrupt requests when
transmission or reception of a byte has been completed.
5.7.5 Serial port registers
The serial port control and status register is the special function register SCON. This
register contains the mode selection bits (and the serial port flags, TI and RI). SBUF
is the receive and transmit buffer for the serial interface. Writing to SBUF loads the
transmit register and initiates transmission. Reading from SBUF accesses a physically
separate receives register.
5.8 Checking our operations on data
Some important applications of RS-232 in embedded systems include the following:
To program on-chip flash memory (for testing or low-volume production), several
8051 devices use the serial port. This can also be an important means of performing
code upgrades to devices in the field. Many developers use RS-232 during system
development, in order to communicate between desktop PCs (on which code is
developed) and prototype boards(on which the code is tested).
33
6 LCD Interfacing and Programming One of the most common devices attached to an 8051 is an LCD display. Some of the
most common LCDs connected to the 8051 are 16x2 and 20x2 displays. This means
16 characters per line by 2 lines and 20 characters per line by 2 lines, respectively.
Fortunately, a standard exists which allows us to communicate with the vast majority
of LCDs regardless of their manufacturer. The standard is referred to as HD44780U,
which refers to the controller chip which receives data from an external source (in this
case, the 8051) and communicates directly with the LCD.
6.1 44780 BACKGROUND
The 44780 standard requires 3 control lines as well as either 4 or 8 I/O lines for the
data bus. The user may select whether the LCD is to operate with a 4-bit data bus or
an 8-bit data bus. If a 4-bit data bus is used the LCD will require a total of 7 data lines
(3 control lines plus the 4 lines for the data bus). If an 8-bit data bus is used the LCD
will require a total of 11 data lines (3 control lines plus the 8 lines for the data bus).
The three control lines are referred to as EN, RS, and RW.
The EN line is called "Enable." This control line is used to tell the LCD that you are
sending it data. To send data to the LCD, your program should make sure this line is
low (0) and then set the other two control lines and/or put data on the data bus. When
the other lines are completely ready, bring EN high (1) and wait for the minimum
amount of time required by the LCD datasheet (this varies from LCD to LCD), and
end by bringing it low (0) again. [13]
The RS line is the "Register Select" line. When RS is low (0), the data is to be treated
as a command or special instruction (such as clear screen, position cursor, etc.). When
RS is high (1), the data being sent is text data which should be displayed on the
screen. For example, to display the letter "T" on the screen you would set RS high.
The RW line is the "Read/Write" control line. When RW is low (0), the information
on the data bus is being written to the LCD. When RW is high (1), the program is
effectively querying (or reading) the LCD. Only one instruction ("Get LCD status") is
a read command. All others are write commands--so RW will almost always be low.
34
Figure 6- 1 Displaying Data on LCD
6.2 HANDLING THE EN CONTROL LINE
As we mentioned above, the EN line is used to tell the LCD that you are ready for it
to execute an instruction that you've prepared on the data bus and on the other control
lines. Note that the EN line must be raised/lowered before/after each instruction sent
to the LCD regardless of whether that instruction is read or write, text or instruction.
In short, you must always manipulate EN when communicating with the LCD. EN is
the LCD's way of knowing that you are talking to it. If you don't raise/lower EN, the
LCD doesn't know you're talking to it on the other lines.
CLR EN
And once we've finished setting up our instruction with the other control lines and
data bus lines, we'll always bring this line high:
SETB EN
The line must be left high for the amount of time required by the LCD as specified in
its datasheet. This is normally on the order of about 250 nanoseconds, but check the
datasheet. In the case of a typical 8051 running at 12 MHz, an instruction requires
1.08 microseconds to execute so the EN line can be brought low the very next
instruction. However, faster microcontrollers (such as the DS89C420 which executes
an instruction in 90 nanoseconds given an 11.0592 Mhz crystal) will require a number
of NOPs to create a delay while EN is held high. The number of NOPs that must be
35
inserted depends on the microcontroller you are using and the crystal you have
selected.[14]
6.3 How to Configure LCD
As we've mentioned, the LCD requires either 8 or 11 I/O lines to communicate with.
For the sake of this tutorial, we are going to use an 8-bit data bus--so we'll be using 11
of the 8051's I/O pins to interface with the LCD.
Let's draw a sample psuedo-schematic of how the LCD will be connected to the 8051.
As one can see, we've established a 1-to-1 relation between a pin on the 8051 and a
line on the 44780 LCD. Thus as we write our assembly program to access the LCD,
we are going to equate constants to the 8051 ports so that we can refer to the lines by
their 44780 name as opposed to P0.1, P0.2, etc.
6.4 Initializing the Lcd
Before you may really use the LCD, you must initialize and configure it. This is
accomplished by sending a number of initialization instructions to the LCD.
The first instruction we send must tell the LCD whether we'll be communicating with
it with an 8-bit or 4-bit data bus. We also select a 5x8 dot character font. These two
options are selected by sending the command 38h to the LCD as a command. As you
will recall from the last section, we mentioned that the RS line must be low if we are
sending a command to the LCD.
The last byte need to be send is used to configure additional operational parameters of
the LCD. One must send the value 06h.
CLR RS
MOV DATA,#06h
SETB EN
CLR EN
LCALL WAIT_LCD
So, in all, initialization code is as follows:
INIT_LCD:
36
CLR RS
MOV DATA,#38h
SETB EN
CLR EN
LCALL WAIT_LCD
CLR RS
MOV DATA,#0Eh
SETB EN
CLR EN
LCALL WAIT_LCD
CLR RS
MOV DATA,#06h
SETB EN
CLR EN
LCALL WAIT_LCD
RET
Having executed this code the LCD will be fully initialized and ready for us to send
display data to it.
6.5 Clearing the Display
When the LCD is first initialized, the screen should automatically be cleared by the
44780 controller. However, it's always a good idea to do things manually so that one
can be completely sure that the display is the way he wants it. Thus, it's not a bad idea
to clear the screen as the very first operation after the LCD has been initialized.
An LCD command exists to accomplish this function. Not surprisingly, it is the
command 01h. Since clearing the screen is a function one very likely will wish to call
more than once, it's a good idea to make it a subroutine:
CLEAR_LCD:
37
CLR RS
MOV DATA,#01h
SETB EN
CLR EN
LCALL WAIT_LCD
RET
How that one has written a "Clear Screen" routine, he may clear the LCD at any time
by simply executing an
LCALL CLEAR_LCD.
6.6 Writing Text to the LCD
Now after getting to the real meat of what one is trying to do: All this effort is really
so he can display text on the LCD.
Once again, writing text to the LCD is something one almost certainly want to do over
and over--so let's make it a subroutine.
WRITE_TEXT:
SETB RS
MOV DATA,A
SETB EN
CLR EN
LCALL WAIT_LCD
RET
The WRITE_TEXT routine that is given above will send the character in the
accumulator to the LCD which will, in turn, display it. Thus to display text on the
LCD all he needs to do is load the accumulator with the byte to display and make a
call to this routine.
38
6.7 CURSOR POSITIONING
The above "Hello World" program is simplistic in the sense that it prints its text in
the upper left-hand corner of the screen. However, what if we wanted to display the
word "Hello" in the upper left-hand corner but wanted to display the word "World" on
the second line at the tenth character? This sounds simple--and actually, it is simple.
However, it requires a little more understanding of the design of the LCD.
The 44780 contains a certain amount of memory which is assigned to the display. All
the text we write to the 44780 is stored in this memory, and the 44780 subsequently
reads this memory to display the text on the LCD itself. This memory can be
represented with the following "memory map":
In the above memory map, the area shaded in blue is the visible display. As you can
see, it measures 16 characters per line by 2 lines. The numbers in each box is the
memory address that corresponds to that screen position.
Thus, the first character in the upper left-hanad corner is at address 00h. The
following character position (character #2 on the first line) is address 01h, etc. This
continues until we reach the 16th character of the first line which is at address 0Fh.
However, the first character of line 2, as shown in the memory map, is at address
40h. This means if we write a character to the last position of the first line and then
write a second character, the second character will not appear on the second line. That
is because the second character will effectively be written to address 10h--but the
second line begins at address 40h.
Thus we need to send a command to the LCD that tells it to position the cursor on the
second line. The "Set Cursor Position" instruction is 80h. To this we must add the
address of the location where we wish to position the cursor. In our example, we said
we wanted to display "World" on the second line on the tenth character position.
Referring again to the memory map, we see that the tenth character position of the
second line is address 4Ah. Thus, before writing the word "World" to the LCD, we
must send a "Set Cursor Position" instruction--the value of this command will be 80h
(the instruction code to position the cursor) plus the address 4Ah. 80h + 4Ah = CAh.
Thus sending the command CAh to the LCD will position the cursor on the second
line at the tenth character position: [14]
39
CLR RS
MOV DATA,#0CAh
SETB EN
CLR EN
LCALL WAIT_LCD
The above code positions the cursor on line 2, character 10. To display "INTEL" in
the upper left-hand corner with the word "LIGENT" on the second line at character
position 10 just requires us to insert the above code into our existing program.
40
7 References [1] www.freepatents.com/rfid
[2] Dargan, Gaurav; Johnson, Brian; Panchalingam, Mukunthan; Stratis, Chris
(2004). The Use of Radio Frequency Identification as a Replacement for Traditional
Barcoding. Retrieved on 2006-05-31. www.patentsstorm.us/patents/5310999.html
[3] http://www.rfidjournal.com/
[4] http://www.vlf.it/frequency/bands.html
[5] http://www.8052.com/tutorial.phtml
[6] http://www.8052.com/tutmemory.phtml
[7],[8] http://www.8052.com/tutorial.phtml
[9] Electronics Industries Association, "EIA Standard RS-232-C Interface
Between Data Terminal Equipment and Data Communication Equipment Employing
Serial Data Interchange", August 1969, reprinted in Telebyte Technology Data
Communication Library, Greenlawn NY, 1985, no ISBN
[10] http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
[11] PC 97 Hardware Design Guide. Redmond,Washington, USA: Microsoft Press.
ISBN 1-57231-381-1.
[12] http://en.wikipedia.org/wiki/RS-232
[13] LIQUID GOLD, “The Story of Liquid Crystal Displays and the Creation of an
Industry”, 2005 World Scientific Publishing Co. Pte. Ltd., ISBN 981-238-956-3
[14] M.A. Mazidi. “ 8051 Microcontroller & Embedded Systems” 2nd edition.
41
Appendix A
Main Code #include <At89x51.h>
sbit Red = P2^0;
sbit Green = P2^4;
extern void wait_lcd(void);
extern void clr_lcd(void);
extern void init_lcd(void);
extern void cur_pos(unsigned char);
extern void wrt_char(unsigned char);
extern void Send2LCD(unsigned char *, unsigned char);
struct Car
unsigned char Name[21];
unsigned char ID[16];
unsigned char Reg[7];
unsigned char Eng[8];
unsigned char Chasis[16];
unsigned char Modal[5];
;
code struct Car Poll[8] =
"Rafique Waraich ",
"61101-4539191-1", "LA-202", "X501201", "NZE 128-6040518", "2007"
,
"Wasif Shah ",
"61102-4535675-1", "LE-002", "X234540", "NZE 127-6432567", "2006"
42
,
"Kamran Akmal
", "61101-4543216-1", "KH-122", "X501202", "NZE 126-6040518", "2005"
,
"Wahid Akhtar ",
"31101-4432191-1", "FG-232", "X501203", "NZE 125-6040518", "2004"
,
"Sardar Asif ",
"63401-4534781-1", "FD-452", "X501204", "NZE 124-6040518", "2003"
,
"Rana Shafique ",
"43101-4556791-1", "RA-672", "X501205", "NZE 123-6040518", "2002"
,
"Saleem Malik ",
"23101-4532191-1", "YU-382", "X501206", "NZE 122-6040518", "2001"
,
"Shahid Raza ",
"41101-4567191-1", "JH-245", "X501207", "NZE 121-6040518", "2006"
;
char RFlag;
char TFlag;
char SrlDataIn;
43
sbit TRPin = P2^7;
// 1200 baud @24MHz.
void InitSerial (void)
SCON = 0x50; // mode 1: 8-bit UART, enable receiver
TMOD |= 0x20; // timer 1 mode 2: 8-Bit reload // TMOD = TMOD | 0X20
TH1 = 0xcc; // reload value 1200 baud, 256 - (Crystal/384)/BaudRate)
EA = 1; // Enable all interupts.
ES = 1; // enable serial port interrupt
TR1 = 1; // timer 1 run
SerialInt(void) interrupt 4
if(RI)
RI = 0;
RFlag = 1;
SrlDataIn = SBUF;
if(TI || TFlag)
TI = 0;
TFlag = 1;
44
void InitTimer0()
TMOD &= 0xfe; //Set Timer 0 as
TMOD |= 0x02; // 8 bit auto reload timer
//TH0 = 0xe6; // for 76000 ticks per second.
TH0 = 230; // for 76000 ticks per second.
EA = 1; // Enable all interupts.
ET0 = 1; // Enable Timer 1 interrupt.
void Timer0() interrupt 1
TRPin = ~TRPin;
void SendChar(unsigned char Byte)
TFlag = 0;
SBUF = Byte;
while(!TFlag)
if(P3_1)
TR0 = 0;
TRPin = 1;
else
TR0 = 1;
45
TR0 = 0;
TRPin = 1;
//end void SendChar(unsigned char ch)
void SendData(unsigned char n)
unsigned char i;
for(i = 0; i < 20; i++)
SendChar(Poll[n].Name[i]);
for(i = 0; i < 15; i++)
SendChar(Poll[n].ID[i]);
for(i = 0; i < 6; i++)
SendChar(Poll[n].Reg[i]);
for(i = 0; i < 7; i++)
SendChar(Poll[n].Eng[i]);
for(i = 0; i < 15; i++)
SendChar(Poll[n].Chasis[i]);
for(i = 0; i < 4; i++)
SendChar(Poll[n].Modal[i]);
Red = 1;
Green = 1;
//end SendData
46
void Delay()
unsigned int i, j;
for(j = 0; j < 10; j++)
for(i = 0; i < 30000;)
i++;
void main()
unsigned char Number;
bit bFlag = 0;
InitSerial();
InitTimer0();
init_lcd();
Send2LCD(" WELCOME ", 0);
Send2LCD(" car Track Sys", 64);
while(1)
//Button one
if(P1 == 0xfe)
Green = 0;
SendData(0);
SendData(0);
SendData(0);
47
Number = 0;
bFlag = 1;
//Button two
if(P1 == 0xfd)
Green = 0;
SendData(1);
SendData(1);
SendData(1);
Number = 1;
bFlag = 1;
//Button three
if(P1 == 0xfb)
Green = 0;
SendData(2);
SendData(2);
SendData(2);
Number = 2;
bFlag = 1;
//Button four
if(P1 == 0xf7)
Green = 0;
SendData(3);
SendData(3);
48
SendData(3);
Number = 3;
bFlag = 1;
//Button five
if(P1 == 0xef)
Red = 0;
SendData(4);
SendData(4);
SendData(4);
Number = 4;
bFlag = 1;
//Button six
if(P1 == 0xdf)
Red = 0;
SendData(5);
SendData(5);
SendData(5);
Number = 5;
bFlag = 1;
//Button seven
if(P1 == 0xbf)
Red = 0;
SendData(6);
49
SendData(6);
SendData(6);
Number = 6;
bFlag = 1;
//Button eight
if(P1 == 0x7f)
Red = 0;
SendData(7);
SendData(7);
SendData(7);
Number = 7;
bFlag = 1;
////Display on LCD
if(bFlag)
clr_lcd();
Send2LCD("Owner's Name:", 0);
Send2LCD(Poll[Number].Name, 64);
Delay();
clr_lcd();
Send2LCD("ID Number:", 0);
Send2LCD(Poll[Number].ID, 64);
Delay();
50
clr_lcd();
Send2LCD("Registration #:", 0);
Send2LCD(Poll[Number].Reg, 64);
Delay();
clr_lcd();
Send2LCD("Engine #:", 0);
Send2LCD(Poll[Number].Eng, 64);
Delay();
clr_lcd();
Send2LCD("Chasis #:", 0);
Send2LCD(Poll[Number].Chasis, 64);
Delay();
clr_lcd();
Send2LCD("Modal #:", 0);
Send2LCD(Poll[Number].Modal, 64);
Delay();
//end if bFlag
//end while 1
//end main
LCD #include<At89x52.h> sbit EN = P2^3; //Pin 6 sbit RW = P2^2; //pin 5 sbit RS = P2^1; //pin 4 void wait_lcd() int set, cnt;
51
set = 1; cnt = 0; EN = 1; RS = 0; RW = 1; P0 = 255; while(set) cnt++; if(P0_7 == 0) set = 0; cnt = 0; //end if else if(cnt == 255) P0_7 = 0; //end while EN = 0; RW = 0; //end wait lcd void clr_lcd() EN = 1; RS = 0; P0 = 1; EN = 0; wait_lcd(); //end clear lcd void init_lcd() //entry mode set EN = 1; RS = 0; P0 = 0x06; EN = 0; wait_lcd(); //Display On/Off EN = 1; RS = 0; P0 = 0x0f; EN = 0; wait_lcd(); //Function Set EN = 1;
52
RS = 0; P0 = 0x38; EN = 0; wait_lcd(); void cur_pos(unsigned char cp) EN = 1; RS = 0; P0 = 128 + cp; EN = 0; wait_lcd(); //end cursor position void wrt_char(unsigned char ch) EN = 1; RW = 0; RS = 1; P0 = ch; EN = 0; wait_lcd(); void Send2LCD(unsigned char *Msg, unsigned char cp) unsigned char index; cur_pos(cp); for(index = 0; *(Msg + index) != '\0'; index++) wrt_char(*(Msg + index)); cp++; if(cp == 16) cp = 64; cur_pos(cp); //end send 2 lcd
Top Related