Examples | Shop
 
Global Positioning System Using the BX-24 Microcontroller


 
This example application demonstrates how a BasicX-24 microcontroller can read data from the DS-GPM Global Positioning System Module and output the information onto an ISLCD220 I2C/Serial LCD module.

In this example we are using serial communication between the DS-GPM, BX-24 and LCD.

Connections  
BX-24 DS-GPM
Pin 16 Pin 1 (Serial output on the RS232 Coms Port)
Pin 17 Pin 2 (Serial input on the RS232 Coms Port)
Pin 23 Pin 3 (GND on the RS232 Coms Port)
  Connect between 6-16V DC to the power header.
BX-24 LCD
Pin 4 (GND) GND on Serial Header
Pin 5 Si on the Serial Header
Pin 21 (5V) +5V on the serial Header
Pin 23 GND
of battery
(do not connect if using
development board
regulated mains power)
Pin 24 +V of
battery (6-15V)

This example was programmed using the BX-24 Development kit, which supplies regulated mains power to the board and serial connection to the microcontroller for easy development and download of the code from your PC.

The code has been written in compiler version 2.1 Beta 1, which has the new CloseCom3 command, as used within this example.

This application uses the BX-24 to send serial commands to the GPS module requesting data from its internal registers. The BX-24 asks for data relating to GPS signal (Good or Bad), Time (UTC, Universal Coordinated Time), Date, Position (Longitude & Latitude), Altitude, Heading (True North and Magnetic North), Speed and the number of satellites being used.

The GPS Module does all the hard work for you, so the BX-24 just needs to read in to an array all the data it has requested. When the BX-24 receives its data from the GPS, it closes the GPS Com port and opens the LCD Com port ready to output the data onto the LCD.

Ensure that the string size is set to 20 or more in the BasicX Editors Options > Environment toolbar. When the .bas file is loaded into the editor, compile and download to the BX-24 (in this example, through the serial cable to the development board).

When downloaded, the mains power can be disconnected and battery power supplied allowing manoeuvrability of the device. Read the DS-GPM data sheet to check signal validity and how to set up the GPS Module.

Download the code here.

 

