Archive – Old stuff

GPS Project Pics

PIC Microcontroller

I have been involved with the PIC microcontrollers by Microchip Technology, Inc. since early 1999.  I got interested using the PIC after using the Basic Stamp II by Parallax, Inc.  I wrote several clock programs using the BSII and wanted to move the code over to the PIC instead of tying up my BSII module.  I then was interested in being able to compile my BSII programs for the PIC so I didn’t have to spend much time learning assembly language.  That’s when I found the PicBasic Pro Compiler by microEngineering Labs, Inc.

Note – The two editors I used for programming were Programmers File Editor and PicMatePro (no longer available).

First Project

Source Code

'PROGRAM: eagle_gps7bl.pbp
'
'Modified by Brian Skrentny, December 1999
'Modified last on June 27, 2000
'https://n9loo.com/
'previously published at http://bskrentny.com/
'
'Program to read position data from a Eagle Explorer GPS and display it on
'a Scott Edwards 4 X 20 LCD display at 9600 baud using PIC 16C558.
'
'Original program written by Decade Engineering
'to work with the Garmin and LCD display.
'
'
' *****  Scott Edwards 4X20 LCD control codes  *****

'Home_Cursor  	CON 01 			'Home the display cursor
Bigchr  	CON 02 			'Start big number display
'Blank_Cursor 	CON 04 			'Turn off cursor
'Underline_Cursor CON 05 		'Underline cursor
'Blink_Blk_Cursor CON 06 		'Blinking block cursor
'Back_Space  	CON 08 			'Back space the cursor
'Line_Feed  	CON 10 			'Move down one row
'Vertical_Tab 	CON 11 			'Move up one row
Clear_Screen 	CON 12 			'Clear the screen (Form feed)
'Carriage_Return CON 13 		'Return to start of next line
blon		CON 14 			'Turn backlight on
bloff		CON 15 			'Turn backlight off
pcurs		CON 16 			'Position cursor at xxx
'Clear_Column 	CON 17 			'Clear a column
dpin		CON 6 			'LCD display pin, PIC pin 12
N9600   	CON 6			'LCD Baudrate (9600,n,8,1)
N29600   	CON $4054		'LCD Baudrate (9600,n,8,1)
GPS_Pin  	CON 0			'GPS data input pin, PIC pin 6 (PORTB.0)
N4800   	CON 16572		'GPS baudrate (4800)
tz		CON 5			'Time zone (4=EST,5=CST,6=MST,7=PST) - st flag adds 1

DEFINE 	CHAR_PACING	2500		'2500 microsecond delay for LCD

time	var byte(4) 	'Unformatted time: 4533= XX:45:33 UTC
hr	var byte	'Hour in CST or CDT - set using tz
Cse	var word	'Whole number course (no decimal)
cmp	var byte(2)	'Course direction
Spd	var word	'Whole number speed in kts.(no decimal)
Spdt	var byte	'Tenths position
Speed	var byte	'Speed in MPH
gpsfix  var byte	'GPS status, A = good data, V = bad data
update	var bit		'status flag
indent	var bit		'indent flag
st	var bit		'standard time flag
bl	var bit		'backlight flag
'
'-----------------------------------------------------------------------------
init:
 pause 2000
 bl = 0
'-----------------------------------------------------------------------------
'
'-----------------------------------------------------------------------------
if PORTB.1 then		'check switch/jumper if Standard or Daylight savings time
	st = 1		'switch/jumper off - standard time
else
	st = 0		'switch/jumper on - daylight savings time
endif
'
'-----------------------------------------------------------------------------
'
id:
 gosub clrscr				'Clear display
 serout dpin,N9600,[pcurs,71,"N9LOO"]
 update = 1 : indent = 0		'reset flags
