Professional Documents
Culture Documents
GPS Based Navigation System A Project Re
GPS Based Navigation System A Project Re
A PROJECT REPORT
Submitted by
of
BACHELOR OF ENGINEERING
IN
APRIL 2006
ANNA UNIVERSITY: CHENNAI 600 025
BONAFIDE CERTIFICATE
Certified that this project report “GPS BASED NAVIGATION SYSTEM” is the
It is our great pleasure to express our deep sense of gratitude and indebtedness to Mr. C.
Vaithilingam and Mr. R. Chandramohan, our project guides, for their invaluable guidance
and constant encouragement throughout this project. Their critical appraisal of the work
done and valuable suggestions, in spite of their busy official schedule, have always been a
source of inspiration and motivation to complete the project.
We are also thankful to Sands Instrumentation Pvt. Ltd., Ashok Nagar, Chennai, and its
Head of Training Division, Mr. A.P. Sundar, for providing us facilities for carrying out the
project work. Our special thanks and gratitude are due to Mr. R. Francis Rajesh, Project
Guide at Sands Instrumentation, for providing the required support and guidance
throughout the project work.
We also thank the Professor R.Chidambaram, professor and head, Department of Electrical
Engineering, faculty and staff of the Department of Electrical Engineering, SRM
Engineering College, for all the help and encouragement given to us during the course of the
project work.
Anish Kumar, P.
Balajee, T.
Divya, G.
Kannan, N.
ABSTRACT
The GPS based navigation system aims at building a GPS reception system which can be
A GPS reception system consists of a GPS antenna, a GPS receiver, an UART (Universal
Once the reception system hardware has been set up, the GPS receiver is synchronized with
the satellites. After this, data is obtained by the microcontroller from the satellites through
the GPS receiver using the UART. This data is then manipulated to extract desired data
Using the GPS reception system, the current location is given to a Visual Basics program. A
target location is also keyed in. Comparing these two, control signals are given to a toy car to
LIST OF FIGURES
FIGURE NO TITLE PAGE
TABLE OF CONTENTS
ABSTRACT iv
LIST OF TABLE v
LIST OF FIGURES vi
1 INTRODUCTION 1
9 PROGRAMS 57
9.1 PIC 18F452 PROGRAM 57
9.2 VISUAL BASIC PROGRAM 75
10 CONCLUSION 82
REFERENCES 91
1: INTRODUCTION
The GPS based navigation system is used to obtain positional information, date and time
from the GPS satellites in orbit. The motives for using a GPS as a means for achieving these
purposes are:
• Using GPS, we can obtain one’s exact location (longitude, latitude and height co-
ordinates) accurate to within a range of 20 m to approximately 1mm.
• Using GPS, we can obtain the precise (Universal Time Coordinated, UTC)
accurate to within a range of 60ns to approximately 5ns.
The reason for the highly accurate time obtainable from the GPS is the presence of atomic
clocks on the GPS satellites. Atomic clocks are currently the most precise instruments
known, losing a maximum of one second every 30,000 to 1,000,000 years.
In this project, using this highly accurate positional data, a target location is tracked by a toy
car. This is done by comparison of current position (latitude and longitude) with the target
position (latitude and longitude). Thus tracking of a target location with a very high degree
of accuracy can be achieved.
The Global Positioning System (GPS) is a space based navigation system developed and
operated by the United States government which is used to establish a position at any point
on the globe.
GPS (the full description is: NAVigation System with Timing And Ranging Global
Positioning System- NAVSTAR-GPS) was developed by the US Department Of Defense
(DoD) and can be used by both civilian and military personnel. The civil signal SPS
(Standard Positioning Service) can be used freely by the general public, whilst the military
signal PPS (Precise Positioning Service) can only be used by authorized government
agencies. The first satellite was placed into orbit on 22nd February 1978, and there are
currently 28 operational satellites orbiting the Earth at a height of 20,180km on six different
orbital planes. Their orbits are inclined at 55° to the equator, ensuring that at least four
satellites are in radio communication with any point on the planet. Each satellite orbits the
Earth in approximately 12 hours and has four atomic clocks on board.
In order to calculate one’s exact position, all that needs to be measured is the signal transit
time between the point of observation and four different satellites whose positions are
known.
2.2 GENERATING GPS SIGNAL TRANSIT TIME
28 satellites inclined at 55º to the equator orbit the earth every 11 hours and 58 minutes at a
height of 20,180 km on 6 different orbital planes.
Each one of these satellites has up to four atomic clocks on board. Each satellite transmits
its exact position and it’s precise on board time to earth at a frequency of 1575.42 MHz.
These signals are transmitted at the speed of light (3,00,000Km/s) and therefore require
approximately 67.3ms to reach a position on the Earth’s surface located directly below the
satellite. The signals require an extra 3.33 micro seconds for every excess kilometer of travel.
If we wish to establish our position on land (or at sea or in the air), all we require is an
accurate clock. By comparing the arrival time of the satellite signal with the onboard clock
time the moment the signal was emitted, it is possible to determine the transit time of that
signal.
Fig 2.1: Determining the transit time
The distance ‘S’ to the satellite can be determined using the known signal transit time‘t’:
Measuring signal transit time and knowing the distance to a satellite is still not enough to
calculate one’s position in 3-D space. To achieve this four independent time measurements
are required. Hence signal communication with four different satellites is needed to calculate
one’s exact position.
Let us imagine that two satellites are orbiting far above us transmitting their on board clock
times and their positions. By using the signal transit time to both satellites, we can draw two
circles with radii S1 and S2 around the satellites. Each radius corresponds to the distance
calculated to the satellite. All possible distances are located on the circumference of the
circle. If the position above the satellite is excluded, the location of the receiver is at the
exact point where the two circles intersect beneath the satellites.
In reality, a position has to be determined in three dimensional space, rather than on a plane.
As the difference between a plane and three-dimensional space consists of an extra
dimension height z), an additional third satellite must be available to determine the true
position.
If the distance to the three satellites is known, all possible positions are located on the
surface of the three spheres whose radii correspond to the distance calculated. The position
sought is the point where all three surfaces of the spheres intersect.
All statements made so far will only be valid, if the terrestrial clock and the atomic clocks on
board the satellites are synchronized, i.e. signal transit time can be accurately determined.
For the receiver to measure time precisely, a highly accurate, synchronized clock is needed. If
the transit time is out by just 1 micro second, this produces a positional error of 300m. As
the clocks on board all three clocks are synchronized, the transit time in the case of all three
measurements is inaccurate by the same amount. When producing calculations, if N
variables are unknown, we need N independent equations.
If the time measurement is accompanied by a constant unknown error, we will have four
unknown variables in 3-D space:
1. Longitude (X)
2. Latitude (Y)
3. Altitude (Z)
4. Time Error (∆t)
It therefore follows that in three-dimensional space, four satellites are needed to
determine a position.
.
Fig 2.2: Four satellites are required to determine a position in 3-D space
Satellite movement
The space segment currently consists of 28 operational satellites orbiting the Earth on six
different orbital planes (four to five satellites per plane). They orbit at a height of 20,180km
above the earth’s surface and are inclined at 55º to the equator. Any one satellite completes
its orbit in around 12 hours. Due to the rotation of the Earth, a satellite will be at its initial
starting position after approximately 24 hours.
Satellite signals
The following information (navigation message) is transmitted by the satellite at the rate of
50 bits per second.
• Satellite time and synchronization signals
• Precise orbital data (Ephemeris)
• Time correction information to determine the exact satellite time
• Correction signals to calculate signal transit time
• Data on the ionosphere
• Information on the satellite health
Each of the 28 satellites transmits a unique signature assigned to it. The signature consists of
an apparent random sequence (Pseudo Random Noise code, PRN) of 1023 zeros and ones.
The control segment (Operational Control System OCS) consists of a master control station
located in the state of Colorado, five monitor stations equipped with atomic clocks that are
spread around the globe in the vicinity of the equator, and three ground control stations that
transmit information to the satellites.
The most important tasks of the control segment are:
• Observing the movement of the satellites and computing orbital data (ephemeris)
• Monitoring the satellite clocks and predicting their behaviour
• Synchronizing on board satellite time
• Relaying precise orbital data received from satellites in communication
• Relaying the approx. orbital data of all satellites (almanac)
• Relaying further information including satellite health, clock errors etc.
Four different signal are generated in the receiver having the same structure as those
received from the four satellites. By synchronizing the signals
Fig 2.6: Measuring signal transit times
generated in the receiver with those from the satellites, the four satellite signal time shifts ∆t
are measured as a timing mark.
The measured time shifts of all four satellite signals are used to determine signal transit time.
The relevant distance to the satellites is determined by the transit time of the signals. The
receiver then calculates the user’s latitude, longitude, altitude and time from the range and
known position of the four satellites.
GPS modules have to evaluate weak antenna signals from at least four satellites, in order to
determine a correct three dimensional position. The signals received (1575.42 MHz) are pre-
amplified and transformed to a lower intermediate frequency. The reference oscillator
provides the necessary carrier wave for frequency conversion, along with the necessary clock
frequency for the processor and correlator. The analog intermediate frequency is converted
into a digital signal by means of a 2-bit ADC.
Fig 2.7:
Signal transit time from the satellites to the receiver is ascertained by correlating PRN pulse
sequences. The satellite PRN code must be used to determine this time, otherwise there is
no correlation maximum. Data is recovered by mixing it with the correct PRN sequence. At
the same time, the useful signal is amplified above the interference level. Up to sixteen
satellite signals are processed simultaneously. The control and generation of PRN sequences
and the recovery of data is carried out by a signal processor. Calculating and saving the
position, including the variables derived from this, is carried out by a processor with memory
facility.
GPS aided navigation and positioning can be used in many sectors of the economy, as well
as in science, technology, tourism, research and surveying. The GPS process can be
employed wherever three-dimensional geodata has a significant role to play. A few important
sectors are detailed below:
GPS provides us with the opportunity of measuring time exactly on a global basis. Right
around the world “time” (UTC Universal Time Co-coordinated) can be accurately
determined to within 1-60ns. Measuring time with GPS is a lot more accurate than with
so-called radio clocks.
3.1 INTRODUCTION
The navigation message is a continuous stream of data transmitted at 50 bits per second.
Each satellite relays the following information to the Earth:
The navigation message is needed to determine the current position of the satellite and to
determine signal transit times.
The data stream I modulated to the HF carrier of each individual satellite. Data is
transmitted in logically grouped units known as frames or pages. Each frame is 1500 bits
long and takes 30 seconds to transmit. The frames are divided into 5 subframes. Each
subframe is 300 bits long and takes 6 seconds to transmit. In order to transmit a complete
almanac, 25 different frames are required. Transmission time for the entire almanac is
therefore 12.5 minutes. A GPS receiver must have collected the complete almanac at least
once to be capable of functioning.
A frame is 1500 bits long and takes 30 seconds to transmit. The 1500 bits are divided into 5
frames each of 300 bits. Each subframe is in turn divided into 10 words each containing 30
bits. Each subframe begins with a telemetry word and a handover word (HOW). A complete
navigation message consists of 25 frames. The structure of the navigation message is
illustrated in the figure 3.1.
• Subframe 1 contains the time values of the transmitting satellites, including the
parameters for correcting signal transit delay and on board clock time, as well as
information on satellite health and an estimation of the positional accuracy of the
satellite. Subframe 1 also transmits the so-called 10-bit week number.
• Subframe 2 and 3 contain the ephemeris data of the transmitting satellite. This data
provides extremely accurate information on the satellites orbit.
• Subframe 4 contains the almanac data on satellite number 25 and further and
information regarding any measurement errors caused by the ionosphere.
• Subframe 5 contains the almanac data on satellite numbers 1 to 24. all 25 pages are
transmitted together with information on the health of the satellite numbers 1 to 24
There are two parts to building a GPS reception system. They are:
1. Synchronization
2. Data Extraction
SYNCHRONISATION
In order to obtain accurate positional and time data from the satellites, the GPS receiver
must be synchronized with the satellites. Failure to do so will result in erroneous data being
received.
The hardware setup for synchronizing the GPS receiver is very simple. We have to connect a
GPS antenna to the receiver and interface the receiver to a computer through a MAX 232
chip. Then we use the Gmonitor software to synchronize the GPS receiver with the
satellites.
GPS ANTENNA
The antenna used for reception of information from GPS satellites is the “GPS Smart
Antenna” from Leadtek Company. It has the following features:
This antenna is used to establish contact by the GPS receiver with the satellites. It has a
magnet base which helps in easy mounting. Once the antenna has been positioned
properly and connected with the GPS receiver, we can start synchronizing the GPS
receiver with the satellites through Gmonitor software.
The GPS receiver used is the “GPS-MS1E” – a fully self controlled receiver module for
Global Positioning System manufactured by SiRF technology, Inc.
GPS receivers require different signals in order to function. These variables are broadcast
after time and position have been successfully calculated. To ensure that the different types
of appliances, there are international standards for data exchange (NMEA and RTCM).
In order to relay computed GPS variables such as position, velocity, course etc to a
peripheral (e.g. computer, screen, transceiver etc), GPS receivers have a serial interface (TTL
or RS-232 level).
The most important elements of receiver information are broadcast via this interface in a
special data format. This format is standardized by the National Marine Electronics
Association (NMEA) to ensure that data exchange takes place without any problems.
Nowadays, data is relayed according to NMEA-0183 specification. NMEA has several data
sets. In our application, we make use of the RMC- Recommended Minimum Specific data
set.
RMC data set: the RMC data set contains information on time, latitude, longitude, height,
system status, speed, course and date. This data set is relayed by all GPS receivers.
$GPRMC,130304.0,A,4717.115,N,00833.912,E,000.04,205.5,200601,01.3,W*7C<R><L
F>
The function of the individual characters or character sets is explained in table 5.1:
The MAX232 has two internal charge pumps that convert +5V to ±10V (unloaded) for RS-
232 driver operation. The first converter uses capacitor C1 to double the +5V input to
+10V on C3 at the V+ output. The second converter uses capacitor C2 to invert +10V to -
10V on C4 at the V- output.
Connections:
• For the capacitor C1, the negative leg goes to pin 3 and the positive leg goes to pin 1.
• For the capacitor C2, the negative leg goes to pin 5 and the positive leg goes to pin 4.
• For the capacitor C3, the negative leg goes to 5 volts and the positive leg goes to pin
2.
• For the capacitor C4, the negative leg goes to pin 6 and the positive leg goes to
ground.
• For the capacitor C5, the negative leg goes to ground and the positive leg goes to pin
16.
The MAX232 includes 2 receivers and 2 transmitters so two serial ports can be used with
a single chip. We have used only one transmitter for this project.
The only thing left is that we need some sort of connector to connect to the serial port.
Most computers use a 9 pin DB9 male connector for Comm1 and Comm2, so a 9 pin
female connector is included for this project. We need a DB9 extension cable to make the
connection easier. There should be 3 wires soldered to the DB9 connector pins 2, 3 and 5.
Connect the wire from pin 5 of the connector to ground. Connect the wire from pin 2 of the
connector to pin 14 of the MAX232.
5.4 GMONITOR SOFTWARE
The GMonitor software is used for synchronizing the GPS receiver with the satellites. On
assembling the hardware for synchronizing, it is connected with the computer’s serial port
through a DB9 extension cable. Then the Gmonitor Software is started up. Then
$GPRMC,130304.0,A,4717.115,N,00833.912,E,000.04,205.5,200601,01.3,W*7C<R><L
F>
• If instead of the alphabet ‘A’ in the above set, we see a ‘V’, then synchronization
has not yet taken place
• Once we see the alphabet ‘V’ changing to ‘A’, we can be sure that the GPS
receiver has been synchronized with the satellites
Then we can close the GMonitor software and proceed to the extraction of relevant data
from the GPS receiver by the microcontroller.
Now that the GPS receiver is receiving valid data, we proceed to connect the GPS receiver
to the PIC18F452 microcontroller through UART16C550. Once this is accomplished, we
then proceed to display the appropriate data on an LCD.
GPS RECEIVER
The UART is designed as an 8-bit peripheral and so it provides 8-bit input and output data
buses, data_in and data_out respectively. A 3-bit address input add selects which register is
being access by the microprocessor. There are more than 8 registers and so the selection is
also based on the state of a special bit. In order to enable any read or write operation on the
registers, a “chip select” condition must be met. This condition is defined by three different
signals: cs1, cs2 and cs_n. The first two must be set at high level and the third at low level in
order for any operation to take place. A read operation is executed when the chip select
condition is met and the signal ior is 1 while ior_n is 0. Similarly, a write operation occurs
when the chip select condition is met and the signal iow is 1 while iow_n is 0.
Splitting the chip select input and the read and write strobes into several signals provides
more versatility to the module while few more gates are added to the circuitry. In this way,
the UART can be connected in a straightforward manner to different microprocessor
architectures.
6.1.1 REGISTER DESCRIPTION: The table 6.1 describes the registers of UART
Table 6.1: Registers summary
Since we use 8 bit long words, the last two bits of LCR register should be set to 1.
Bit 7 is Divisor Latch Access Bit (DLAB). This bit must be set in order to access the DLL,
DLM and PSD registers which program the division constants for the baud rate divider and
the prescaler. As these registers occupy the same locations as the THR, RHR, and IER,
DLAB must be zero to access these other registers.
6.1.2 RECEPTION
The serial data comes into the UART through the rxd pin. The Receiver Shift Register (RSR)
gets this data and converts it to parallel format. When a complete character has been
assembled it is passed to the Receiver Holding Register (RHR), where it is read from the
microprocessor. The reception of a character starts when a bit at low
6.1.3 TRANSMISSION
The transmission of data is done through the txd pin. The transmitter has a Transmitter
Holding Register (THR) to hold the data to be sent. This buffer is written from by
microprocessor. The data in the THR is passed to the Transmitter Shift Register (TSR),
which is used to serialize the character data bits. During this serialization process, the start,
stop and parity bits are
added.
Once the data has been passed to the microcontroller, it does the following functions:
• Selectively receives data only between ‘$’ and ‘*’. Thus the information between
these two bits in the RMC data set is only used.
• Extracts the required information i.e. time, latitude, longitude and date separately.
• Performs the conversion from GMT (Greenwich Meridian Time) to IST (Indian
Standard Time).
• Displays the data on an LCD in an appropriate format.
There are three memory blocks in this microcontroller. These memory blocks are:
• Program Memory
• Data RAM
• Data EEPROM
Data and program memory use separate busses, which allows for concurrent access of these
blocks.
A 21-bit program counter is capable of addressing the 2-Mbyte program memory space.
Accessing a location between the physically implemented memory and the 2-Mbyte address
will cause a read of all ’0’s (a NOP
instruction). The PIC18F452 has 32 Kbytes of FLASH memory. This means that
PIC18F452 can store up to 16K of single word instructions. The RESET vector address is at
0000h and the interrupt vector addresses are at 0008h and 0018h.
The figure 6.2 shows the Program Memory Map for PIC18F452
The program counter (PC) specifies the address of the instruction to fetch for execution.
The PC is 21-bits wide. The low byte is called the PCL register. This register is readable and
writable. The high byte is called the PCH register. This register contains the PC<15:8> bits
and is not directly readable or writable. Updates to the PCH register may be performed
through the PCLATH register. The upper byte is called PCU. This register contains the
PC<20:16> bits and is not directly readable or writable. Updates to the PCU register may be
performed through the PCLATU register. The PC addresses bytes in the program memory.
To prevent the PC from becoming misaligned with word instructions, the LSB of PCL is
fixed to a value of ’0’. The PC increments by 2 to address sequential instructions in the
program memory. The CALL, RCALL, GOTO and program branch instructions write to
the program counter directly. For these instructions, the contents of PCLATH and
PCLATU are not transferred to the program counter. The contents of PCLATH and
PCLATU will be transferred to the program counter by an operation that writes PCL.
Similarly, the upper two bytes of the program counter will be transferred to PCLATH and
PCLATU by an operation that reads PCL. This is useful for computed offsets to the PC.
The data memory is implemented as static RAM. Each register in the data memory has a 12-
bit address, allowing up to 4096 bytes of data memory. The data memory map is divided into
as many as 16 banks that contain 256 bytes each. The lower 4 bits of the Bank Select
Register (BSR<3:0>) select which
bank will be accessed. The upper 4 bits for the BSR are not implemented.
The data memory contains Special Function Registers (SFR) and General Purpose Registers
(GPR). The SFRs are used for control and status of the controller and peripheral functions,
while GPRs are used for data storage and scratch pad operations in the user’s application.
The SFRs start at the last location of Bank 15 (0xFFF) and extend downwards. Any
remaining space beyond the SFRs in the Bank may be implemented as GPRs. GPRs start at
the first location of Bank 0 and grow upwards. Any read of an unimplemented location will
read as ’0’s.
The entire data memory may be accessed directly or indirectly. Direct addressing may require
the use of the BSR register. Indirect addressing requires the use of a File Select Register
(FSRn) and a corresponding Indirect File Operand (INDFn). Each FSR holds a 12-bit
address value that can be used to access any location in the Data Memory map without
banking.
The instruction set and architecture allow operations across all banks. This may be
accomplished by indirect addressing or by the use of the MOVFF instruction. The MOVFF
instruction is a two-word/two-cycle instruction that moves a value from one register to
another. To ensure that commonly used registers (SFRs and select GPRs) can be accessed in
a single cycle, regardless of the current BSR values, an Access Bank is implemented. A
segment of Bank 0 and a segment of Bank 15 comprise the Access RAM.
The need for a large general purpose memory space dictates a RAM banking scheme. The
data memory is partitioned into sixteen banks. When using direct addressing, the BSR should
be configured for the desired bank. BSR<3:0> holds the upper 4 bits of the 12-bit RAM
address. The BSR<7:4> bits will always read ’0’s, and writes will have no effect. A MOVLB
instruction has been provided in the instruction set to assist in selecting banks. We select the
bank 0 when General purpose registers are to be used and bank 15 when special function
registers are to be used.
Indirect addressing is possible by using one of the INDF registers. Any instruction using the
INDF register actually accesses the register pointed to by the File Select Register, FSR.
Reading the INDF register itself, indirectly (FSR = 0), will read 00h. Writing to the INDF
register indirectly, results in a no operation. The FSR register contains a 12-bit address. The
INDFn register is not a physical register. Addressing INDFn actually addresses the register
whose address is contained in the FSRn register (FSRn is a
pointer). This is indirect addressing.
There are three indirect addressing registers. To address the entire data memory space (4096
bytes), these registers are 12-bit wide. To store the 12-bits of addressing information, two 8-
bit registers are required. These indirect addressing registers are:
1. FSR0: composed of FSR0H:FSR0L
2. FSR1: composed of FSR1H:FSR1L
3. FSR2: composed of FSR2H:FSR2L
In addition, there are registers INDF0, INDF1 and INDF2, which are not physically
implemented. Reading or writing to these registers activates indirect addressing, with the
value in the corresponding FSR register being the address of the data. If an instruction writes
a value to INDF0, the value will be written to the address pointed to by FSR0H:FSR0L. A
read from INDF1 reads the data from the address pointed to by FSR1H:FSR1L.
Every character from the GPS receiver is sequentially stored in registers pointed to by the
FSR register. Just by incrementing the value of the FSR register, we can access successive
memory locations where the characters received can be stored.
1 = The USART receive buffer, RCREG, is full (cleared when RCREG is read)
0 = The USART receive buffer is empty
So before transmission and reception, these two bits have to be checked to ascertain
whether the microcontroller is ready for these activities.
Depending on the device selected, there are either five ports or three ports available. Some
pins of the I/O ports are multiplexed with an alternate function from the peripheral features
on the device. In general, when a peripheral is enabled, that pin may not be used as a general
purpose I/O pin. Each port has three registers for its operation. These registers are:
• TRIS register (data direction register)
• PORT register (reads the levels on the pins of the
device)
• LAT register (output latch)
The data latch (LAT register) is useful for read-modify-write operations on the value that the
I/O pins are driving.
PORTA is a 7-bit wide, bi-directional port. The corresponding Data Direction register is
TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e.,
put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISA bit (= 0)
will make the corresponding PORTA pin an output (i.e., put the contents of the output latch
on the selected pin). Reading the PORTA register reads the status of the pins, whereas
writing to it will write to the port latch.
PORTB is an 8-bit wide, bi-directional port. The corresponding Data Direction register is
TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e., put
the corresponding output driver in a Hi-Impedance mode). Clearing a TRISB bit (= 0) will
make the corresponding PORTB pin an output (i.e., put the contents of the output latch on
the selected pin).
6.2.5.3 PORTC and TRISC Registers
PORTC is an 8-bit wide, bi-directional port. The corresponding Data Direction register is
TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e., put
the corresponding output driver in a Hi-Impedance mode). Clearing a TRISC bit (= 0) will
make the corresponding PORTC pin an output (i.e., put the contents of the output latch on
the selected pin).
PORTD is an 8-bit wide, bi-directional port. The corresponding Data Direction register is
TRISD. Setting a TRISD bit (= 1) will make the corresponding PORTD pin an input (i.e.,
put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISD bit (= 0)
will make the corresponding PORTD pin an output (i.e., put the contents of the output latch
on the selected pin)
PORTE is a 3-bit wide, bi-directional port. The corresponding Data Direction register is
TRISE. Setting a TRISE bit (= 1) will make the corresponding PORTE pin an input (i.e.,
put the corresponding output driver in a Hi-Impedance mode). Clearing a TRISE bit (= 0)
will make the corresponding PORTE pin an output (i.e., put the contents of the output latch
on the selected pin).
Thus in order to enable reception, both SPEN and CREN should be set.
Thus to enable the low speed asynchronous transmission required, TXEN is set, SYNC is
reset and RGH is also reset.
The BRG supports both the Asynchronous and Synchronous modes of the USART. It is a
dedicated 8-bit baud rate generator. The SPBRG register controls the period of a free
running 8-bit timer. In Asynchronous mode, bit BRGH (TXSTA<2>) also controls the
baud rate.
Given the desired baud rate and Fosc (Frequency of Oscillator), the nearest integer value for
the SPBRG register can be calculated using the formula:
In this mode, the USART uses standard non-return-to zero (NRZ) format (one START bit,
eight or nine data bits and one STOP bit). The most common data format is 8-bits. An on-
chip dedicated 8-bit baud rate generator can be used to derive standard baud rate frequencies
from the oscillator. The USART transmits and receives the LSB first. The USART’s
transmitter and receiver are functionally independent, but use the same data format and baud
rate. Asynchronous mode is selected by clearing bit SYNC
(TXSTA<4>).
The USART Asynchronous module consists of the following important elements:
• Baud Rate Generator
• Asynchronous Transmitter
• Asynchronous Receiver
The heart of the transmitter is the Transmit (serial) Shift Register (TSR). The shift register
obtains its data from the read/write transmit buffer, TXREG. The TXREG register is
loaded with data in software. The TSR register is not loaded until the STOP bit has been
transmitted from the previous load. As soon as the STOP bit is transmitted, the TSR is
loaded with new data from the TXREG register (if available). Once the TXREG register
transfers the data to the TSR register, the TXREG register is empty and flag bit TXIF
(PIR1<4>) is set.
1. Initialize the SPBRG register for the appropriate baud rate. If a high speed baud rate is
desired, set bit BRGH.
2. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
3. Enable the transmission by setting bit TXEN, which will also set bit TXIF.
4. Load data to the TXREG register (starts transmission).
The data is received on the RC7/RX/DT pin and drives the data recovery block. The data
recovery block is actually a high speed shifter operating at x16 times the baud rate, whereas
the main receive serial shifter operates at the bit rate or at FOSC. This mode would typically
be used in RS-232 systems.
1. Initialize the SPBRG register for the appropriate baud rate. If a high speed baud rate is
desired, set bit BRGH.
2. Enable the asynchronous serial port by clearing bit SYNC and setting bit SPEN.
3. Enable the reception by setting bit CREN.
4. Flag bit RCIF will be set when reception is complete
5. Read the 8-bit received data by reading the RCREG register.
6.3 GPS RECEIVER BOARD
Fig:
6.7
GPS
Receiver Board
6.4 PIC 18F452 MICROCONTROLLER BOARD
24. The IST is 5 hours, 30 minutes and 3 seconds ahead of GMT. So add 30 to
the value of minutes stored in the register.
I. If this value turns out to be greater than 60, increment the hour
register by 1 and decrement the minutes register by 60.
25.
I. The IST is 5 hours, 30 minutes and 3 seconds ahead of GMT. So add
5 to the value of hours stored in the register.
II. If this value turns out to be greater than 24, decrement the hour
register by 24.
26. Transmit the characters after the third comma (‘.’) till the next comma to the
third line of the LCD (after “LAT :”). This comprises the Latitude data.
27. Transmit the characters after the fifth comma (‘,’) till the next comma to the
fourth line of the LCD (after “LON :”). This comprises the longitude data.
28. END
7.2 FLOWCHART FOR DATA EXTRACTION
START
INITIALISE SERIAL
COMMUNICATION, THE UART
AND THE LCD
A
A
B
B
END
In this, the antenna is mounted on a toy car. Now the location shown by the GPS system
designed so far is the position of the car. This data is given to the Visual Basic program. A
target location is typed in the Visual Basic form. Now comparison of the current location
and target location takes place. Using a set of nine conditions, the toy car is directed to move
towards the target location by controlling it using signals from the parallel port.
This module is totally software based. Hence the Visual Basic program used is enclosed in
the following pages
9: PROGRAMS
LIST P=PIC18F452
INCLUDE"P18F452.INC"
CBLOCK 80H
SEC
RESU
RLT
MIN
HUR
R1
RG1
REG1
REG2
DAT
TEMP
NO1
NO2
NO3
NO4
NO5
NO6
CON1
CON2
HR
MN
SC
TEM
SC1
MN1
REG
COUNT
REG11
RESULT
ENDC
ORG 200H
RVReset
GOTO START
ORG 208H
RVIntH
RETFIE
ORG 218H
RVIntL
RETFIE
START
MOVLB 0
CALL SE_INIT
CALL UART_INIT
MOVLB 0F
CLRF TRISD
CLRF TRISA
MOVLW 0X06
MOVWF ADCON1
CALL LCD_INIT
MOVLB 0F
LFSR 0,0X0A0
REP
CALL UART_RECX
MOVLW '$'
CPFSEQ DAT
GOTO REP
MOVFF DAT,INDF0
MOVLB 0F
INCF FSR0L,1
MOVLB 0
RP
MOVF DAT,0
CALL UART_RECX
MOVLB 0
MOVFF DAT,INDF0
MOVLB 0F
INCF FSR0L,1
MOVLW '*'
MOVLB 0
CPFSEQ DAT
GOTO RP
MOVF DAT, 0
CALL DISP1
LFSR 0,0X0A0
GOTO REP
SE_INIT
MOVLB 0F
BSF RCSTA,SPEN
BSF RCSTA,CREN
BSF TXSTA,TXEN
BCF TXSTA,BRGH
BCF TXSTA,SYNC
MOVLW 09H
MOVWF SPBRG
RETURN
; LCD initialization
LCD_INIT
BCF PORTA,0
MOVLW 3CH
MOVWF PORTD
CALL L_SEND
MOVLW 01H
MOVWF PORTD
CALL L_SEND
MOVLW 02H
MOVWF PORTD
CALL L_SEND
MOVLW 06H
MOVWF PORTD
CALL L_SEND
MOVLW 0X0E
MOVWF PORTD
CALL L_SEND
RETURN
; Displaying data on LCD
LCD
MOVLB 0F
BSF PORTA,0
MOVWF PORTD
CALL L_SEND
RETURN
L_SEND
BSF PORTA,1
CALL DELAY
CALL DELAY
BCF PORTA,1
CALL DELAY
CALL DELAY
RETURN
; Transmission
TRANX
MOVLB 0F
MOVWF TXREG
NOP
BTFSS PIR1,TXIF
GOTO $-1
RETURN
; Reception
RECX
BTFSS PIR1,RCIF
GOTO $-1
MOVF RCREG,0
MOVLB 0
MOVWF RG1
RETURN
DISP1
CALL DISP
MOVLB 0F
BCF PORTA,0
MOVLW 0XC1
MOVWF PORTD
CALL L_SEND
LFSR 0,0X0A0
TTIME
INCF FSR0L,1
MOVF INDF0,0
MOVLB 0
MOVWF NO1
MOVLB 0F
INCF FSR0L,1
MOVF INDF0,0
MOVLB 0
MOVWF NO2
MOVLB 0F
INCF FSR0L,1
MOVF INDF0,0
MOVLB 0
MOVWF NO3
MOVLB 0F
INCF FSR0L,1
MOVF INDF0,0
MOVLB 0
MOVWF NO4
MOVLB 0F
INCF FSR0L,1
MOVF INDF0,0
MOVLB 0
MOVWF NO5
MOVLB 0F
INCF FSR0L,1
MOVF INDF0,0
MOVLB 0
MOVWF NO6
MOVLB 0F
RETURN
; Separates time data as hours, minutes and seconds and stores them in 3 registers
HMS
MOVLB 0
MOVFF NO1,CON1
MOVFF NO2,CON2
CALL ADD
MOVWF HR
MOVLW ':'
MOVLB 0
MOVFF NO3,CON1
MOVFF NO4,CON2
CALL ADD
MOVWF MN
MOVLW ':'
MOVLB 0
MOVFF NO5,CON1
MOVFF NO6,CON2
CALL ADD
MOVWF SC
RETURN
ADD
MOVLW 0X0F
ANDWF CON1,1
SWAPF CON1,1
MOVLW 0X0F
ANDWF CON2,0
ADDWF CON1,0
RETURN
NUMBER
MOVLB 0
MOVWF TEM
MOVWF REG
MOVLW 0XF0
ANDWF REG,1
SWAPF REG,0
ADDLW 30H
CALL LCD
MOVLB 0
MOVLW 0X0F
ANDWF TEM,0
ADDLW 30H
CALL LCD
RETURN
SEC_CON
MOVLB 0
MOVF SC,0
ADDLW 03H
DAW
MOVWF RESULT
MOVLW 60H
CPFSEQ RESULT
GOTO NE
MOVLW 00H
INCF MN,1
RETURN
NE
CPFSGT RESULT
GOTO NG
INCF MN,1
MOVLW 0X60
SUBWF RESULT,0
RETURN
NG
CPFSLT RESULT
GOTO NL
MOVF RESULT,0
NL
RETURN
; Performs minute conversion
MIN_CON
MOVLB 0
MOVF MN,0
ADDLW 30H
DAW
MOVWF RESU
MOVLW 60H
CPFSEQ RESU
GOTO ME
MOVLW 00H
INCF HR,1
RETURN
ME
CPFSGT RESU
GOTO MG
INCF HR,1
MOVLW 0X60
SUBWF RESU,0
RETURN
MG
CPFSLT RESU
GOTO ML
MOVF RESU,0
ML
RETURN
HR_CON
MOVLB 0
MOVF HR,0
ADDLW 05H
DAW
MOVWF RLT
MOVLW 24H
CPFSEQ RLT
GOTO HE
MOVLW 00H
RETURN
HE
CPFSGT RLT
GOTO HG
MOVLW 0X24
SUBWF RLT,0
RETURN
HG
CPFSLT RLT
GOTO HL
MOVF RLT,0
HL
RETURN
DSP_HR
MOVF HUR,0
CALL NUMBER
MOVLW ':'
CALL LCD
RETURN
DSP_MN
MOVLB 0
MOVF MIN,0
CALL NUMBER
MOVLW ':'
CALL LCD
RETURN
DSP_SC
MOVLB 0
MOVF SEC,0
CALL NUMBER
RETURN
ARV
MOVLB 0F
MP
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO MP
INCF FSR0L,1
MOVLW 'A'
CPFSEQ INDF0
GOTO INV
MOVLW 'A'
RETURN
DLONG
MOVLB 0F
BCF PORTA,0
MOVLW 0XD4
MOVWF PORTD
CALL L_SEND
MOVLB 0
MOVLW 0X3C
MOVWF COUNT
CALL XX
RETURN
DLAT
MOVLB 0F
BCF PORTA,0
MOVLW 0X94
MOVWF PORTD
CALL L_SEND
MOVLB 0
MOVLW 0X2C
MOVWF COUNT
CALL XX
RETURN
DISP
MOVLB 0F
MOVLW 08H
MOVWF PCLATH
MOVLB 0
CLRF COUNT
MOVLB 0F
BCF PORTA,0
MOVLW 0X80
MOVWF PORTD
CALL L_SEND
; Moves data from data table and checks for end of line
XX
MOVLB 0
MOVF COUNT,0
MOVLB 0Fb
CALL LOOK
MOVLB 0
MOVWF REG11
MOVLW '*'
CPFSEQ REG11
GOTO YY
RETURN
YY
MOVF REG11,0
CALL LCD
MOVLB 0
INCF COUNT,1
INCF COUNT,1
CALL DELAY
CALL DELAY
GOTO XX
LAT
MOVLB 0F
EF
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO EF
INCF FSR0L,1
MOVLW '.'
CPFSEQ INDF0
GOTO ED
MOVF INDF0,0
CALL LCD
GOTO ER
ED
MOVF INDF0,0
CALL TRANX
CALL LCD
ER
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO ED
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
RETURN
LONG
MOVLB 0
GH
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO GH
LONG_N
INCF FSR0L,1
CPFSEQ INDF0
GOTO LONG_T
GOTO EG
LONG_T
MOVF INDF0,0
CALL TRANX
CALL LCD
MOVLW ','
GOTO LONG_N
EG
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
RETURN
; UART initialization
UART_INIT
;Ports
MOVLB 0F
CLRF TRISB
CLRF TRISC
CLRF TRISE
MOVLW 06H
MOVWF ADCON1
;Address line
MOVLW 03H
MOVWF PORTE
BCF PORTE,2
; Data line
MOVLW 03H
MOVWF PORTC
MOVLW 80H
MOVWF PORTB
CALL SEND
MOVLW 00H
MOVWF PORTC
MOVLW 18H
MOVWF PORTB
CALL SEND
MOVLW 01H
MOVWF PORTC
MOVLW 00H
MOVWF PORTB
CALL SEND
MOVLW 03H
MOVWF PORTC
MOVLW 03H
MOVWF PORTB
CALL SEND
RETURN
SEND
BCF PORTE,1
CALL DELAY
BSF PORTE,1
RETURN
; UART reception
UART_RECX
MOVLB 0F
SETF TRISB
RE
MOVLB 0F
MOVLW 05H
MOVWF PORTC
BCF PORTE,0
MOVF PORTB,0
BSF PORTE,0
MOVLB 0
MOVWF TEMP
BTFSS TEMP,0
GOTO RE
MOVLB 0F
MOVLW 00H
MOVWF PORTC
BCF PORTE,0
MOVF PORTB,0
BSF PORTE,0
MOVLB 0
MOVWF DAT
RETURN
; Giving delay
DELAY
MOVLB 0
MOVLW 0XFF
MOVWF REG2
DECFSZ REG2,1
GOTO $-1
MOVLB 0F
RETURN
; Extracting date
DATE
BCF PORTA,0
MOVLW 0XCA
MOVWF PORTD
CALL L_SEND
DS
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO DS
DX
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO DX
; Displays date
DM
INCF FSR0L,1
MOVLW ','
CPFSEQ INDF0
GOTO DM
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
MOVLW '/'
CALL LCD
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
MOVLW '/'
CALL LCD
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
INCF FSR0L,1
MOVF INDF0,0
CALL LCD
RETURN
; Data table
ORG 800H
LOOK
ADDWF PCL,1
DT " GPS NAVIGATION SYS *"
DT " LAT :*" ;28
DT " LON :*";3C
END
9.2 VISUAL BASIC PROGRAM
OPTION EXPLICIT
PRIVATE DECLARE SUB PORTOUT LIB "IO.DLL" (BYVAL PORT AS INTEGER,
BYVAL DATA AS BYTE)
PRIVATE DECLARE SUB PORTWORDOUT LIB "IO.DLL" (BYVAL PORT AS
INTEGER, BYVAL DATA AS INTEGER)
PRIVATE DECLARE SUB PORTDWORDOUT LIB "IO.DLL" (BYVAL PORT AS
INTEGER, BYVAL DATA AS LONG)
PRIVATE DECLARE FUNCTION PORTIN LIB "IO.DLL" (BYVAL PORT AS
INTEGER) AS BYTE
PRIVATE DECLARE FUNCTION PORTWORDIN LIB "IO.DLL" (BYVAL PORT AS
INTEGER) AS INTEGER
PRIVATE DECLARE FUNCTION PORTDWORDIN LIB "IO.DLL" (BYVAL PORT
AS INTEGER) AS LONG
PRIVATE DECLARE SUB SETPORTBIT LIB "IO.DLL" (BYVAL PORT AS
INTEGER, BYVAL BIT AS BYTE)
PRIVATE DECLARE SUB CLRPORTBIT LIB "IO.DLL" (BYVAL PORT AS
INTEGER, BYVAL BIT AS BYTE)
PRIVATE DECLARE SUB NOTPORTBIT LIB "IO.DLL" (BYVAL PORT AS
INTEGER, BYVAL BIT AS BYTE)
PRIVATE DECLARE FUNCTION GETPORTBIT LIB "IO.DLL" (BYVAL PORT AS
INTEGER, BYVAL BIT AS BYTE) AS BOOLEAN
PRIVATE DECLARE FUNCTION RIGHTPORTSHIFT LIB "IO.DLL" (BYVAL PORT
AS INTEGER, BYVAL VAL AS BOOLEAN) AS BOOLEAN
PRIVATE DECLARE FUNCTION LEFTPORTSHIFT LIB "IO.DLL" (BYVAL PORT
AS INTEGER, BYVAL VAL AS BOOLEAN) AS BOOLEAN
PRIVATE DECLARE FUNCTION ISDRIVERINSTALLED LIB "IO.DLL" () AS
BOOLEAN
DIM PORTNO, I, J AS INTEGER
DIM INP AS STRING
DIM DLAT(40), DLON(50) AS SINGLE
DIM LA, LO, S, T, TLAT, TLON, PLAT, PLON, SLON, SLAT, LLON, LLAT AS
SINGLE
PRIVATE SUB COMMAND2_CLICK()
TIMER2.ENABLED = TRUE
COMMAND4.VISIBLE = TRUE
COMMAND2.VISIBLE = FALSE
END SUB
'1ST CONDITION
IF PLON < TLON AND PLAT < TLAT THEN
1:
CALL SETPORTBIT(&H378, 3): CALL SETPORTBIT(&H378, 0)
'IF [(TLAT-SLAT)PLON] - [(TLON-SLON)PLAT] = [(TLAT-SLAT)*SLON] - [(TLON-
SLON)*SLAT)] THEN
'CALL SETPORTBIT(&H378, 3)
'ELSE
'IF PLON > LLON THEN CALL SETPORTBIT(&H378, 3): CALL
SETPORTBIT(&H378, 0)
'IF PLON < LLON THEN CALL SETPORTBIT(&H378, 3): CALL
SETPORTBIT(&H378, 1)
'END IF
END IF
'2ND CONDITION
IF PLON < TLON AND PLAT > TLAT THEN
2:
CALL SETPORTBIT(&H378, 3): CALL SETPORTBIT(&H378, 1)
'IF [(TLAT-SLAT)PLON] - [(TLON-SLON)PLAT] = [(TLAT-SLAT)SLON] - [(TLON-
SLON)SLAT)] THEN
'CALL SETPORTBIT(&H378, 3)
'ELSE
'IF PLON > LLON THEN CALL SETPORTBIT(&H378, 3): CALL
SETPORTBIT(&H378, 1)
'IF PLON < LLON THEN CALL SETPORTBIT(&H378, 3): CALL
SETPORTBIT(&H378, 0)
'END IF
END IF
'3RD CONDITION
IF PLON < TLON AND PLAT = TLAT THEN CALL SETPORTBIT(&H378, 3)
'4TH CONDITION
IF PLON > TLON AND PLAT < TLAT THEN
DO
CALL SETPORTBIT(&H378, 2)
LOOP UNTIL TLON = PLON + 5
GOTO 1
END IF
'5TH CONDITION
IF PLON > TLON AND PLAT > TLAT THEN
DO
CALL SETPORTBIT(&H378, 2)
LOOP UNTIL TLON = PLON + 5
GOTO 2
END IF
'6TH CONDITION
IF PLON > TLON AND PLAT = TLAT THEN CALL SETPORTBIT(&H378, 2)
'7TH CONDITION
IF PLON = TLON AND PLAT < TLAT THEN
DO
CALL SETPORTBIT(&H378, 2)
LOOP UNTIL TLON = PLON + 5
GOTO 1
END IF
'8TH CONDITION
IF PLON = TLON AND PLAT > TLAT THEN
DO
CALL SETPORTBIT(&H378, 2)
LOOP UNTIL TLON = PLON + 5
GOTO 2
END IF
'9TH CONDITION
IF PLON = TLON AND PLAT = TLAT THEN
CALL CLRPORTBIT(&H378, 0): CALL CLRPORTBIT(&H378, 1): CALL
CLRPORTBIT(&H378, 2): CALL CLRPORTBIT(&H378, 3): CALL
CLRPORTBIT(&H378, 4): CALL CLRPORTBIT(&H378, 5): CALL
CLRPORTBIT(&H378, 6): CALL CLRPORTBIT(&H378, 7)
'MSGBOX "YOU ARE AT THE REQUIRED POSITION: TARGET ACHIEVED"
END IF
LLON = PLON
LLAT = PLAT
END SUB
END SUB
10: CONCLUSION
Through this project, the applicability of GPS for target tracking has been demonstrated.
The advantage that GPS offers for target tracking is the very high degree of accuracy. Hence
any location can be tracked by a vehicle very accurately.
The main disadvantage of this system is that it does not possess an obstacle avoidance
system. Incorporation of an obstacle avoidance system into this GPS will improve the
reliability of the system greatly. The accuracy of the system can be improved by using
sophisticated antennas which enable good reception even in covered areas and adverse
climatic conditions.
Thus, exploration and collection of data of potentially hazardous regions can be done with
minimum risk by employing the tracking feature of this system. The mundane job of
landscape surveying can be automated through the implementation of an enhanced version
of this system.
Thus, applications requiring any sort of tracking can make use of the basic principle of this
system to track locate and reach any desired position. Depending on the specific application,
further enhancement of this scheme will lead to the development of a highly accurate
system.
APPENDIX 1: PIN DIAGRAM AND DEVICE FEATURES OF PIC18F452
Pin
diagram
Device features of PIC 18F452
AP
PE
ND
IX
2:
AR
CHITECTURE OF PIC18F452
AP
PE
N
DI
X
3:
EL
EC
TRICAL CHARACTERSITICS OF PIC18F452
REFERENCES