'***************************************************************************
'***************************************************************************
'Description: This example application demonstrates use of the DS-GPM Global 'positioning system using the BX-24 microcontroller and an ISLCD220 IIC/Serial 'LCD.
'
'Compiler Version 2.1 Beta 1
'Created: 22/01/03 Revision 1.00
'Written by: TRControl Solutions (Jamie Finnan)
'
'TR31
'***************************************************************************
'***************************************************************************
dim icom3(1 to 50) as byte 'inwards buffer
dim ocom3(1 to 50) as byte 'outwards buffer
dim data (1 to 50) as byte 'incoming data store
dim data2 (1 to 50) as byte 'incoming data store
dim data3 (1 to 50) as byte 'incoming data store
'***************************************************************************
Public sub main()
do
call setup_LCD 'Setup the LCD screen
call welcome 'Send the initialising screen to the LCD
Call CloseCom(3, icom3, ocom3) 'Close the serial coms to the LCD
Call ClearQueue(icom3) 'Clear the data queues
Call ClearQueue(ocom3) 'Clear the data queues
call setup_GPM 'Setup the GPS
call Read_GPM 'Read registers from the GPS
Call CloseCom(3, icom3, ocom3) 'Close the serial coms to the GPS
Call ClearQueue(icom3) 'Clear the data queues
Call ClearQueue(ocom3) 'Clear the data queues
call setup_LCD 'Setup the LCD again ready for coms
call LCD_Output 'Output Data to the LCD screen
Call CloseCom(3, icom3, ocom3) 'Close the serial coms to the LCD
Call ClearQueue(icom3) 'Clear the data queues
Call ClearQueue(ocom3) 'Clear the data queues
delay (2.0) '2.0 second delay
loop 'loop the program
end sub
'***************************************************************************
Public sub welcome()
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (0.5) '0.5 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"Global Positioning") 'send first line to LCDcall putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "using the BX-24") 'send line 2
delay (0.5) '0.5 second delay
end sub
'***************************************************************************
Public sub setup_GPM()
call openqueue(icom3,50) 'create input queue
call openqueue(ocom3,50) 'create output queue
call definecom3 (16,17,bx1000_1000) 'define coms port on pin16 & 17
call opencom(3,9600,icom3,ocom3) 'initiate coms port3
end sub
'***************************************************************************
Public sub setup_LCD()
call openqueue(icom3,50) 'create input queue
call openqueue(ocom3,50) 'create output queue
call definecom3 (0,5,bx1000_1000) 'define coms port on pin 0 and 17
call opencom(3,9600,icom3,ocom3) 'initialise coms port3
end sub
'***************************************************************************
Public Sub LCD_Output()
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1.0 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"GPS Quality is ") 'send line 1
if data3(20) = 0 then 'If then else statement to see quality of GPS
call putqueuestr(ocom3, "Bad") 'unit.
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "There is no signal")
elseif data3(20) = 1 then
call putqueuestr(ocom3, "Good")
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "There is a signal")
else
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "No Reading")
end if
Delay (3.0) '3 second delay
'***************************************************************************
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"Time is " & CStr(data(3))& CStr(data(4)) & ":" & _ CStr(data(5)) & CStr(data(6)) & ":" & CStr(data(7))& CStr(data(8)))
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "Date is " & CStr(data(9))& CStr(data(10)) & "/" & _ CStr(data(11)) & CStr(data(12)) & "/" & CStr(data(13)) & CStr(data(14)) & _ CStr(data(15)) & CStr(data(16)))
Delay (3.0) '3 second delay
'***************************************************************************
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1.0 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"The headings are") 'send line 1
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "True North =" & CStr(data2(3))& CStr(data2(4))& _ CStr(data2(5)) & "." & CStr(data2(6)) & "deg" ) 'send line 2
Delay (3.0) '3 second delay
'***************************************************************************
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1.0 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"Mag North =" & CStr(data2(7))& CStr(data2(8))& _ CStr(data2(9)) &"." & CStr(data2(10)) & "deg") 'send line 1
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "The speed =" & CStr(data2(11)) & CStr(data2(12)) & _ CStr(data2(13)) & "." & CStr(data2(14))& "Km/h") 'send line 2
Delay (3.0) '3 second delay
'***************************************************************************
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1.0 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"Position & Altitude") 'send line 1
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3, "Lat = " & CStr(data3(3)) & CStr(data3(4)) & ":" & _ CStr(data3(5)) & CStr(data3(6))& ":" & CStr(data3(7)) & CStr(data3(8)) & _ CStr(data3(9)) & CStr(data3(10)))
Delay (3.0) '3 second delay
'***************************************************************************
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1.0 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"Lon = " & CStr(data3(11)) & CStr(data3(12)) & _ CStr(data3(13)) & ":" & CStr(data3(14)) & CStr(data3(15))& ":" & CStr(data3(16)) _ & CStr(data3(17)) & CStr(data3(18)) & CStr(data3(19))) 'send line 1
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3,"Alt = " & CStr(data3(26)) & CStr(data3(27)) & _ CStr(data3(28)) & CStr(data3(29)) & "m") 'send line 2
Delay (3.0) '3 second delay
'***************************************************************************
call putqueuestr(ocom3,chr(254) & chr(1)) 'clear the screen
delay (1.0) '1.0 second delay
call putqueuestr(ocom3,chr(254) & chr(128)) 'Command byte sent
call putqueuestr(ocom3,"There are " & CStr(data3(21)) & CStr(data3(22)))
call putqueuestr(ocom3,chr(254) & chr(192)) 'command byte
call putqueuestr(ocom3,"Satellites in use") 'send line 2
Delay (3.0) '3 second delay
end sub '***************************************************************************
Public sub Read_GPM()

'Read the registers relating to Time and Date
call putqueuestr(ocom3, "[" & Chr(209) & Chr(128) & "]" & "]")
'command characters with two terminators
delay (0.6) '0.6 second delay
call getqueue(icom3,data,17) 'receive 17 bytes from the GPS
delay (0.6) '0.6 second delay
sleep (20)
'Read the registers relating to Heading and speed
call putqueuestr(ocom3, "[" & Chr(209) & Chr(130) & "]" & "]")
'command characters with two terminators
delay (0.6) '0.6 second delay
call getqueue(icom3,data2,16) 'receive 16 bytes from the GPS
Delay (0.6) '0.6 Second delay
sleep (20)
'Read the registers related to Position and Altitude
call putqueuestr(ocom3, "[" & Chr(209) & Chr(129) & "]" & "]")
'command characters with two terminators
delay (0.6) '0.6 second delay
call getqueue(icom3,data3,29) 'receive 29 bytes from the GPS
Delay (0.6) '0.6 second delay
sleep (20)
end sub
'***************************************************************************
'***************************************************************************

Examples | Shop