'
'-----------------------------------------------------------------------------
'
get_data:
 if PORTB.2 = 0 then blight		'Check for backlight button (PIC pin 8)
 serin2 GPS_Pin,N4800,2100,no_data,[wait("RMC,"),dec2 hr,str time\4,skip 1,gpsfix,wait("W,"),dec Spd,dec Spdt,dec Cse]
 if update = 0 then id
 if gpsfix="A" then good_fix
 if gpsfix="V" then bad_fix
goto get_data
'
'-----------------------------------------------------------------------------
'
bad_fix:
 gosub clrscr						'Clear display
 serout dpin,N9600,[pcurs,88,"PLEASE WAIT"]		'data not reliable
 serout dpin,N9600,[pcurs,107,"WHILE POSITION"]
 serout dpin,N9600,[pcurs,125,"IS BEING ACQUIRED"]
 update = 0
 goto get_data
'
'-----------------------------------------------------------------------------
'
good_fix:
 Spd = (Spd * 10) + Spdt		'Multiply Knots by 10 (includes tenths for accuracy)
 Speed = (Spd */ $0127) / 10		'Multiply by 1.151 to convert Knots to MPH and / 10
 if hr > ((tz - 1) + st) then		'check if next day (UTC)
	hr = hr - (tz + st)		'subtract hr's according to time zone (5=CDT, 6=CST)
 else
	hr = 24 - ((tz + st) - hr)	'subtract hr's from previous day
 endif

 if cse < 23 then north				'determine heading
 if cse < 68 then northeast
 if cse < 113 then east
 if cse < 158 then southeast
 if cse < 203 then south
 if cse < 248 then southwest
 if cse < 293 then west
 if cse < 338 then northwest
 if cse < 361 then north

north:
 cmp(0) = "N" : cmp(1) = " " : indent = 1	'N
goto dsp_cmphd

northeast:
 cmp(0) = "N" : cmp(1) = "E"			'NE
goto dsp_cmphd

east:
 cmp(0) = "E" : cmp(1) = " " : indent = 1	'E
goto dsp_cmphd

southeast:
 cmp(0) = "S" : cmp(1) = "E"			'SE
goto dsp_cmphd

south:
 cmp(0) = "S" : cmp(1) = " " : indent = 1	'S
goto dsp_cmphd

southwest:
 cmp(0) = "S" : cmp(1) = "W"			'SW
goto dsp_cmphd

west:
 cmp(0) = "W" : cmp(1) = " " : indent = 1	'W
goto dsp_cmphd

northwest:
 cmp(0) = "N" : cmp(1) = "W"			'NW

dsp_cmphd:
 if indent = 0 then skip_indent
 serout dpin,N9600,[pcurs,64,bigchr,"   ",pcurs,67,bigchr,cmp(0)] : indent = 0
goto dsp_time
'
'-----------------------------------------------------------------------------
'
skip_indent:
 serout dpin,N9600,[pcurs,64,bigchr,cmp(0),cmp(1)]

dsp_time:
 serout2 dpin,N29600,[pcurs,74," ",dec2 hr,":",time(0),time(1),":",time(2),time(3)]

dsp_speed:
 serout2 dpin,N29600,[pcurs,116,dec Speed," MPH "]
goto get_data

no_data:
 gosub clrscr
 serout dpin,N9600,[pcurs,67,"NO SERIAL DATA"]
 serout dpin,N9600,[pcurs,105,"PLEASE CONNECT GPS"]
 serout dpin,N9600,[pcurs,128,"AT 4800 BAUD"]
' update = 0					'Never gets to ID since check is skipped, but ok
goto get_data					'Need to add pause and goto id if desired
'
'-----------------------------------------------------------------------------
'
clrscr:
 serout dpin,N9600,[Clear_Screen]		'Clear display
 pause 250
 return
'
'-----------------------------------------------------------------------------
'
blight:
	'pause 250				'needed to move since slow checking
	branch bl, [bln, blff]
bln:
	serout dpin,N9600, [blon]
	bl = 1 : pause 500			'debounce switch
	goto get_data
blff:
	serout dpin,N9600, [bloff]
	bl = 0 : pause 500			'debounce switch
	goto get_data