Interfacing a GPS to an LCD using a Microcontroller A. HENRICHSEN Interfacing a GPS to an LCD using a Microcontroller 27/10/1998 Interfacing a GPS to an LCD using a Microcontroller Prepared by: ¯ Arne Henrichsen, fourth-year student in the Department of Electrical Engineering at the University of Cape Town Prepared for: ¯ The Department of Electrical Engineering University of Cape Town 27/10/1998 This thesis is prepared in partial fulfillment of the requirements for the degree of BSc. in Electrical Engineering. Acknowledgements I would like to give my thanks to the following people for all their help and advice. Mr G. Tattersfield, Department of Electrical Engineering, for his guidance as my thesis supervisor. Mr J. Pinto, MSc. Student at the University of Cape Town, for his help with the Atmel Microcontroller. Mr J. Salzwedel, Student at the University of Cape Town, for being a co-operative partner in sharing the GPS receiver, implementing the principles of the GPS and the construction of the final GPS container. And finally to the people at `Avnet Kopp', for lending us their copy of the Motorola GPS manual, and for donating the Motorola voltage regulator and Atmel microcontroller free of charge. Declaration The work was my own, although this project could not have been accomplished without the help of the people mentioned in the Acknowledgements. The breakdown http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (1 of 206) [30/05/2004 08:31:22 a.m.]
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Interfacing a GPS to an LCD using a Microcontroller
A. HENRICHSEN
Interfacing a GPS to an LCD using a Microcontroller
27/10/1998
Interfacing a GPS to an LCD using a MicrocontrollerPrepared by: ¯ Arne Henrichsen, fourth-year student in the Department of Electrical Engineering at the University of Cape TownPrepared for: ¯ The Department of Electrical Engineering University of Cape Town
27/10/1998
This thesis is prepared in partial fulfillment of the requirements for the degree of BSc. in Electrical Engineering.
AcknowledgementsI would like to give my thanks to the following people for all their help and advice.Mr G. Tattersfield, Department of Electrical Engineering, for his guidance as my thesis supervisor.Mr J. Pinto, MSc. Student at the University of Cape Town, for his help with the Atmel Microcontroller.Mr J. Salzwedel, Student at the University of Cape Town, for being a co-operative partner in sharing the GPS receiver, implementing the principles of the GPS and the construction of the final GPS container.And finally to the people at `Avnet Kopp', for lending us their copy of the Motorola GPS manual, and for donating the Motorola voltage regulator and Atmel microcontroller free of charge.
DeclarationThe work was my own, although this project could not have been accomplished without the help of the people mentioned in the Acknowledgements. The breakdown
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (1 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
of work on various aspects of the thesis is as follows:
Circuit ImplementationI received substantial help in the design of the external RAM for the microcontroller from Mr J. Pinto. I was responsible for the PCB layout using the program Tango PCB and the testing of the circuit. The boards were produced by the `Electronics Supermarket' in Cape Town.
Design of the GPS boxThe design and construction of the plastic box for the GPS circuitry was done by `Mr Plastic' from Montague Gardens.
Software ImplementationThe C++ and assembly programs are my own, except for the help I received from Mr J. Pinto with the setting up of the RAM and ROM areas of the microcontroller.
Voltage RegulatorThe voltage regulator used in the circuit was suggested by Mr N. Ballard from `Avnet Kopp'. The incorporation of the regulator into the circuit is entirely my own.
System AnalysisThe final analysis of the GPS system is my own, as are the conlusions drawn.
Terms Of ReferenceThis Thesis was proposed by Mr G. Tattersfield, Programme Co-ordinator of Electro-Mechanical Engineering at the University of Cape Town. The briefing was given on the 25 June 1998 and work commenced on the 13 July 1998.Mr Tattersfield's specific instructions were:
1. To develop a hand-held GPS system using the following: ❍ The Motorola GPS Oncore Receiver ❍ A Liquid Crystal Display (LCD)
2. To investigate different microcontrollers and choose the most appropriate device to interface the GPS and LCD. 3. The system should be controlled by a small keyboard. 4. The GPS should be powered by a battery. 5. The hand-in date for the thesis is the 28 October 1998.
Synopsis
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (2 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
This thesis describes the investigation undertaken in implementing a hand-held Global Positioning System (GPS).
The objectives of this thesis were to use the Motorola Oncore GPS Receiver (Serial No. R3111G1111) in an embedded application and to build a user-friendly GPS system, which would display all basic features of the GPS on a Liquid Crystal Display (LCD). A software based program would be controlled using a certain number of keys, which would in turn operate and control the LCD and GPS.
The project was approached by first interfacing the GPS receiver to the PC via the serial port and the LCD to the PC via the parallel port. By studying the protocols of the GPS and LCD, a program was implemented in C++. The next step in the design was to replace the PC using a suitable microcontroller. This microcontroller was chosen to be the Atmel 89C55, as it had the necessary program memory and ports to substitute the PC. In order to program the Atmel chip, the already implemented C++ code was converted into assembly language using a cross compiler. The final circuit was designed around the Atmel 89C55 chip.
In order to make the system more versatile, the user is able to switch between the microcontroller and the PC. This was achieved by providing an RS-232 connector, which lets the GPS communicate with any computer. Power is provided by either a car battery or a `Gel' cell battery.
The major conclusions that could be drawn from the investigation are:
1. Most functions (position, status, data) could be implemented with the GPS and displayed on the LCD. 2. The use of the Atmel 89C55 microcontroller made the implementation of software and hardware easy as much help was available. 3. The system was succesfully tested and the layout of the keyboard and LCD made the system easy to use.
A GPS system was succesfully built and demonstrated. Since time was limited, some functions were not able to be implemented. Thus the following recommendations can be made to improve the system:
1. Display the data obtained from the GPS graphically using the existing LCD, instead of using text as at present. 2. Implement the NMEA format for GPS data output using the RS-232 serial port. 3. Add non-volatile memory in order to store data from the GPS to be used later. 4. Display maps and plot the current position using a bigger colour screen/LCD. 5. Implement Differential GPS to get better position accuracies.
GlossaryBMP
- Bitmap Image CG RAM
- Character Generator Random Access Memory GPS
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (3 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
- Global Positioning System LCD
- Liquid Crystal Display NMEA
- National Marine Electronics Association PC
- Personal Computer
Contents1 Introduction2 The Motorola Oncore GPS 2.1 Brief Description of GPS 2.2 Antenna Information 2.3 GPS Oncore Information 2.3.1 Electrical Specifications 2.3.2 The Serial Interface 2.4 Interface Protocol 2.4.1 Motorola Binary Format 2.4.2 Details of some Commands 2.5 NMEA Interface Standard 2.5.1 Brief Description of NMEA 2.5.2 Outline of Command Structure3 The Graphics Liquid Crystal Display 3.1 Module Pin-out 3.2 Status Check 3.3 Setting the Cursor and Address Pointer 3.4 Generating User Defined Characters 3.5 Displaying Graphics4 The Atmel 89C55 Microcontroller 4.1 External RAM 4.2 The Serial Port 4.3 The Keypad 4.4 Other Microcontroller Connections5 Software Development
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (4 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
5.1 PC application 5.2 Microcontroller application6 Description of Power Supply 6.1 Switching between the Microcontroller and PC7 System Analysis and Errors 7.1 Keypad Scanning Routine 7.2 Microcontroller serial port 7.3 GPS Differential Mode 7.4 External RAM 7.5 LCD Contrast Voltage8 Conclusion9 Recommendations10 BibliographyA GPS Oncore CommandsB Almanac ParametersC LCD Controller NotesD Circuit DiagramsE C++ CodeF Assembly CodeG Included Disc
List of Figures 2.1 Oncore GPS Receiver (from the `GT PLUS ONCORE RECEIVER' pamphlet, available from Motorola). 3.1 User defined character of the degree sign 3.2 Bitmap Image displayed on LCD 3.3 Graphics Data Format 4.1 External RAM taken and modified from [Atmel,1997] 4.2 Keypad used in this thesis 5.1 Program Flow Diagram B.1 Details of Subframe 5 C.1 Character Code Map from the T6963C D.1 Circuit Diagram for External RAM D.2 Interface Diagram for LCD
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (5 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
D.3 Microcontroller and PC to GPS D.4 Keypad Connections D.5 Power Supply and Contrast Voltage D.6 PCB Circuit Design D.7 PCB Circuit Keyboard Design
List of Tables 2.1 Oncore Power - Data Connector Pin Assignments [Motorola, 1996]. 2.2 Oncore Interface Protocol [Motorola, 1996] 3.1 Relationship between CG RAM and Offset register 5.1 Virtual KeyBoard A.1 Commands from GPS used for Thesis A.2 NMEA Commands A.3 Format Commands B.1 Parameters of Subframe 4 and 5
Chapter 1 IntroductionThis thesis sets out the results of the design and construction of a hand-held GPS receiver system.
The NAVigation Satellite and Ranging (NAVSTAR) GPS is an all weather, radio based, satellite navigation system that enables users to accurately determine 3-dimensional position, velocity and time worldwide. The GPS system has been developed by the US Department of Defense and the service it provides is free to an unlimited number of users [Motorola, 1996]. Receivers like the Motorola Oncore are inexpensive and easily obtainable and allow the inclusion of the receiver in embedded applications. This gives the designer the freedom of designing a system suitable to a wide range of people [Motorola, 1996].
The Objectives of this thesis was to build a GPS system with the following aspects:
1. Must be hand-held. 2. Must be able to display all relevant information on a Graphics LCD. 3. The interfacing must be done using a microcontroller.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (6 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
The thesis is restricted to the objectives outlined above due to the limited time that was available. It is up to the recommendations to provide details of other aspects that could be included in a GPS system.
This thesis will first investigate the protocols associated with the Motorola Oncore GPS Receiver and the functions to be included in the project. Based on this information and the visual requirements needed to display all necessary data, the graphics LCD screen is discussed. The method of displaying a bitmap image is outlined here in detail. The choice of the Atmel 89C55 microcontroller will be discussed next, focusing on the suitability as an interface between the GPS and LCD. Following this, there will be certain sections describing software development and the final circuit will be described with the chosen power supply. The whole system will be analysed and discussed. Finally, conclusions are made about the design and effectiveness of the GPS system and recommendations are made about further improvements that could be implemented.
Chapter 2 The Motorola Oncore GPSAs the GPS receiver forms the central part of this thesis, the first thing to do was to get a good understanding of the functions and requirements this particular GPS receiver can provide. This was done using the Motorola GT/UT Oncore User's Guide [Motorola, 1996].
2.1 Brief Description of GPS
The overall Global Positioning System consists of three major segments: the space segment, the ground segment, and the user segment. These are detailed below from the Motorola Oncore User's Guide [Motorola, 1996].
Space Segment: This consists of the 24 satellites that make up the GPS. These satellites are found in 6 orbital planes and are equally spaced about the equator and inclined at 55 degrees. The satellites are found at an altitude of 20 183km.
Ground Control Segment: This segment consist of a master control center and a number of monitoring stations. This network of stations tracks the satellites and precisely determines their orbits. At certain intervals they will update the almanac ephemeris and other system data which the satellites transmit to the users.
User Segment: The user segment consists of all the GPS receivers. The GPS receiver's position is determined by the geometric intersection of several simultaneously observed ranges (satellite to receiver distance) from the satellites with known co-ordinates in space. The receiver measures the time required for a satellite signal to reach the receiver. This transmission time is determined using code correlation techniques. This means that each satellite has a unique code sequence that is identical to a code sequence generated by the receiver. The receiver code is shifted until maximum correlation between the 2 codes exist. This time shift is multiplied by the speed of light and gives the distance to each satellite. Factors like satellite and receiver clock errors and propagation delays are included in that signal. A minimum of 4 satellites need to be tracked in order to solve for 4 unknown parameters (i.e. latitude, longitude, altitude
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (7 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
and clock offset). If one of these parameters is known and fixed, one only needs to track 3 satellites.
2.2 Antenna Information
The major components included in the antenna is a microstrip patch antenna, a ceramic RF filter and a signal preamplifier. This antenna is designed to collect the L1 band signals transmitted from GPS satellites at a frequency of 1575.42 MHz. The signals are then amplified and relayed to the receiver. The signal is first preamplified within the antenna and this is made possible by the external power supply supplied by the Oncore receiver. The antenna module draws 22 mA of current at 5 Vdc, directly from the antenna connector.
The Oncore receiver is capable of detecting the presence of an antenna. An antenna sense circuit can detect under current (open circuit), over current (shorted or exceeding maximum receiver limits), or a valid antenna connection [Motorola, 1996].
The above information is available through 2 I/O messages, namely the `Position/Status/Data' and `Self-Test' message.
2.3 GPS Oncore Information
The Motorola Oncore Receiver is a compact and lightweight module, especially designed to be used in embedded applications. It has 8 channels which enables it to track 8 satellites simultaneously. A RF signal processing circuit converts the RF signal received from the antenna to an intermediate frequency (IF) which is passed on to an analog-to-digital converter which digitizes the signal. This digitized IF signal is routed to the 8 channels for code correlation, carrier tracking and filtering. A microprocessor decodes and processes satellite data and computes position, velocity and time [Motorola, 1996].
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (8 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
Figure 2.1: Oncore GPS Receiver (from the `GT PLUS ONCORE RECEIVER' pamphlet, available from Motorola).
2.3.1 Electrical Specifications
The Oncore receiver operates on a +5 Vdc regulated power source. The power source chosen for this thesis will be described in detail later. The data I/O serial port interface is inverted TTL (5 V logic). The receiver has a 10-pin, power/data connector and a miniature RF connector for the antenna connection [Motorola, 1996].
The following table lists the assigned signal connections of the Oncore receiver:
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (9 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
2 +5 Power +5Vdc regulated main power
3 Ground Ground (receiver)
4 Vpp Flash memory programming voltage
5 RTCM Input Differential correction input pin
6 1 PPS 1 Pulse per second signal
7 1 PPS RTN 1 pulse per second return
8 TTL TXD Transmit 5V logic
9 TTL RXD Receive 5V logic
10 TTL RTN Transmit / Receive return
Table 2.1: Oncore Power - Data Connector Pin Assignments [Motorola, 1996].
5V PWR: 4.75 Vdc to 5.25 Vdc
Battery or Backup PWR: 2.5 Vdc to 5.25 Vdc
2.3.2 The Serial Interface
To connect the GPS Oncore receiver to a PC, the TTL signal levels of the receiver have to be converted to RS-232 signal levels (i.e. TTL: 0V to be converted to +3 to +25Volts and TTL: 5V to -3V to -25Volts) To achieve this, the MAX232 driver ( or LT1032 ) is placed in the circuit which operates from a +5V power supply and uses a charge pump to generate the negative supply needed.
2.4 Interface Protocol
The folowing table lists the interface protocol parameters:
Format: Motorola
Type: Binary
Baud Rate: 9600bps
Data Bits: 8 bits
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (10 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
The I/O port on the receiver operates under interrupt control. The incoming data is stored in a buffer that is serviced by the Oncore every 1.0 seconds.
2.4.1 Motorola Binary Format
The Oncore Receiver uses binary data messages consisting of a number of binary characters. A data message can be divided into the following sections [Motorola, 1996]:
Message Start: @@ - (2 x 40hex) denotes the start of the binary message
Message ID: (A..Z)(a..z, A..Z) - ASCII upper-case letter, followed by an ASCII lower-case or upper-case letter. These 2 characters together identify the message type and imply the correct message length and format.
Binary Data Sequence: This consists of a variable number of bytes of binary data dependent on the command type.
Checksum: C - This is the exculsive-or of all bytes after the @@ and prior to the checksum.
Message Terminator: <CR> <LF> - carriage return and line feed characters denoting the end of the binary message.
A list of all commands used in this thesis are found in Appendix A.
Every Oncore receiver input command has a corresponding response message to determine if the command has been accepted or rejected. If a correct command has been received, the receiver will perform the requested function.A binary message is considered received if the following checks out:
● the message started with @@ and is terminated with a carriage return and line feed character. ● the message is the correct length for its type ● the checksum validates.
[Motorola, 1996]
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (11 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
The data field contains binary data which can either be integer or floating point data. Negative numbers are stored as two's complement numbers.
The Oncore receiver will reject the entire command if one of its input parameters is out of range. For example, to change the GMT offset, the range of hours to be changed is between -23 and +23. If a command is send requesting to change the GMT offset to 24 hours, the entire command is rejected and the original setting is kept.
Response messages are identified in the same way as the Oncore receiver decodes the commands.
2.4.2 Details of some Commands
As describing each of the commands will take up many pages, only some commands will be descibed in more detail. These are taken from [Motorola, 1996].
1. The structure of the `Latitude'command is highlighted. All other commands follow the same structure but may be of different lengths. Input Command: ¯ Poll current Latitude: @@AdxxxxC<CR><LF> where xxxx = 4 out of range bytes (99hex99hex99hex99hex) Message length is 11 bytes.
Change current Latitude: @@AdddddC<CR><LF> where dddd = latitude in milliarcseconds (mas) (-324 000 000 .. 324 000 000) (-90o .. 90o)
Response Message: @@AdddddC<CR><LF>
To convert milliarcseconds to degrees, the following relationship is used: 1o = 3 600 000 mas
2. The `Position/Status/Data' command combines nearly all other commands. The response message contains the date, time, position, velocity, geometry, the satellite visibility and tracking status, and the status of each of the 8 channels. The message length is 76 bytes. It is possible to poll the receiver once or to request a updated message at certain intervals.
3. The Almanac data output message contains satellite data. This almanac data is loaded into the onboard RAM of the Oncore receiver and takes about 15 minutes after power-up to be broadcast from the satellites. As there are 34 satellites, there are 34 response messages. Almanac data is transmitted in words 3-10 of subframe 5 (pages 1-25), and words 3-10 of subframe 4 (pages 2-5, 7-10, and 25) of the satellite broadcast message.Appendix B shows the format of the parameters that are situated in words 3-10 [GPS ICD-200].
As this message requires a big buffer (1122 bytes at least) to store the values in, this command has only been implemented on the PC and not on the
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (12 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
microcontroller.
2.5 NMEA Interface Standard
The Oncore receiver supports the National Marine Electronics Associatian (NMEA) 0183 format for GPS data output [NMEA,1997]. Using the `Switch to NMEA' command makes it possible to change the serial data format of the serial port. The baud rate is switched from 9600 to 4800 and the input commands are only recognized in NMEA format.
Due to time limitations, this format was not implemented. It is, however, compared to the Motorola Binary Format.
2.5.1 Brief Description of NMEA
The National Marine Electronics Association (NMEA) developed this standard to allow a satisfactory direct data interface between electronic marine instruments, navigation equipment and communications equipment. This standard defines electrical signal requirements, data transmission protocol and timing for a 4800-baud serial data bus. The intended application for this standard is between a single TALKER to one or many LISTENERS in one-way serial data transmission. The data and commands are in the form of ASCII characters and as in the Motorola binary format, certain sequences of ASCII characters convey information about the position, altitude etc. Each ASCII character has 8 data bits with the most significant bit always set to zero. Valid characters are the ASCII characters from 20h to 7Eh except some characters defined as reserved characters [NMEA,1997].
2.5.2 Outline of Command Structure
The following gives an outline of the reply message the Oncore receiver will send to an electronic navigation instrument [NMEA,1997]:
Start of sentence: This is the ASCII character `$'= 24h [Adress field:] This field consists of 5 characters. The first 2 characters identify the TALKER. In the case of the GPS, this code consists of the 2 ASCII characters `GP'. The last 3 characters are the sentence formatter or message ID.
Field delimiter: The character `,' = 2Ch starts each field except the address and checksum fiels. If it is followed by a null field, it indicates that no data is present.
Data Sentence block: This consists of a series of data fields containing all the data that is transmitted. The sequence is identified by the sentence formatter.
Checksum Delimiter: The character `*' = 2Ah follows the last data field and indicates that a 2 byte hex value follows from the checksum.
Checksum field: This is the same as in the Motorola Binary format: all data between the `$' and the `*' are exclusive-or'ed together.
Terminates the sentence:
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (13 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
<CR> = 0Dh and <LF> = 0Ah.
To request such a message from the Oncore, the following command needs to be sent [Motorola, 1996]:
Start of command: $PMOTG, where the P identifies the message as Proprietary format; MOT stands for Motorola and G for GPS. [Command field:] This field consists of 3 characters and corresponds to the sentence formatter of the address field above. The Oncore receiver has 7 NMEA commands which are outlined in Appendix A.
Update Rate: 4 bytes instruct the receiver to output the message once or continuously.
The command also includes field delimiters, a checksum field and the 2 terminating characters.
As can be seen above, the NMEA format is similar to the Motorola Binary Format. The NMEA Format makes it easier for an electronic navigation instrument that supports NMEA to communicate with the GPS.
As the information from NMEA commands can also be requested through the Motorola Binary Format, the NMEA Format was not implemented. The project could have been expanded to include an electronic navigation instrument that communicates with the GPS.
Chapter 3 The Graphics Liquid Crystal DisplayOne of the requirements for this thesis was to display all information from the GPS on a LCD. A Graphics display was chosen as the biggest text display only had 40 characters by 4 lines. The display used is a 240 X 64 pixel graphics display from Varitronix (MGL(S)-24064-G-LED03). This was the biggest display the budget could afford. With a 6 X 8 character font, text of 40 characters by 8 lines could be displayed which is sufficient for this thesis.
This chapter will describe the LCD controller from Toshiba (T6963C) and how to display a uncompressed black and white bitmap image on the screen.
3.1 Module Pin-out
This section will describe some of the pins from the LCD.
1. The supply voltage is +5 Volts with a negative contrast voltage of about -10 Volts. This contrast voltage depends on the display type and temperature. In the
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (14 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
final circuit a charge pump (LT1054) is included to generate the required negative voltage. As its input +12 Volts is used (directly from Car battery or `Gel' cell battery) which is inverted to -12 Volts. A potentiometer is included in the circuit to enable a variable negative contrast voltage.
2. There are 4 control pins: /WR (Write), /RD (Read), /CE (Chip enable) and C\/D (data/command register). These pins are used to write data or commands, or to read the status byte [Toshiba,1997]. Write data:
The data to be written should be set on D0-7 andC/\D taken low/WR taken low (/RD should be high)/CE must be pulsed low for greater than 80ns
Write command: The command should be set on D0-7 andC/\D taken high/WR taken low (/RD should be high)/CE must be pulsed low for greater than 80ns
Read Status: To check the status of the controller:C/\D taken high/RD taken low (/WR should be high)/CE must be pulsedAfter approximately 150ns the data can be read from D0-7/CE taken high
3. This LCD enables the user to choose the font size of the text characters. The fonts available are either 8x8 or 6x8 pixels. A 6x8 font was chosen in order to increase the number of characters per row to 40. Only 30 characters are available per row with an 8x8 font.
3.2 Status Check
Before data or commands are read or written, a status read must be performed. This means checking that Status bit 0 (STA0) and Status bit 1 (STA1) are set to 1. If they are set to zero, the controller is still busy executing a command or an internal read/write is taking place [Toshiba,1997].
It was only possible to interface to the parallel port of the PC if the port was bidirectional. As some PC's only have an output port, a delay of 1ms was inserted before writing the data. As the Atmel microcontroller has bidirectional ports, this was not needed as the status byte can be read directly.
3.3 Setting the Cursor and Address Pointer
On initialisation, the text and graphics home address have to be defined. The address can be anywhere in the RAM area available (8k). The text home address was chosen to be 0000h and the graphics home address to be 0200h. In this way, text and graphics data will not interfere with one another.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (15 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
The user can choose between either graphics or text mode. In text mode there are certain cursor functions: a 1-8 line cursor, blinking or on/off. The cursor is moved according to the following equation:
address = TextBASE + (y * BYTES PER ROW) + x
where y = [0,8], x = [0,63] and BYTES PER ROW = 40 with a 6X8 fontFromJohn P. Beale's program (May 3-4, 1997, [email protected])
The cursor pointer is not automatically moved with each write. Only the address pointer is incremented / decremented to the next position. The address pointer is also set up according to the above equation.
3.4 Generating User Defined Characters
Appendix C shows the character map available to this LCD controller. The character codes are different from ASCII codes. To display an ASCII number means subtracting 20h which will be then the correct index into the character map. As this character map does not contain all ASCII characters, it was necessary to generate one's own character. The degree sign character was defined in the following way:
1. The `Offset Register' command is used to determine the external character CG RAM area. As seen in Appendix C, characters are already defined from 00h to 7Fh. User defined characters can be from 80h to FFh in CG RAM.The following table will help chosing the nescessary Offset register data [Toshiba,1997]:
Offset Register data CG RAM area
00000 0000 to 07FFh
00001 0800 to 0FFFh
00010 1000 to 17FFh
00011 1800 to 1FFFh
... ... ...
11110 F000 to F7FFh
11111 F800 to FFFFh
Table 3.1: Relationship between CG RAM and Offset register
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (16 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
As this LCD only has 8k of RAM available, only the first 4 offset data numbers are usable. The CG RAM area used was from 1800 to 1FFFh, so that character 80h will take up locations 1C00 to 1C07h (1800h + 80h*8 lines). This meant using an offset register number of 3h.
2. Then to set character number 80h to a user defined character:
Figure 3.1: User defined character of the degree sign
To store this character in RAM, the address pointer has to be set to 1C00h and the 8 bytes from Figure 3.1 written to it. Setting then the address pointer to 80h will display the degree sign on the LCD.
3.5 Displaying Graphics
To display an image on the LCD involves a number of steps:
1. To create an image in black and white the Microsoft Paint Program was used. A canvas exactly the same size, in pixels, as the LCD was set up in the paint program.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (17 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
Figure 3.2: Bitmap Image displayed on LCD
2. This image was saved in uncompressed `Tiff' format, now stored in negative mode. A black pixel is thus stored as a logical `0' and a white pixel as a logical `1'. As the LCD is in positive mode, the image will be inverted. To remedy this, the bits were inverted when writing to the LCD.
3. To convert the image into hexadecimal form, a freeware program called bin2hex.exe was used. It is available from the following website: http://www.hantronix.com. This program creates a text file which can be edited to the user's needs. The bytes of the image are listed in the following way:
00 15 12 32 ac ...
4. A `Hantronix' Application Note [Hantronix] says that one must delete the first 25 bytes from that text file, as these bytes are part of the `Tiff' header. This was found not to be true. The text file in question consisted of 2260 bytes. To subtract 25 would give 2235 bytes. The LCD only needs 1920 bytes (30 bytes in a row by 64 pixels (rows)). Thus the `Tiff' header which should be subtracted is 340 bytes long.
5. When reformatting the text file (using a simple text editor) to be included in an assembly program, the bytes will look like the following (see also page 122):
db 000h 015h 012h 032h 0ach ...
6. The data is formatted as shown below: This applies to the 240X64 Pixel Display.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (18 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
Figure 3.3: Graphics Data Format
7. The graphics area in RAM needs to be set up to how many bytes later one wants the next line to start at. This can be the same number of bytes to fill one line of the screen for most efficient use of the RAM. If one would set the number of bytes in RAM less than the number of bytes per row the image gets corrupted as certain bits / bytes get overwritten. With an 8X8 font there are 30 bytes in a row as in the `Tiff' file. But as a 6X8 font is used, the RAM had to be set up to 40 bytes per row. The following equation which sets the address for each of the bytes in the text file on the LCD is taken from John P. Beale's program (May 3-4, 1997, [email protected]):
where row = [0,63], column = [0,239] and BYTES PER ROW = 40 with a 6X8 font
To set the bits on the LCD the `Set bit within byte' command is used.
8. As mentioned above, the image consists of 1920 bytes. Most of the pixels on the image were not set. To compress the same image the number of interstitial `zero' bytes were counted and replaced with a number representing the number of `zero' bytes.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (19 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
For example: The following sequence of bytes:
0aah 0deh 000h 000h 000h 000h 0ffh
would be converted to this:
0aah 0deh 4 0ffh
In this way the image was compressed to ±1000 bytes. The display routine simply jumps over the number and offsets the address by the required number of bytes.
(The code which displays the image on the LCD is found on page 89-90.)
Chapter 4 The Atmel 89C55 MicrocontrollerAfter interfacing the GPS and the LCD to the PC and implemeting the code in C++, it became evident that the microcontroller to be used had to have at least 16 kbytes of Onboard ROM. This came from the fact that the image and the C-code would take up much memory. The microcontroller also needed approximately 512 bytes of RAM, half of it used for the buffer to store the GPS data in and the rest for program variables. A UART serial port was also needed.
Two microcontrollers were considered: the XC68HC705C9A from Motorola and the 89C55 from Atmel. As the Motorola microcontroller was not available, the Atmel microcontroller was chosen as it has 20 kbytes of Flash, 256 bytes of RAM and a UART serial port. Another interesting fact was that the Flash Memory was electronically and not UV erasable and made debugging and program development faster. The only drawback was that not enough Onboard RAM was available.
4.1 External RAM
As the program needed another 256 bytes of RAM, a small RAM array was inserted in the circuit.
The following figure shows the hardware configuration for accessing up to 2 kbytes of external RAM (see also Figure D.1):
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (20 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
Figure 4.1: External RAM taken and modified from [Atmel,1997]
The 3 lines from Port 2 were strapped to +5V as they were not needed. Port 0 supplied the address and data and only 256 bytes could be accessed, which gave an overall total of 512 bytes of RAM.
In order to access the external RAM, the `movx' instruction was used instead of the normal `mov' instruction. The address is placed on Port 0 and is latched with the `ALE' pin after which the data is read or written from RAM.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (21 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
The Atmel 89C55 makes use of 4 register banks. Only register bank `zero' was used during program execution which meant that the other 3 register banks were used as additional 21 bytes of RAM.
4.2 The Serial Port
The serial port was used in Mode `1' with 8 data bits and 1 start and 1 stop bit. The onboard timer/counter1 was used to generate the nescessary baud rate of 9600. With an oscillator frequency of 11.059MHz the following equation was used to determine the reload value for TH1 (the timer/counter high byte 1):
The serial port was setup so that it could generate an interrupt whenever it received an character, in this case from the Oncore GPS receiver. The characters are read from the microcontroller serial buffer (SBUF) and stored in a temporary circular buffer.
4.3 The Keypad
The program required 7 keys to control the LCD and GPS. The following concept on scanning a keypad is taken and modified from: [Yeralan S and Ahluwalia A, 1995]. The keys were arranged in the following way (see also Figure D.4):
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (22 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
Figure 4.2: Keypad used in this thesis
Each pushbutton has 2 terminals with one connected to a column rail and the other to a row rail. The row and column rails are then connected to the microcontroller Port 1. The columns are then driven low by the port and the rows are read in. If no key has been pressed, the rows read `1'. When a row is detected to be `0', it indicates that a key has been pressed. To detect which key has been pressed, the microcontroller loops through each column, driving 1 column at a time low and inspects the row. The row will be grounded when the column in which the key resides is driven low. In this way the keys can be identified. Each key has a number associated with it and this number is stored in the global variable `key'.
This particular keypad is implemented to invoke an interrupt. The 2 rows are combined into an AND gate. As the rows are normally at a logic level `1' , the output
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (23 of 206) [30/05/2004 08:31:22 a.m.]
Interfacing a GPS to an LCD using a Microcontroller
of the AND gate is also a `1'. When a key is pressed, the `1' to `0' transition at the AND gate will trigger the interrupt.
A debouncing scheme has also been implemented. After the pressed key has been identified, the rows are checked until the key has been released. Only then does the program continue.
(The code which implements the keypad scanning is found on page 78.)
4.4 Other Microcontroller Connections
It was decided that the LCD's data pins should be connected to Port `0' of the microcontroller(see figure D.2). To drive the LCD, pull-up resistors had to be inserted. These pull-up resistors do not interfere with the external RAM. Accessing external RAM also does not have any effect on the LCD as the LCD control lines (on Port `2') are inactive.
Chapter 5 Software DevelopmentTwo types of programs were implemented. A program was written in C++ for the PC and another was written in assembly language for the microcontroller. Both programs are identical: they implement the same routines in different languages.
5.1 PC application
In order to get a better understanding of both the GPS and LCD, the thesis was first implemented on the PC. The GPS Oncore was connected to the PC via the serial port and the LCD was connected to the PC via the parallel port. The program was developed using Borland C++ for DOS, as the author has had previous experience with it.
The following diagram shows the program flow of the main routines:
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (24 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (25 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure 5.1: Program Flow Diagram
If a key has been pressed, the program will decide which Menu to display and which command to send to the GPS. The GPS will then send information back. As the serial port was interrupt driven, every time the GPS Oncore send back data, an interrupt service routine would store the incomming characters in an ringbuffer (see code on page 57).The main program would then check to see if the headpointer and tailpointer of the ringbuffer are equal or not. If not equal, then the ringbuffer received new data and a routine had to decide which command had been send back. A command is identified by the 3rd and 4th character of each sequence (see Appendix A). For each command from the GPS Oncore there is a display function which operates on the data in the ringbuffer and displays it in the best possible way (see code in Appendix E).
5.2 Microcontroller application
The microcontroller had to use the same routines as the PC. The only difference is the implementation of the keypad. The PC has the whole keyboard available to input strings of numbers. It was decided to use only seven keys with the microcontroller. These are the Up and Down Keys, Left and Right Keys, Enter Key, Escape Key and a Menu Key. This meant that a virtual keyboard had to be implemented on the LCD. The four `arrow' keys were used to scroll through the virtual keyboard and the `Enter' key used to select a number. The XY coordinates on the LCD display were used as an index into a Look-up Table to get the correct number selected. The number was then stored in an array. To leave the virtual keyboard, the user has to select the `*' character. The `arrow' keys were used in the same way as outlined above to scroll through the different LCD menus.
0 1 2 3
* 4 5 6
7 8 9
Table 5.1: Virtual KeyBoard
The program flow is exactly the same as for the PC. A cross-compiler was used to change the C++ code to assembler. As the Engineering Departement did not have a cross-compiler, a demo cross-compiler was used. This cross-compiler (HI-TECH C compiler for the 8051) only generated 500 lines of assembly code. Therefore it was nescessary to break up the C++ code into smaller pieces and cross-compile these sections individually. It was then nescessary to edit the assembly code and insert the names of the allocated variables in RAM, as the cross-compiler did not do so.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (26 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Assembly code was not generated for all functions. The cross-compiler left it to the user to generate code for 32-bit division and displaying strings. 32-bit division was implemented by means of successive subtraction [Yeralan S and Ahluwalia A, 1995].
To display strings of characters the following code was used:lcall lcdprintdb "The Oncore Receiver.",0
If a subroutine is called, the return address is pushed onto the stack. On entering this subroutine (lcdprint), the return address is popped again from the stack into the data pointer. This data pointer will now point to the first character of the string, `T'. The data pointer is incremented after each character is displayed. If the data pointer points to a `0', the routine returns to the calling program. As the return address was already popped from the stack, a `jump' is made to the address pointed to by the data pointer, which points now to the instruction after the `0' (see code on page 86).
As the LCD character generator RAM only displays one character at a time, a number consisting of several characters had to be split up into its individual characters. For example, the number `125' had to be split up into `1', `2', and `5'. This was achieved by dividing the number by `10', storing the remainder in an array and later displaying the variables in the array. To show how this works the above number is used:
125 / 10 = 12 with a remainder of `5'12 / 10 = 1 with a remainder of `2'1 / 10 = 0 with a remainder of `1'
The remainder numbers are stored in an array and then displayed individually (see code on page 106).
Chapter 6 Description of Power SupplyA prerequisite for this thesis was to make the GPS portable. This meant running the GPS of batteries. It was decided to use a `Gel' cell battery and as another alternative a car battery. The `Gel' cell battery was chosen as it was small enough and is rechargeable. It supplies 12 Volts with 2.2Ah.
As the GPS, LCD and microcontroller need a +5 Volt supply, a voltage regulator was needed. The voltage regulator chosen initially was the LM340. This regulator is designed to change only 10 Volts to the required 5 Volts by dissipating the extra power. Using the `Gel' cell battery with the LM340 wasn't so desirable as the power regulator had to dissipate an extra 2 Volts. As the car battery supplies 14 Volts when the car is running and the `Gel' cell battery supplies 12 Volts, the regulator finally chosen was the MC34167 from Motorola. This is a fixed frequency power-switching regulator which changes any voltage ranging from 7-35 Volts to 5 Volts (see figure D.5).
The box which houses the GPS circuitry has an extra compartment to hold the `Gel' cell battery. In order to prevent connecting the car battery to the circuit while the
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (27 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
`Gel' cell battery is still in the compartment, the connector can only be plugged in inside the compartment with the `Gel' cell battery removed.
6.1 Switching between the Microcontroller and PC
To switch between the microcontroller and the PC a Quad Bilateral Switch (HCF4066) was used. Using a `double throw, double pole' switch the bilateral switch and the power to the microcontroller and LCD was controlled (See Figure D.3).
Chapter 7 System Analysis and ErrorsThe following sections will describe some areas in the GPS system where errors occur or where the design is not very efficient. The errors are mostly timing related, as in the keypad scanning routine. Another factor which will be discussed is the expanding of the external RAM from 256 bytes to 2 kbytes.
7.1 Keypad Scanning Routine
A major problem is that the keys do not respond sometimes when pressed. This is due to other routines still running and setting the `key' variable back to zero, which indicates that no key was pressed. The user then has to press the key a couple of times before the program will function in the normal way again.
The key debouncing routine is very efficient, although sometimes the keys react to fast by `jumping' over certain functions in the program. This could be due to the fact that the microcontroller is too fast and already `sees' the next key being pressed. This is minimal though and does not really affect the program.
7.2 Microcontroller serial port
Incoming data from the GPS receiver via the serial port is slow (9600 bps) in comparison to the program execution of the microcontroller (at a frequency of 11.059 MHz). The incoming data is stored in a circular buffer, but at the same time data can be read from it. To prevent the tailpointer from `catching' the headpointer in the circular buffer, every time data is read from the buffer a delay is inserted in the program. The length of the delay was determined by trial and error and is about 50ms. This gives the serial interrupt routine time to store all incoming characters in the buffer.
7.3 GPS Differential Mode
The GPS receiver is only accurate to ±100m in the horizontal position and ±156m in the vertical position. Only military users have access to the more accurate
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (28 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
satellite code to give them accuracies of centimetres or millimetres. A civilian user could get an accuracy of 1-5 meters by using the GPS Oncore receiver in differential mode (DGPS). This means that a link between a base station, of which the exact position is known and fixed, and a GPS receiver exist so that the GPS receiver can receive correction messages from the base station. A base station can be a GPS receiver being at a fixed location sending its correction messages to another receiver. The GPS GT Oncore receiver, like the one used in this project, is capable of accepting these messages through one of its pins (Pin 5). But as only one GPS receiver was available, the differential mode could not have been implemented. The GPS receiver also has to be capable of generating these correction messages. The VP Oncore receiver from Motorola is capable of generating these correction messages.
In South Africa there are some base stations where these correction messages are available. The user has to buy `airtime' from them in order to receive these. A possible way of using the Oncore receiver in differential mode would be to have a cell-phone link between the base staion and the GPS receiver in order to receive these correction messages.
7.4 External RAM
Only 256 bytes of external RAM was used, but the chip can provide up to 2 kbytes of memory. Being able to access this amount of memory, the 2 functions `Almanac data' and `Visible Satellites' could also be implemented with the microcontroller, as these functions need a bigger circular buffer to store data in. Due to time limitations this was not done, but it could be easily implemented by using the 3 unused address lines provided on the RAM chip. These address lines are tied to +5 Volts, but could be connected to the unused pins of port 2 of the microcontroller. The extra address has to be then placed onto the port 2 pins before a `write' or `read' is to be done to external RAM.
7.5 LCD Contrast Voltage
Switching from the `Gel' cell battery to the car battery and vice versa means adjusting the LCD contrast voltage every time using the provided potentiometer. Initially the design provided only the use of one battery and only later included the use of the car battery. As this is not an ideal situation, this contrast voltage should be made battery (voltage) independent. This could be done by adding another voltage inverter and by routing the 2 batteries separately to the 2 voltage inverters.
Chapter 8 ConclusionThe project undertaken to design and build a GPS system was succesfully completed. The final system is hand-held, user-friendly and reliable. From the implementation process and work carried out on the GPS, the following conclusions can be drawn:
1. Microcontroller. The use of the Atmel 8051 microcontroller made the implementation of software and hardware very easy, as much help was available in form of literature and cross-compilers.
2. Battery. The `Gel' cell battery is well suited for hand-held applications, and as it is rechargeable it can be used many times.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (29 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
3. Method of Operation. The lay-out of the keyboard and LCD as well as the integration of the battery into a separate compartment made the system easy to use. Making use of a virtual keyboard reduces the number of keys on the box but does not reduce the functionability.
4. Cost. The cost of this GPS system is ± R2000.00 which is initially more expensive than commercially available GPS systems that can be obtained nowadays for less and are much smaller. But having a clear understanding of the Motorola Oncore GPS receiver means that more functions can be implemented at a later stage to the user's preferences.
Chapter 9 RecommendationsAs time was limited, many functions of the Oncore receiver could not be implemented. Therefore the following recommendations can be made:
1. Implement the NMEA protocol and use an electronic navigation system to communicate with the GPS. 2. Use the LCD more extensively by displaying the position of the GPS receiver or satellites graphically, instead of only using text. 3. Add non-volatile external memory to record data (i.e. position) in order to recall it later, or use it with the PC together to plot co-ordinates on a map. 4. Display a map and plot the current position on it, using a bigger colour screen. 5. Implement Differential GPS using the existing GPS receiver to get better position accuracies.
Bibliography
[Atmel,1997] Atmel Corporation Microcontroller Data Book, San Jose California, 1997.
[GPS ICD-200] GPS Interface Control Document: p86,p123-130
[Hantronix] A simple way to create Bitmap Images for Graphics LCD's
[NMEA,1997] National Marine Electronics Association, NMEA 0183, Standard for Interfacing Marine Electronic Devices, Version 2.20, January1, 1997.
[Toshiba,1997] Toshiba T6963C Data Sheet, Toshiba Corporation, 07/04/1997
[Yeralan S and Ahluwalia A, 1995] Programming and Interfacing the 8051 Microcontroller, Addison-Wesley Publishing Comapany, Massachusetts: p75-111, p176-181, p185-195.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (30 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Appendix A GPS Oncore Commands
Function Description Binary Command
Time Time of day @@Aa
Time GMT Offset @@Ab
Time Date @@Ac
Position Latitude @@Ad
Position Longitude @@Ae
Position Height @@Af
Position Satellite Mask Angle @@Ag
Receiver Atmosphere Correction Mode @@Aq
Time Time Mode @@Aw
Receiver Visible Satellite Status message @@Bb
Almanac Almanac Data Output @@Be
Time Leap Second Pending Status @@Bj
Receiver Set-to-Defaults @@Cf
Receiver Receiver ID @@Cj
Position Position/Status/Data @@Ea
Receiver Self-Test @@Fa
Table A.1: Commands from GPS used for Thesis
Command name Description
GPGGA Global Positioning System Fix Data
GPGLL Geographic Position - Latitude/Longitude
GPGSA GPS DOP and Active Satellites
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (31 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
GPGSV GPS Satellites in View
GPRMC Recommended Minimum Specific GPS / Transit Data
GPVTG Course over Ground and Ground Speed
GPZDA Time and Date
Table A.2: NMEA Commands
The following 2 commands are used with the NMEA data format:
Command name Description
@@Ci Switch to NMEA Format
$PMOTG,FOR, Switch to Motorola Binary Format
Table A.3: Format Commands
Appendix B Almanac Parameters
Parameters No. of Bits Scale Factor Units
e 16 2-21 dimensionless
toa 8 212 seconds
δi** 16* 2-19 semi-circles
Omegadot 16* 2-38 semi-circles/second
(A)1/2 24 2-11 meters1/2
(Omega)0 24* 2-23 semi-circles
ω 24* 2-23 semi-circles
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (32 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
M0 24* 2-23 semi-circles
af0 11* 2-20 seconds
af1 11* 2-38 sec/sec
Table B.1: Parameters of Subframe 4 and 5
* These parameters are represented in 2's Complement with the sign bit in the MSB.** Relative to 0.3 semi-circles.
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (33 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure B.1: Details of Subframe 5
The following pages of subframe 4 have the same format as above: 2-5, 7-10.
Appendix C LCD Controller Notes
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (34 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure C.1: Character Code Map from the T6963C
Appendix D Circuit Diagrams
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (35 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (36 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure D.1: Circuit Diagram for External RAM
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (37 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (38 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure D.2: Interface Diagram for LCD
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (39 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (40 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure D.3: Microcontroller and PC to GPS
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (41 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (42 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure D.4: Keypad Connections
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (43 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (44 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure D.5: Power Supply and Contrast Voltage
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (45 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (46 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (47 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Figure D.6: PCB Circuit Design
Figure D.7: PCB Circuit Keyboard Design
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (48 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Appendix E C++ CodeThe following files make up the 'GPS' program in C++ code:
[Writegps.cpp (p50):] Includes the main program from which commands are send to the GPS and messages from the GPS are decoded. Gps.h (p54):
Contains the function which sends characters to the GPS and reads characters from the ringbuffer. Lcd.h (p56):
Contains lcd routines to display characters on the LCD. Disp.h (p60):
Contains routines which format the data received from the GPS and display it. Pic.h (p72):
Contains the array holding the bytes for the picture displayed on the LCD.
These files are also included on the attached disc.
switch(index1) { case 'A': switch(index2) { case 'a': Disp_Aa(0);
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (50 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
break; case 'b': Disp_Ab(); break; case 'c': Disp_Ac(0); break; case 'd': Disp_Ad(0); break; case 'e': Disp_Ae(0); break; case 'f': Disp_Af(0); break; case 'g': Disp_Ag(); break; case 'q': Disp_Aq(); break; case 'w': Disp_Aw(); break; } break; case 'B': switch(index2) { case 'b': Disp_Bb(); break; case 'j': Disp_Bj(); break; } break; case 'C': switch(index2) { case 'b': Disp_Cb(); break; case 'f': Disp_Same(0); break; case 'j': Disp_Cj(); break; } break; case 'E': switch(index2) { case 'a':
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (51 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
flag = Disp_Ea(flag); break; } break; case 'F': switch(index2) { case 'a': Disp_Fa(); break; } break; case 'S': switch(index2) { case 'z': Disp_Same(1); break; } break; } }
if(flag == 1) { outp(PORT, var1); //send char to serial port delay(1); } else if(flag == 2) { outp(PORT, var1); //send char to serial port delay(1); outp(PORT, var2); //send char to serial port delay(1); } else if(flag == 3) { outp(PORT, var1); //send char to serial port delay(1); outp(PORT, var2); //send char to serial port delay(1); outp(PORT, var3); //send char to serial port delay(1); } outp(PORT, checksum); //send char to serial port delay(1); outp(PORT, 0x0D); //send <CR> to serial port delay(1); outp(PORT, 0x0A); //send <LF> to serial port delay(1);}
int Buffer(){ int ch; ch = buffer[bufferout]; delay(2); bufferout++; if(bufferout == 2048) bufferout = 0;
return ch;}
long Bytes(int num){ long b; int i; for(i = 0; i < num; i++) { if(i == 0) b = Buffer(); b <<= 8;
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (59 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
////////////////////////////////////////////////////////Program to control a T6963C-based 240x64 pixel LCD display////////////////////////////////////////////////////////
#define CEHI outp(pcont, (inp(pcont) & 0xfe))//take PC 1 HI#define CELO outp(pcont, (inp(pcont) | 0x01))//take PC 1 LO
#define RDHI outp(pcont, (inp(pcont) & 0xfd))//take PC 14 HI#define RDLO outp(pcont, (inp(pcont) | 0x02))//take PC 14 LO
#define WRHI outp(pcont, (inp(pcont) | 0x04))//take PC 16 HI#define WRLO outp(pcont, (inp(pcont) & 0xfb))//take PC 16 LO
#define CDHI outp(pcont, (inp(pcont) & 0xf7))//take PC 17 HI#define CDLO outp(pcont, (inp(pcont) | 0x08))//take PC 17 LO
#define G_BASE 0x0200 //base address of graphics memory#define T_BASE 0x0000 //base address of text memory#define BYTES_PER_ROW 40 //how many bytes per row on screen
//This will be 30 with 8x8 font, 40 with 6x8 font, //for both Text & Graphics modes. Font selection by //FS pin on LCD module://FS=High: 6x8 font. FS=Low: 8x8 font.
void dput(int byte); //write data byte to LCD moduleint sget(void); //check LCD display status pbrtvoid cput(int byte); //write command byte to LCD module//make sure control lines are at correct levelsvoid lcd_setup(); void lcd_init(); //initialize LCD memory and display modes//send string of characters to LCDvoid lcd_print(char *string); void lcd_clear_graph(); //clear graphics memory of LCDvoid lcd_clear_text(); //clear text memory of LCD
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (60 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
//set memory pointer to (x,y) position (text)void lcd_xy(int x, int y); //set single pixel in 240x64 arrayvoid lcd_setpixel(int column, int row); void Disp_Pic();int array[15];
#define BASE 0x378 //base address for parallel port LPT1:int pdata = BASE; //par.port data registerint pcont = BASE+2;//par.port control register
////////////////////////////////////////////////////////////void lcd_clear_graph() //clear graphics memory of LCD{ int i;
dput(G_BASE%256); dput(G_BASE>>8); cput(0x24); //addrptr at address G_BASE
for (i = 0; i < 2560; i++) { dput(0); //write data cput(0xc0); //inc ptr } //end for(i)} //end lcd_clear_graph()
void lcd_clear_text(){ int i;
dput(T_BASE%256); //set low address dput(T_BASE>>8); //set high address cput(0x24); //addrptr at address T_BASE
for (i = 0; i < 320; i++)//40 chars in a line * 8 lines { dput(0); //write space cput(0xc0); //inc ptr } //end for(i)} //lcd_clear_text()
//send string of characters to LCDvoid lcd_print(char *string){ int i; int c;
for (i = 0; i < strlen(string); i++) { c = string[i] - 0x20; //convert ASCII to LCD char address if (c<0) c=0;
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (61 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
/* =================================================== * Low-level I/O routines to interface to LCD display * based on four routines: * * dput(): write data byte * cput(): write control byte * sget(): read status * =================================================== */ //make sure control lines are at correct levelsvoid lcd_setup(){ CEHI; //disable chip RDHI; //disable reading from LCD WRHI; //disable writing to LCD CDHI; //command/status mode
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (64 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
} //end lcd_setup()
void lcd_init() //initialize LCD memory and display modes{ dput(G_BASE%256); dput(G_BASE>>8); cput(0x42); //set graphics memory to address G_BASE
dput(BYTES_PER_ROW%256); dput(BYTES_PER_ROW>>8); cput(0x43); //n bytes per graphics line
dput(T_BASE%256); dput(T_BASE>>8); cput(0x40); //text memory at address T_BASE
dput(BYTES_PER_ROW%256); dput(BYTES_PER_ROW>>8); cput(0x41); //n bytes per text line
cput(0x80); //mode set: Graphics OR Text, ROM CGen
cput(0xA7); //cursor is 8 lines high
dput(0x00); dput(0x00); cput(0x21); //put cursor at (x,y) location
//define own char(degree sign) dput(0x03); dput(0x00); cput(0x22); //offset register set / set CG RAM dput(0x00); dput(0x1C); cput(0x24); //set address pointer
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (65 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
} //end lcd_init()
int sget(void) //get LCD display status byte{ int lcd_status;
RDLO; //bring LCD /RD line low (read active) WRHI; //make sure WRITE mode is inactive CELO; //bring LCD /CE line low (chip-enable active) CDHI; //bring LCD C/D line high (read status byte) delay(1); lcd_status = inp(pdata); //read LCD status byte CEHI; //bring LCD /CE line high, disabling it RDHI; //deactivate LCD read mode
return(lcd_status);} //sget()
//write data byte to LCD module over par. portvoid dput(int byte) //assume PC port in data OUTPUT mode{ //wait until display ready do {} while ((0x03 & sget()) != 0x03); outp(pdata, byte); //write value to data port CDLO; WRLO; //activate LCD's write mode RDHI; //make sure LCD read mode is off CELO; //pulse enable LOW > 80 ns (hah!) delay(1); CEHI; //return enable HIGH WRHI; //restore Write mode to inactive} //end dput()
void cput(int byte) //write command byte to LCD module //assumes port is in data OUTPUT mode{ //wait until display ready do {} while ((0x03 & sget()) != 0x03);
outp(pdata, byte); //present data to LCD on PC's port pins
void Init_Text( int f ){ lcd_clear_text(); //write spaces if(f == 0) cput(0x97); //Graphics OFF & Text ON, cursor blinking else if(f == 1) cput(0x94); //Graphics OFF & Text ON, cursor off}
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (75 of 206) [30/05/2004 08:31:22 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
lcd_print("Main Menu to operate the GPS Oncore."); lcd_xy(0,1); //first character, 2 line lcd_print("Press ESC to quit!!"); lcd_xy(8,3); //first character, 4 line lcd_print("POSITION/STATUS/DATA:"); lcd_xy(8,4); //first character, 5 line lcd_print("GPS MODES:"); lcd_xy(8,5); //first character, 6 line lcd_print("RECEIVER FUNCTIONS:");}
void Sub_Menu1(){ Init_Text(0); Cursor_Pos(0, 7);
lcd_xy(8,0); //write text from upper left corner lcd_print("POS/STATUS/DATA:"); lcd_xy(8,1); //first character, 2 line lcd_print("LATTITUDE:"); lcd_xy(8,2); //first character, 3 line lcd_print("LONGITUDE:"); lcd_xy(8,3); //first character, 4 line lcd_print("HEIGHT:"); lcd_xy(8,4); //first character, 5 line lcd_print("DATE:"); lcd_xy(8,5); //first character, 6 line lcd_print("TIME OF DAY:"); lcd_xy(8,6); //first character, 7 line lcd_print("VISIBLE SATELLITES:"); lcd_xy(8,7); //first character, 8 line lcd_print("ALMANAC DATA OUTPUT:");}
void Sub_Menu2(){ Init_Text(0); Cursor_Pos(1, 7);
lcd_xy(8,1); //first character, 2 line lcd_print("GMT OFFSET:"); lcd_xy(8,2); //first character, 3 line lcd_print("TIME MODE:"); lcd_xy(8,3); //first character, 4 line lcd_print("LEAP SECOND PENDING STATUS:"); lcd_xy(8,4); //first character, 5 line lcd_print("ATMOSPHERIC CORRECTION MODE:"); lcd_xy(8,5); //first character, 6 line lcd_print("SATELLITE MASK ANGLE:");}
lcd_xy(2,1); //first character, 2 line if(flag == 0) lcd_print("Disable Polling:"); else if(flag == 1) lcd_print("Poll Position/Status/Data once:"); lcd_xy(2,2); //first character, 3 line lcd_print("Poll Position once every 10 seconds:"); lcd_xy(2,3); //first character, 4 line lcd_print("Poll Position once every 20 seconds:"); lcd_xy(2,4); //first character, 5 line lcd_print("Poll Position once every 30 seconds:");}
void Gmt_Menu(){ Init_Text(0); Cursor_Pos(3, 1);
lcd_xy(2,3); //first character, 3 line lcd_print("Poll current GMT Offset:"); lcd_xy(2,4); //first character, 4 line lcd_print("Change current GMT Offset:");}
void Time_Menu(){ Init_Text(0); Cursor_Pos(3, 1);
lcd_xy(2,3); //first character, 3 line lcd_print("Poll current Time Mode:"); lcd_xy(2,4); //first character, 4 line lcd_print("Change current Time Mode:");}
lcd_xy(2,1); //first character, 2 line lcd_print("Ionosperic Model disabled:"); lcd_xy(2,2); //first character, 3 line lcd_print("Ionosperic Model only enabled:"); lcd_xy(2,3); //first character, 4 line lcd_print("Tropospheric Model only enabled:"); lcd_xy(2,4); //first character, 5 line lcd_print("Both Models enabled:");}
void Mask_Menu(){ Init_Text(0); Cursor_Pos(3, 1);
lcd_xy(2,3); //first character, 3 line lcd_print("Poll current Satellite Mask Angle:"); lcd_xy(2,4); //first character, 4 line lcd_print("Change current Satellite Mask Angle:");}
void Mask_Sub_Menu(){ Init_Text(0);
lcd_xy(2,0); //write text from upper left corner lcd_print("Enter angle in degrees( 0 - 89 ): ");}
void Disp_Aa(int flag){
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (78 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (83 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Init_Text(1);
lcd_xy(3,3); lcd_print("Current Visible Satellites: "); num = Buffer(); lcd_print_num(num,0); lcd_xy(10,7); lcd_print("...press enter for next page.");
lcd_xy(0,3); lcd_print("Leap Second Pending Status: "); byte = Buffer(); lcd_xy(2,4); if(byte == 0) lcd_print("'0' = No leap second pending."); else if(byte == 1) lcd_print("'1' = Addition of one second pending."); else if(byte == 2) lcd_print("'2' = Subtraction of one second pending.");
End();}
void Disp_Cb(){ int data_id, sv_id, frame, page; int af0, af1; int i; float number; char pm[2]; strcpy(pm, " ");
The assembly code consists of only one file: 'Oncore.as'. The assembly code implements exactly the same functions as the C++ code. Only the 'Almanac' and 'Vissible Satellite' commands are ommitted.
This file is also included on the attached disc. FILE: ONCORE.H
;Data Segment dseg at 0008h ;data segment in Ram from 03h
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (96 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
org 0030h ;stack from 030h to 04fhStack: ds 0020h ;32 bytes of stack
;now the rest of the Ram from 050h to 07fh is available org 50h
i data 50h ;vars for lcd routinesrow data 52hcolumn data 53haddress data 54hx data 56hy data 58hl data 5ahcar data 5bhf data 5chlines data 5dhchars data 5ehflag data 5fh ;vars for main functiontag data 60hcheck data 61hcount data 62hindex1 data 63hindex2 data 64hnum1 data 65hnum2 data 66hnum3 data 67h checksum data 68h ;vars for data_to_gps functionvar1 data 69hvar2 data 6ahvar3 data 6bhfl data 6chfla data 6dh ;var for Numbers function
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (97 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
s data 6eh ;vars for main functionhours data 6fhminutes data 70hsign data 71htime data 72hatmos data 73hangle data 74hj data 75h ;var for data_to_gps functionnum data 76h ;vars for Bytes functionlb data 77hch data 7bhbufferin data 7chbufferout data 7dhkey data 7ehuniv data 7fh
ALE equ 8eh
;/////////////////////////////////;Xdata Segment xseg at 00h ;switch to XDATA segment at address 0
;//////////////////////////////////////;Interrupt service routine serial
serial: push acc jnb TI,serial1 clr TI ;ignore transmit interruptsserial1: jnb RI,serialdone ;done if no receive interrupt mov b,SBUF clr RI ;clear serial status bit
KeyRelease: mov P1,#0fh mov a,P1 orl a,#0f0h cpl a jz NoKey setb C retNoKey: clr C ret
;/////////////////////////////////////////////// org 01a0h Start: using 0 ;using bank of registers 0
Initilisation: ;sets up stack pointer to 5fh as required. mov SP,#(Stack-1) mov IE,#00h ;disable all interrupts mov P0,#00h ;P0: low, configured as output ;P1: columns low and rows high for keyboard routine mov P1,#0fh mov P2,#0f0h ;P2: low byte output
;initiate serial port anl PCON,#7fh mov TMOD,#20h ;set Timer 1 for auto reload - Mode 2 mov TCON,#41h ;run Timer 1 and set edge trig ints ;set Timer 1 for 9600 baud with xtal = 11.059Mhz mov TH1,#0fdh mov SCON,#50h ;set mode 1 and 8 data bits mov IE,#91h ;enable ES,EX0 and global interrupt ;Disable ALE; only active during movx instruction orl ALE,#01h
;/////////////////////////////////////////////;Function Main: calls Gps and receives info back ;from Gps and displays it on LCD
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (101 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Case_Ag: ;case 'g': lcall Disp_Ag ;Disp_Ag() jmp EndA ;break
Case_Aq: ;case 'q': lcall Disp_Aq ;Disp_Aq() jmp EndA ;break
Case_Aw: ;case 'w': lcall Disp_Aw ;Disp_Aw() jmp EndA ;break
Switch_A: mov a,index2 add a,#159 jz Case_Aa dec a jz Case_Ab dec a jz Case_Ac dec a jz Case_Ad dec a jz Case_Ae dec a jz Case_Af dec a jz Case_Ag add a,#246 jz Case_Aq add a,#250 jz Case_Aw jmp EndA
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (109 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
jmp F10F9: jmp Pos_Status_DataF10: dec a jz Lattitude dec a jz Longitude dec a jz Height dec a jz Date dec a jz Time_Of_DayEndPosition: jmp EndCommand ;break
Sat_Find: mov a,num3 dec a jz Mask_Poll dec a jz Mask_ChangeEndMask: jmp EndModes ;break
SwitchSub2: mov a,num2 dec a jz F15 jmp F16F15: jmp GmtF16: dec a jz F17 jmp F18F17: jmp Time_ModeF18: dec a jz F19 jmp F20F19: jmp Leap_SecondF20: dec a jz F21 jmp F22F21: jmp AtmosphereF22: dec a jz F23 jmp F24F23: jmp Satellite_MaskF24:
EndModes: jmp EndCommand ;break
Receiver_Func: ;case 3:
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (115 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
prtLCD: pop dph ; pop return address into dptr pop dplprtNext: clr a ; set offset = 0 movc a,@a+dptr ; get chr from code memory cjne a,#0, chrOK ; if chr = 0 then return sjmp retPrtLCDchrOK: subb a,#20h mov r7, a lcall wrLCDdata ; send character inc dptr ; point at next character ljmp prtNext ; loop till end of stringretPrtLCD: mov a, #1h ; point to instruction after string jmp @a+dptr ; return with a jump instruction
;////////////////////////////////////////////lcd_print1: clr a ; set offset = 0 movc a,@a+dptr ; get chr from code memory mov univ,a mov a,#1 ; set offset = 0 movc a,@a+dptr ; get chr from code memory mov dpl,a mov a,univ mov dph,a
printNext: clr a ; set offset = 0 movc a,@a+dptr ; get chr from code memory cjne a,#0, char_is_OK ; if chr = 0 then return sjmp returnPrtLCDchar_is_OK: subb a,#20h mov r7, a lcall wrLCDdata ; send character inc dptr ; point at next character ljmp printNext ; loop till end of stringreturnPrtLCD: ret
;//////////////////////////////////////////////////;Function wrLCDdata: prints out characters
wrLCDdata: lcall dput
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (119 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
mov r7,#192d lcall cput
ret
;//////////////////////////////////////////////;Function lcd_xy: place cursor at x/y position
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (139 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Gps_Chars:
sendGPS: pop dph ;pop return address into dptr pop dpl mov j,#0sendNext: clr a ; set offset = 0 movc a,@a+dptr ; get chr from code memory cjne a,#0,charOK ; if chr = 0 then return sjmp retsendGPScharOK: mov r0,a lcall sendGPSdata ; send character inc dptr ; point at next character inc j
mov a,j dec a jz D1 dec a jz D1 dec a jz D2 jmp D3D1: ljmp sendNext ; loop till end of stringD2: mov checksum,r0 ljmp sendNext ; loop till end of string
D3: mov a,r0 xrl checksum,a ljmp sendNext ; loop till end of string
retsendGPS: mov a, #1h ; point to instruction after string jmp @a+dptr ;return with a jump instruction
;////////////////////////////////////////////////////;Function sendGPSdata: sends out characterssendGPSdata: clr TI mov SBUF,r0 lcall mdelay ret
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (140 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
mov a,r5 dec a jz C1 jmp C2C1: jmp PossiC2: dec a jz C3 jmp C4C3: jmp LatC4: dec a jz C5 jmp C6C5: jmp LonC6: dec a jz C7 jmp C8C7: jmp HeiC8: dec a jz C9 jmp C10C9: jmp DatumC10: dec a jz C11 jmp C12C11: jmp TimC12: dec a jz C13 jmp C14C13: jmp GmtPC14: dec a jz C15 jmp C16C15: jmp GmtCC16: dec a jz C17 jmp C18C17: jmp TPollC18: dec a
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (141 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
jz C19 jmp C20C19: jmp TChangeC20: dec a jz C21 jmp C22C21: jmp LeapSC22: dec a jz C23 jmp C24C23: jmp AtmosPC24: dec a jz C25 jmp C26C25: jmp AtmosCC26: dec a jz C27 jmp C28C27: jmp MaskPC28: dec a jz C29 jmp C30C29: jmp MaskCC30: dec a jz C31 jmp C32C31: jmp SelfC32: dec a jz C33 jmp C34C33: jmp DefaC34: jmp lastchars
Possi: lcall Gps_Chars db "@@Ea",0 jmp lastchars
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (142 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
Lat: lcall Gps_Chars db "@@Ad",99h,99h,99h,99h,0 jmp lastchars
Lon: lcall Gps_Chars db "@@Ae",99h,99h,99h,99h,0 jmp lastchars
Hei: lcall Gps_Chars db "@@Af",99h,99h,99h,99h,99h,0 jmp lastchars
Datum: lcall Gps_Chars db "@@Ac",0ffh,0ffh,0ffh,0ffh,0 jmp lastchars
Tim: lcall Gps_Chars db "@@Aa",0ffh,0ffh,0ffh,0 jmp lastchars
GmtP: lcall Gps_Chars db "@@Ab",0ffh,0ffh,0ffh,0 jmp lastchars
GmtC: lcall Gps_Chars db "@@Ab",0 jmp lastchars
TPoll: lcall Gps_Chars db "@@Aw",0ffh,0 jmp lastchars
TChange: lcall Gps_Chars db "@@Aw",0 jmp lastchars
LeapS: lcall Gps_Chars db "@@Bj",0 jmp lastchars
AtmosP: lcall Gps_Chars db "@@Aq",0ffh,0 jmp lastchars
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (143 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
AtmosC: lcall Gps_Chars db "@@Aq",0 jmp lastchars
MaskP: lcall Gps_Chars db "@@Ag",0ffh,0 jmp lastchars
Z111: mov b,#10d ;pow operation (value will never be ;greater then 100) mul ab cjne r5,#0,Gogo1 jmp Gogo2Gogo1: djnz r5,Z111Gogo2: jz Power mov fl,a jmp CorrectPower: inc a mov fl,aCorrect: clr c mov a,var2 subb a,#01h mov r3,a mov a,#yebo add a,r3 mov r1,a movx a,@r1 ;r4 contains now value from array mov 4+0,a
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (162 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
GetVal: mov a,r2 inc a movc a,@a+pc retnums: db 0 db 0 db 0 db 1 db 0 db 0 db 2 db 0 db 0 db 3 db 0 db 0 db 0 db 4 db 0 db 0 db 5 db 0 db 0 db 6 db 0 db 0 db 0 db 7 db 0 db 0 db 8 db 0 db 0 db 9
;////////////////////////////////////////////
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (164 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
;Function lcd_print_num;count - num;temp - x;i - l;f - car
div32_loop: clr C ;clear carry flag mov a,PR0 ;shift the highest bit of the dividend... rlc a ;... into... mov PR0,a mov a,PR1 rlc a mov PR1,a mov a,PR2 rlc a mov PR2,a mov a,PR3 rlc a mov PR3,a
mov a,X0 ;... the lowest bit of the partial ... rlc a ;... remainder mov X0,a mov a,X1 rlc a mov X1,a mov a,X2 rlc a mov X2,a mov a,X3
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (167 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
rlc a mov X3,a
lcall SUB32 ;attempt to subtract to see if the... ;... partial remainder is as large or... ;... larger than the divisor.
mov C,OV ;get subtraction external barrow cpl C ;complement external barrow jnc div32_1 mov X3,Z3 mov X2,Z2 mov X1,Z1 mov X0,Z0div32_1: mov a,r3 ;add result bit to partial quotient rlc a mov r3,a mov a,r4 rlc a mov r4,a mov a,r5 rlc a mov r5,a mov a,r6 rlc a mov r6,a
djnz r7,div32_loop
mov Z7,r6 ;put quotient in Z4 - Z7 mov Z6,r5 mov Z5,r4 mov Z4,r3 mov Z0,X0 ;get remainder, saved before the... mov Z1,X1 ;last subtraction mov Z2,X2 mov Z3,X3 clr OV ;divisor is not 0 ret ;done
;//////////////////////////////////////////////////;==================================================; subroutine SUB32; 32-Bit Unsigned subtraction;==================================================SUB32: mov a,X0 ;load X low byte into accumulator clr C ;clear carry flag subb a,Y0 ;subract Y low byte mov Z0,a ;put result in Z low byte mov a,X1 ;repeat with other bytes... subb a,Y1 mov Z1,a mov a,X2
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (168 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
subb a,Y2 mov Z2,a mov a,X3 subb a,Y3 mov Z3,a mov OV,C ;set ZOV id an external barrow is produced ret ;done
;////////////////////////////////////////////////////;===================================================; subroutine ADD16; 16-Bit Unsigned Addition;===================================================ADD16: mov a,#low(Gps_pic_less); load X low byte into accumulator add a,r2 ; add Y low byte mov dpl,a ; put result in Z low byte mov a,#high(Gps_pic_less); load X high byte into accumulator addc a,r3 ; add Y high byte with the carry from low ... ; ... byte operation mov dph,a ; save result in Z high byte mov OV,C ; set OV if external carry ret ; done
mov a,univ cjne a,#0,ww8 lcall lcd_print db "'0' = Ionosphere model disabled.",0 jmp ww11ww8: cjne a,#1,ww9 lcall lcd_print db "'1' = Ionosphere model only enabled.",0 jmp ww11ww9: cjne a,#2,ww10 lcall lcd_print db "'2' = Tropospheric model only enabled.",0 jmp ww11ww10: cjne a,#3,ww11 lcall lcd_print db "'3' = Both models enabled.",0
lcall lcd_print db "Leap Second Pending Status: ",0
lcall Buffer mov univ,r3
mov r2,#high (4) mov r3,#low (4) mov r4,#high (2)
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (185 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller
mov r5,#low (2) lcall lcd_xy
mov a,univ cjne a,#0,ww14 lcall lcd_print db "'0' = No leap second pending.",0 jmp ww16ww14: cjne a,#1,ww15 lcall lcd_print db "'1' = Addition of one second pending.",0 jmp ww16ww15: cjne a,#2,ww16 lcall lcd_print db "'2' = Subtraction of one second pending.",0ww16: lcall EndDisps ret
kk16: db "Antenna Undercurrent:",0kk15: db "Antenna Overcurrent:",0kk14: db "RTC Comm & Time Fail",0kk13: db "Temperature Sensor Fail",0kk12: db "Ignore",0kk11: db "RAM Fail",0kk10: db "ROM Fail",0kk9: db "1 kHz Presence",0kk8: db "Channel 8 Correlation Test Fail!!!",0kk7: db "Channel 7 Correlation Test Fail!!!",0kk6: db "Channel 6 Correlation Test Fail!!!",0kk5: db "Channel 5 Correlation Test Fail!!!",0kk4: db "Channel 4 Correlation Test Fail!!!",0kk3: db "Channel 3 Correlation Test Fail!!!",0kk2: db "Channel 2 Correlation Test Fail!!!",0kk1: db "Channel 1 Correlation Test Fail!!!",0
tt9: db " - available for position.",0tt8: db " - ephemeris acquire.",0tt7: db " - satellite time available.",0tt6: db " - message sync detect.",0tt5: db " - bit sync detect.",0tt4: db " - preg acquire.",0tt3: db " - AGC set.",0tt2: db " - code acquire.",0tt1: db " - code search.",0
tt17: db " - using for position fix.",0tt16: db " - satellite momentum alert flag.",0tt15: db " - satellite anti-spoof flag set.",0tt14: db " - satellite reported unhealthy.",0tt13: db " - satellite reported inaccurate(>16m).",0tt12: db "",0tt11: db "",0
http://www.dip.ee.uct.ac.za/~ahenric/oncorhtm.html (202 of 206) [30/05/2004 08:31:23 a.m.]takshop.net
Interfacing a GPS to an LCD using a Microcontroller